Received: by 2002:a19:771d:0:0:0:0:0 with SMTP id s29csp1265701lfc; Wed, 1 Jun 2022 13:34:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzF8ST2Ro+lcmXltoj27Kpc4t4ECfYUq9tbVxYE1Qbp1IRLgbXR72ncGyLCWlhPo/E/CMF1 X-Received: by 2002:a17:90a:b396:b0:1e4:d7de:ea3d with SMTP id e22-20020a17090ab39600b001e4d7deea3dmr1240772pjr.222.1654115641018; Wed, 01 Jun 2022 13:34:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654115641; cv=none; d=google.com; s=arc-20160816; b=UKoKWNYdxsplrchSNglLrR/MRvSKcBQ/Wm+BK4gwL6sAqJhmQIZa/Ea6ZMWiKu7uJP ++WWgETceeFuFnzp+/uu2IRnnLIPrCwKCBIqsOuenVnUdbKbsPM82ndLAdnOOrLj3/E1 ZiTv1TJO/t/Z+kuZoKqQlRscMbAqQxiANNYXMtzS9iGvHWyrYcZ8cxYq/RxxvO9yO1M1 YerIvkBziDzqXGEFbDs2apb7sDET6wtUHTSXs2u1rl4d0zKhalnuZ/qjCOUoN+hrGhJF h1puefaIMOLHMAWN+fwTS/cE9HwiPY+7rWUJwsbedba+Lu0ooPSa+E5XbkDwyB15QXWr ZMow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vjCZnJlkGKf+jcIPuDFQBSVbJFVWz+DiqFe3ZaJS4b8=; b=Zc2FH/NxPn7X/B0krB0rqEGomkimz9lmTSWdYgYl5HI2uzMNzVnJlOJL6zgkBdSCsi 9/iWoKVaXwD9fNBh+jbHlH8EZkIWCI9oIlX8OZBkzBDLjwnV725qjiF2uLj7IhwqGBMI EAtdXbCJyY8RB960iZjBWwDMOriKzSePSLQqiG48BkQ1oOpMXgSLEP8Gei5jgQS5KPQt qCtSf0vZwDhGWEZOwaXVBUYk0XON0dIAXE2yemD93yKIWTiou+h19icMkRPYhwZjXFkS 6RtQsmvfDN5QNun4iLj2r2EuLLDNDM1lJVsMTs7BJkPekhePty+ISzl+cXADVNqlSVTQ 0gYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=QIzTsSQi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id ot3-20020a17090b3b4300b001cb7ed1747fsi3591221pjb.171.2022.06.01.13.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 13:34:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=QIzTsSQi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 74BAB1E7ADE; Wed, 1 Jun 2022 12:43:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236931AbiE3Pkp (ORCPT + 99 others); Mon, 30 May 2022 11:40:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237679AbiE3PkQ (ORCPT ); Mon, 30 May 2022 11:40:16 -0400 X-Greylist: delayed 62 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 30 May 2022 07:47:35 PDT Received: from mta-64-226.siemens.flowmailer.net (mta-64-226.siemens.flowmailer.net [185.136.64.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8657E207EF6 for ; Mon, 30 May 2022 07:47:35 -0700 (PDT) Received: by mta-64-226.siemens.flowmailer.net with ESMTPSA id 202205301446317fba133b70edf42456 for ; Mon, 30 May 2022 16:46:31 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=daniel.starke@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=vjCZnJlkGKf+jcIPuDFQBSVbJFVWz+DiqFe3ZaJS4b8=; b=QIzTsSQikYXPx9W4y2QpkNI1ifNbZAW1JTYmGOvMjwtwIB2IJkgReiuL3XwEE9sJs7ntah gbedjXj1ln7lheE9T3uG3BNpXwQTmHMT7FJAfpUzedelRT6ZUvWiLYPrc1jU5BC506xA3tvX NWOvk1lqtSEOoG4WcLybXeLBtY7/Q=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v3 8/9] tty: n_gsm: fix resource allocation order in gsm_activate_mux() Date: Mon, 30 May 2022 16:45:11 +0200 Message-Id: <20220530144512.2731-8-daniel.starke@siemens.com> In-Reply-To: <20220530144512.2731-1-daniel.starke@siemens.com> References: <20220530144512.2731-1-daniel.starke@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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") Cc: stable@vger.kernel.org Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) There have been no comments on v2, hence, no change was done. Link: https://lore.kernel.org/all/20220519070757.2096-8-daniel.starke@siemens.com/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 9e4ada510c9f..b0b093e8e9d9 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -2483,6 +2483,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); @@ -2499,9 +2503,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.34.1