Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4319669iob; Sun, 8 May 2022 09:09:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEweiVZykME33dH3mTsrJVnqJGU28DpBHBYxcEdVADB0h7F5SxqD8EbkicKqKCxooZ7HSM X-Received: by 2002:a05:6870:796:b0:da:3d6a:101d with SMTP id en22-20020a056870079600b000da3d6a101dmr5082610oab.20.1652026156186; Sun, 08 May 2022 09:09:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652026156; cv=none; d=google.com; s=arc-20160816; b=dSmr0w/Pjq0dTABW2I8du3EYss1P9cHJ7bJ4nsNz01/StAkK99ti8DXMWpi4gQ4fjF hccvAxgOa4VJrcHuDja9/jdb5M79smYhAmcYY/xk9ixMKholsJzlxqGynRVV0B2P8E4U 08k1Ho65b1htzKhOw5+drIRX4l/LdJUv9SmUMS/5p39tPc7DCTIrUxhKqvkUW+VSjuuM 6v7OUzbzxnhZnaR5l/+4YXisJ9f4sBU5q2v2QE5HeR5weMlLK1xTg9CN1UJE0z1biHYT fLeQ0t6i9pZbM+XbI6vQIkRPukvURmIxbAwtgpOc5DazWWVmMpML4CIAcDhEfEX1w07B xTVQ== 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=w7+1FyWYBp58et+MdwPYUbYFNCyrAX6GWLPQCaGa6EY=; b=kRISbZ5XY1td/ewBd0kfqoGupOQic4VpZ/vw8QteBsG7i4TmpbwcL63MM5a01X/53g onr7ZsegUkU7VWmIIU/SeGcY1BjritepwIESqpyCyBK5k9BeVSkKQiDom13qfYmc3F4l sPQtC48UGuGPv/9fDNT+goMJUpRsKXIK2HTacZQSw9oqpfGXQisf9iG1mEWIuMK88Wzt ZOHQYvgKcyIUOitSRb7JwSRfvieIcg+hFuWaOC0wcLxSiWoWl7TwPSa5i6iaAABhikZD AZCaJuImh5cAfS7Guf+lIH58/TipTd/ivaWXsyBjKt9f5B1K6CcuMicSurIKDjiw35Wt ty8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Px2DojIi; 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 lv17-20020a056871439100b000e217d47651si7326703oab.191.2022.05.08.09.09.01; Sun, 08 May 2022 09:09:16 -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=Px2DojIi; 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 S1358608AbiEDRmn (ORCPT + 99 others); Wed, 4 May 2022 13:42:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356394AbiEDRJN (ORCPT ); Wed, 4 May 2022 13:09:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AAEE49F33; Wed, 4 May 2022 09:55:07 -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 9EE83B82792; Wed, 4 May 2022 16:55:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AABFC385A4; Wed, 4 May 2022 16:55:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683305; bh=tu6l9fKoJQRRQfGhMHhs099JASbvUAe14tz+M+Fikp4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Px2DojIiu0X1elwCKkxpjkYIDCB/5aNYatAek/ubhSSwH7MNLQ5tJeUtlkNnM6HfS apqlxMGDH9d7wnyJ7Iopk0exGgYswWgs77aUQ5NlKh7pVbWReFPloKoAaOm2eN1o2n k+3Ah9aHNmOrc8rHScKE/G8VisvWirUdRm3JHEq8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Starke Subject: [PATCH 5.15 170/177] tty: n_gsm: fix reset fifo race condition Date: Wed, 4 May 2022 18:46:03 +0200 Message-Id: <20220504153108.816450783@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153053.873100034@linuxfoundation.org> References: <20220504153053.873100034@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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 commit 73029a4d7161f8b6c0934553145ef574d2d0c645 upstream. 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 Link: https://lore.kernel.org/r/20220414094225.4527-17-daniel.starke@siemens.com Signed-off-by: Greg Kroah-Hartman --- drivers/tty/n_gsm.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -1417,13 +1417,17 @@ static int gsm_control_wait(struct gsm_m 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); @@ -3078,13 +3082,17 @@ static unsigned int gsmtty_chars_in_buff 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 */ }