Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2927730rwb; Mon, 15 Aug 2022 14:13:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR7KOBg0xDYdj1k68DuPvJm3qmJfTELAKTEqZVBAsljnJGHcBCPVeK9R75veqixkWJnpfbnR X-Received: by 2002:a63:494a:0:b0:41c:f29e:2a2e with SMTP id y10-20020a63494a000000b0041cf29e2a2emr15275752pgk.477.1660597993087; Mon, 15 Aug 2022 14:13:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660597993; cv=none; d=google.com; s=arc-20160816; b=mPvvqTleeNbvM3TksjtzPJShArl4k4yrr9Tb6eQnpi0JWFfqkuRYxd1PiYHnR6vi+X tkCEHjT7uhzlu7As4ElxHXMshg2YjSK07Ysc4gth6fPXVHYQRzH9py8vlLc9mFxnnJI+ tgVSLiM+R3ZC0iPwpMdUz2N6yAi54xAoZi913YrIvNGKQTDOjmJs/kS+TEpIwpC2cYmI Cshbmm3TLfioS0dVyc4lT1Z7aMDzdoAWtR7XxahBr0RL3ZRlJCqAA3PhFzv8P9i3yBTT +jzRe/ynRIXEQdCHk0lwNjkzdcx028gM0hr4X99dtYDKYiqfYIx2A619GRwkav2dfQu1 ggBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iciPdkPEmnQPLKyzREgjJpvXiyi1QThkbWLMZxvG9Ao=; b=VQzrTzgNOYZ57irofZDaICu+94iStiCwHvbKlHfuVad3JPsB6YDtOsme3jqY1y3s8/ aZS4b0aubeA/4EN01XwbnT4yzyeqJHolxl5aGcOZL/jv7hzBnRU9nFVTaV0S3soC4WVo iTIxaReTlTSsgQaaU4AKVJBL8DCTid7QVzRs9vvYGyZ6Wv/tGWtJHVaB+0kzH3MhWZKE m7tJnAhaJfqlP71ro6ZtgQO+BdyA0x64el9Df+qmTmCsDnUzKofOTyMOluFx1jryL4Pb gimLFn4XCHyhzQ+Pq3GdSsixT0xJeRua2BqcQOU4AaDMm07VTPW9xvuEPMyP6VmUyLEe WPkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FdUwHOY6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 6-20020a170902ee4600b0016ea0e19867si10858299plo.478.2022.08.15.14.13.02; Mon, 15 Aug 2022 14:13:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FdUwHOY6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343899AbiHOTfy (ORCPT + 99 others); Mon, 15 Aug 2022 15:35:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244222AbiHOT2T (ORCPT ); Mon, 15 Aug 2022 15:28:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C384A5D0CF; Mon, 15 Aug 2022 11:43:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 392D7611E7; Mon, 15 Aug 2022 18:43:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B929C433D6; Mon, 15 Aug 2022 18:43:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589030; bh=DQYpAKgxnwyRGtLDlzQC5Y75d+Ggep7f0vdNwu/fXAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FdUwHOY61+PEYG7wzMlImxL1maXq+mc99hUvGTsgadK3zvuJzKfausZ1r46YSREhY B1gdi9WOJN4ypfg4dYeUxjW4E1EblqzCnI3cavn0xk83ZRu2nuzpaRNSVG8Un44p9t qaagi0Hb8emC2TSU2fGLPSvab2LYivhW6siEehnQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Starke , Sasha Levin Subject: [PATCH 5.15 590/779] tty: n_gsm: fix resource allocation order in gsm_activate_mux() Date: Mon, 15 Aug 2022 20:03:54 +0200 Message-Id: <20220815180402.560197049@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Starke [ Upstream commit 7349660438603ed19282e75949561406531785a5 ] Within gsm_activate_mux() all timers and locks are initiated before the actual resource for the control channel is allocated. This can lead to race conditions. Allocate the control channel DLCI object first to avoid race conditions. Fixes: e1eaea46bb40 ("tty: n_gsm line discipline") Signed-off-by: Daniel Starke Link: https://lore.kernel.org/r/20220701122332.2039-2-daniel.starke@siemens.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/n_gsm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 23fcb34240ac..b5ce10b0656f 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -2435,6 +2435,10 @@ static int gsm_activate_mux(struct gsm_mux *gsm) struct gsm_dlci *dlci; int ret; + dlci = gsm_dlci_alloc(gsm, 0); + if (dlci == NULL) + return -ENOMEM; + timer_setup(&gsm->kick_timer, gsm_kick_timer, 0); timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); init_waitqueue_head(&gsm->event); @@ -2450,9 +2454,6 @@ static int gsm_activate_mux(struct gsm_mux *gsm) if (ret) return ret; - dlci = gsm_dlci_alloc(gsm, 0); - if (dlci == NULL) - return -ENOMEM; gsm->has_devices = true; gsm->dead = false; /* Tty opens are now permissible */ return 0; -- 2.35.1