From nobody Fri Oct 24 20:29:27 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 184CCC3F6B0 for ; Mon, 15 Aug 2022 22:38:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350167AbiHOWfv (ORCPT ); Mon, 15 Aug 2022 18:35:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351199AbiHOW1v (ORCPT ); Mon, 15 Aug 2022 18:27:51 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A3CB6E8BB; Mon, 15 Aug 2022 12:47:35 -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 sin.source.kernel.org (Postfix) with ESMTPS id 5220CCE1262; Mon, 15 Aug 2022 19:47:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F4E1C433C1; Mon, 15 Aug 2022 19:47:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592851; bh=3L4T/m9YgJO7JlfsOZH6grUtry7M7JcMnJO4As2Penk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IY8EwQuGodfZot181YLg7VD2DtjckAm7UzH+UAHB5eLI3lJ2f/Taw5AeigowJR38B 6+Nv3rqZuMhuqFsS9OaxulNpHtxKtccu6PUZbzZkywlYU/KVLNDPiQIgim5tfik1aU +YXP7b6n+35Oj8aaeECdTVfkWk7QBaOP+zlwNRME= 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 0854/1095] tty: n_gsm: fix user open not possible at responder until initiator open Date: Mon, 15 Aug 2022 20:04:13 +0200 Message-Id: <20220815180504.657385062@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-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Daniel Starke [ Upstream commit ac77f0077c3265197d378158c85a55eee6d21508 ] After setting up the control channel on both sides the responder side may want to open a virtual tty to listen on until the initiator starts an application on a user channel. The current implementation allows the open() but no other operation, like termios. These fail with EINVAL. The responder sided application has no means to detect an open by the initiator sided application this way. And the initiator sided applications usually expect the responder sided application to listen on the user channel upon open. Set the user channel into half-open state on responder side once a user application opens the virtual tty to allow IO operations on it. Furthermore, keep the user channel constipated until the initiator side opens it to give the responder sided application the chance to detect the new connection and to avoid data loss if the responder sided application starts sending before the user channel is open. Fixes: e1eaea46bb40 ("tty: n_gsm line discipline") Signed-off-by: Daniel Starke Link: https://lore.kernel.org/r/20220701061652.39604-1-daniel.starke@siemen= s.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/n_gsm.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 9f2a8c0e1e33..e15b3b107b5e 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -1510,6 +1510,8 @@ static void gsm_dlci_close(struct gsm_dlci *dlci) if (debug & 8) pr_debug("DLCI %d goes closed.\n", dlci->addr); dlci->state =3D DLCI_CLOSED; + /* Prevent us from sending data before the link is up again */ + dlci->constipated =3D true; if (dlci->addr !=3D 0) { tty_port_tty_hangup(&dlci->port, false); spin_lock_irqsave(&dlci->lock, flags); @@ -1539,6 +1541,7 @@ static void gsm_dlci_open(struct gsm_dlci *dlci) del_timer(&dlci->t1); /* This will let a tty open continue */ dlci->state =3D DLCI_OPEN; + dlci->constipated =3D false; if (debug & 8) pr_debug("DLCI %d goes open.\n", dlci->addr); /* Send current modem state */ @@ -1619,6 +1622,25 @@ static void gsm_dlci_begin_open(struct gsm_dlci *dlc= i) mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); } =20 +/** + * gsm_dlci_set_opening - change state to opening + * @dlci: DLCI to open + * + * Change internal state to wait for DLCI open from initiator side. + * We set off timers and responses upon reception of an SABM. + */ +static void gsm_dlci_set_opening(struct gsm_dlci *dlci) +{ + switch (dlci->state) { + case DLCI_CLOSED: + case DLCI_CLOSING: + dlci->state =3D DLCI_OPENING; + break; + default: + break; + } +} + /** * gsm_dlci_begin_close - start channel open procedure * @dlci: DLCI to open @@ -1762,10 +1784,13 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_m= ux *gsm, int addr) dlci->addr =3D addr; dlci->adaption =3D gsm->adaption; dlci->state =3D DLCI_CLOSED; - if (addr) + if (addr) { dlci->data =3D gsm_dlci_data; - else + /* Prevent us from sending data before the link is up */ + dlci->constipated =3D true; + } else { dlci->data =3D gsm_dlci_command; + } gsm->dlci[addr] =3D dlci; return dlci; } @@ -3178,6 +3203,8 @@ static int gsmtty_open(struct tty_struct *tty, struct= file *filp) /* Start sending off SABM messages */ if (gsm->initiator) gsm_dlci_begin_open(dlci); + else + gsm_dlci_set_opening(dlci); /* And wait for virtual carrier */ return tty_port_block_til_ready(port, tty, filp); } --=20 2.35.1