Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp978523pxb; Fri, 15 Apr 2022 17:14:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxv+jx3gKOUqRYN3qMh3rdWbrUiICLluMR/T34ezv2dynflJrweXHbdzohaxdnjSqtYH6sR X-Received: by 2002:a17:902:bcc2:b0:14f:23c6:c8c5 with SMTP id o2-20020a170902bcc200b0014f23c6c8c5mr1387878pls.131.1650068049648; Fri, 15 Apr 2022 17:14:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650068049; cv=none; d=google.com; s=arc-20160816; b=tXS0cw4khd2vEd8O8W+IDWloqFnoNiIVNnCxkw+2Gb+pTSBepSbjLs6eMj91gftHiW Nq6Rc5URyWx5bAo+sPOsdSafkVBSR40rqpqI2o0LrxNFQ9Nnkv6j5la3mLY5yCcMxl// xzwatchLtkI+T2lgmcoxJm7h4xqKPudI4vI8UKf5PIbyUWdiTcG1vXS4zt3izjVhEQ1z KEzTWI3SxrDsD9gxCNjaCQ48IV2NifmTiRYtNZsI9TnxjpMJ0ZmTnL8d6b2z7ClAtgQA 4pAY5ydPrcmznUg//qvrVlsKK7GUVdW4bNrp0dnSK/cCGQDRV8JKdkeAMSlJU4b80Bwg HWyw== 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=4xST5nXMealzJWOxw0+fWFESwSlcs/PlqI2uAm5csAw=; b=E+dMT6vZX3ReOsuAHqEFl1cbWoCOjeRq79kvgzaYs7mt09ZKPNu5TL5Y4kcVsXYLF4 tpfpEQupdox+cvOZrqtVRRwGMtTmrRrZ1E9wbB/5e0cZSGfVinWg4PtjpC6JtMI/bDoe 9ot1x8qDDPiKAiRFzXN/S+1gWJQD/DlOrwcRF50ObIUx4U+gWZXwVja6xWkFg+xCh5qb a3Ei/ZNksCJ71vWfFCypRrp/gu7dCz0APKhI5YePAD304ATbbA+WUo5t4gflnmjFnAPi 8o39H0sslQzvn+IklVsFwxi58c2vQMwZwQXqKAJeEyNWlj4sKGXKxwch0pkZi8PTP4do PshA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=Yl0EQYXr; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id 143-20020a630495000000b0039da9ed215fsi2813095pge.107.2022.04.15.17.14.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:14:09 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=Yl0EQYXr; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 9EDC95F261; Fri, 15 Apr 2022 17:13:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242010AbiDNJsw (ORCPT + 99 others); Thu, 14 Apr 2022 05:48:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241966AbiDNJqn (ORCPT ); Thu, 14 Apr 2022 05:46:43 -0400 X-Greylist: delayed 62 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 14 Apr 2022 02:44:01 PDT Received: from mta-64-225.siemens.flowmailer.net (mta-64-225.siemens.flowmailer.net [185.136.64.225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C8DA6E54C for ; Thu, 14 Apr 2022 02:44:01 -0700 (PDT) Received: by mta-64-225.siemens.flowmailer.net with ESMTPSA id 20220414094251f0f4b22f51d08a3779 for ; Thu, 14 Apr 2022 11:42:57 +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=4xST5nXMealzJWOxw0+fWFESwSlcs/PlqI2uAm5csAw=; b=Yl0EQYXrkCNaKKsvBtvQlMTcSanTd8OQSDD1ocSkKm4p2tyWLt77g1rJ5lsKVmnhjPkTSv V1q+QzaP1eURa4Y1KGuxLsrk8/7FJrFrX1Qa7cf7tWYFqd0IPNia6TmqR2RxhLRuk1moP9IS +q42CDQ4uiCJIl8SKVubXMIKKVOhA=; 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 17/20] tty: n_gsm: fix reset fifo race condition Date: Thu, 14 Apr 2022 02:42:22 -0700 Message-Id: <20220414094225.4527-17-daniel.starke@siemens.com> In-Reply-To: <20220414094225.4527-1-daniel.starke@siemens.com> References: <20220414094225.4527-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 gsmtty_write() and gsm_dlci_data_output() properly guard the fifo access. However, gsm_dlci_close() and gsmtty_flush_buffer() modifies the fifo but do not guard this. Add a guard here to prevent race conditions on parallel writes to the fifo. Fixes: e1eaea46bb40 ("tty: n_gsm line discipline") Cc: stable@vger.kernel.org Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index f4ec48c0d6d7..1e135a71860f 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -1446,13 +1446,17 @@ static int gsm_control_wait(struct gsm_mux *gsm, struct gsm_control *control) static void gsm_dlci_close(struct gsm_dlci *dlci) { + unsigned long flags; + del_timer(&dlci->t1); if (debug & 8) pr_debug("DLCI %d goes closed.\n", dlci->addr); dlci->state = DLCI_CLOSED; if (dlci->addr != 0) { tty_port_tty_hangup(&dlci->port, false); + spin_lock_irqsave(&dlci->lock, flags); kfifo_reset(&dlci->fifo); + spin_unlock_irqrestore(&dlci->lock, flags); /* Ensure that gsmtty_open() can return. */ tty_port_set_initialized(&dlci->port, 0); wake_up_interruptible(&dlci->port.open_wait); @@ -3150,13 +3154,17 @@ static unsigned int gsmtty_chars_in_buffer(struct tty_struct *tty) static void gsmtty_flush_buffer(struct tty_struct *tty) { struct gsm_dlci *dlci = tty->driver_data; + unsigned long flags; + if (dlci->state == DLCI_CLOSED) return; /* Caution needed: If we implement reliable transport classes then the data being transmitted can't simply be junked once it has first hit the stack. Until then we can just blow it away */ + spin_lock_irqsave(&dlci->lock, flags); kfifo_reset(&dlci->fifo); + spin_unlock_irqrestore(&dlci->lock, flags); /* Need to unhook this DLCI from the transmit queue logic */ } -- 2.25.1