Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3026320rwb; Mon, 15 Aug 2022 16:24:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR7d3DpfL47NOAtIyHwnvGZA92rby2By+LN62ygTVsrkAPVyFfKCG0Os5cT8Loa8jylZngk0 X-Received: by 2002:a17:902:8302:b0:16d:bf03:847c with SMTP id bd2-20020a170902830200b0016dbf03847cmr19240899plb.125.1660605863913; Mon, 15 Aug 2022 16:24:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605863; cv=none; d=google.com; s=arc-20160816; b=NabtH1S2boIMbqgGvFxwrN+8HwOVw6gEQTslztN5JkPqf53Cj1coBT2k2GgEjGNCKS 0QdiBd6NXO3DfWkRBq4l2dLOhL+Ynqvv/zqBEVWJqoz1MqYlT6RQ8ceTlw9tMhB3FMBN Y7hYKl3eIR5k32IXGz0mRt0B6f/FXYe25BeZ4Teg/NPWS9ptWh/ApQt9yF4PkEPEg526 Bvp/6QSGWkTC0q7Ai4/QHYZHbUekcPzc4iLhz/vSUED0fxyWGdw1Mcd80cktLchrl195 z1VRWm9JzXzDdwJPV7oBwlJWW3VgV0tPR/61AKIyb5By5hNofy617Ieb+FbbF1aVGB0L Wecw== 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=wT/g2SqupaTXQ+vgMG6UcPd3NJnxfbWipsg28XF6S0I=; b=PVpUCFU+5dF3VOSZ4Zp5qN7HsWwpM7KfGBfwr37xKZoD7ySkC935FMpiF5QyBUv/fu 42K3z0T+ygXulLcuvkiMAwbA4tUFhAZuXhWiu1zXlUEt1ur2HCOmMYCWEmX+2eDs30Cy m1C4pnMoIGLRw49gp8fUpSR48EHCPhA5aCqo2wNAjsrdpbnktS9SYtt04s5ooXvaLIZu o4OevCQtGgbik1A+osCCRGSNxL/FJSPq9ENHIi5318zEqKv0RPbe4/ldtzb2WP0v0e1c D9uwzFMI0eELlKmyUFYLESfldZhtKSPM7pRdwVGjsV0gXv54Wt7P4eYqYiiHA9PRXRbt pSRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tm3yy2nE; 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 j15-20020a170902da8f00b0016caa701d5bsi12985270plx.487.2022.08.15.16.24.12; Mon, 15 Aug 2022 16:24:23 -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=tm3yy2nE; 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 S1351503AbiHOWoa (ORCPT + 99 others); Mon, 15 Aug 2022 18:44:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350537AbiHOWjs (ORCPT ); Mon, 15 Aug 2022 18:39:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B4834DB2A; Mon, 15 Aug 2022 12:51:34 -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 ams.source.kernel.org (Postfix) with ESMTPS id 94650B80EAD; Mon, 15 Aug 2022 19:51:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEB59C433C1; Mon, 15 Aug 2022 19:51:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593091; bh=NMcjJwEwPiqeIaDe8zmQomMLRLCK3nydvXSKtNTM+6g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tm3yy2nEoA+inXMb+Z3N0Fi4RF6iTUwZx2yh0lTbrpGryqQglnizIEUf16D64B/JY PsnNxwT/6/qU36xAhaeMcrMhGvQt4y3j8Eg+hTbeHzGYdy2bqtQ6CaIsJeBnqRbhHR iSQtKsJzhuGq8vGOXRlUxyZSfET46yXV6bO4nR+o= 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.18 0862/1095] tty: n_gsm: fix resource allocation order in gsm_activate_mux() Date: Mon, 15 Aug 2022 20:04:21 +0200 Message-Id: <20220815180504.996320151@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 ab7765afab86..17927163790e 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -2501,6 +2501,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_WORK(&gsm->tx_work, gsmld_write_task); @@ -2517,9 +2521,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