Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1426727iob; Thu, 19 May 2022 06:29:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0qbGogtcFoKSxKuwt2LLlZ4iE1B4Qya5sOTPv9Sv0Iuckw6YLj56oJRWQXE9Ai38ntTPz X-Received: by 2002:a05:6402:5193:b0:428:414d:e20d with SMTP id q19-20020a056402519300b00428414de20dmr5327656edd.173.1652966992623; Thu, 19 May 2022 06:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652966992; cv=none; d=google.com; s=arc-20160816; b=L4KEDT9mi/gYiWGiRPMiZc54ew5c9HCNkUawFHXXq4e8xf4vsEyZBNL0KNwxy1Am69 MwvAhPYXfHgJrbcrsLecGyWTtAnCYOLP/PeVG1Lf1c2wt1+uKDzjpYp1ohdeSpD/Oc5y 4NEryWgEFrvXy72pK8uq5TuBscjdWlclpRWKxbQCnTBbV2On5A53YEWdO5oW22wXuHdP D2Dw2s26wMLYQ6rnd0FtZewW9VSmMIAl8lq+TitiOPV1vVcgW4V6awKuICxkVUqfJwgD 2yQlWjwgj7WWexgXBPzG4Y3zeg36mHC3bgNAfY5dYMJ6ZOT1mCzi8J8O0P52irPONAkC qLRA== 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=siZxk5R56Dq0DvHKMgxC8Lp3i8azA/9hzTUgUHhVAuc=; b=r/iXQPbbnsKCMRxrbNS2pI3oZMrQSugO7o68pMD0bMba1nS1deCwGGN4r5piP2lu0R 37rWMnHIvom+BU9waiiTGtDh1gywg+esuRAk1GnAORSjb5rOxDBSC4zp9KGkAFS/PoeC 8cfadtTyBaVeHOdBTyDJHggc8vP4e8I74JtJa2kzmwqAXCdoyWlC/LHpkdkFy/z4Uq5+ Pxa/WbxNGMZidfSQiBPACmSP/p0BLcXmPcHsTfUb5ZLBbwzrysNuK0bbsdWU2qlJABe3 Pb8X0eIy+cS+rU/+e80neH5lnGz53esaj6ulec5ddCUEQnKLhs4RE5rcuLsDpI3UhOcl 5g4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=dkUsHyj6; 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=siemens.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga32-20020a1709070c2000b006f3a79245c6si6329361ejc.941.2022.05.19.06.29.24; Thu, 19 May 2022 06:29:52 -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=@siemens.com header.s=fm1 header.b=dkUsHyj6; 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=siemens.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234618AbiESHKL (ORCPT + 99 others); Thu, 19 May 2022 03:10:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234539AbiESHJ0 (ORCPT ); Thu, 19 May 2022 03:09:26 -0400 Received: from mta-64-227.siemens.flowmailer.net (mta-64-227.siemens.flowmailer.net [185.136.64.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4360BBA542 for ; Thu, 19 May 2022 00:09:25 -0700 (PDT) Received: by mta-64-227.siemens.flowmailer.net with ESMTPSA id 20220519070923cee592c4340802a67e for ; Thu, 19 May 2022 09:09:23 +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=siZxk5R56Dq0DvHKMgxC8Lp3i8azA/9hzTUgUHhVAuc=; b=dkUsHyj6GftTTRoLVglXYo0ikvu3J+IlDqhiu32iglRObTfay5hYLm20hZVPHRS6GHZCvz W1ruzbaCL8R1J37OsdSPu5LpUhhCMDqeR2iKoUhUQY4gd6wKaoOMTKnM6ojEiZ4vipU5S3G1 +XBpzthJNC+/Bhi4hpfiaF7NK4pIg=; 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 v2 8/9] tty: n_gsm: fix resource allocation order in gsm_activate_mux() Date: Thu, 19 May 2022 09:07:56 +0200 Message-Id: <20220519070757.2096-8-daniel.starke@siemens.com> In-Reply-To: <20220519070757.2096-1-daniel.starke@siemens.com> References: <20220519070757.2096-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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 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(-) See patch 6 regarding changes since to v1. diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index dfc537eb2b49..cc349f5a37fb 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