Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5252224ioo; Wed, 1 Jun 2022 01:24:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiKx7iquZNtuZIbXAzEsNb1OFnSP/woTMsfSiAEW0aN3/dp4dRoUqJ+9cD8kVydc+2cORj X-Received: by 2002:a17:906:6985:b0:6fe:988b:d248 with SMTP id i5-20020a170906698500b006fe988bd248mr55676623ejr.226.1654071844680; Wed, 01 Jun 2022 01:24:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654071844; cv=none; d=google.com; s=arc-20160816; b=RdqJNy/x6uEkCa6XttwhKpSB5eBhEhplbvQxz5SqfEc4PIIqpNCKFf7QdHMmvV+GH2 5suKI1L75zqb1BAqJaFszMTO03kLs5JrX0QDFBj/00SEJihNoYNzr70u7QDvxYbBVl6T K5O3cDAmof4Ibd39Go5vuVUvWAgQj71Mv1jvlCVqPbbtUtso7QKY0OZ+ootThhZfoPY0 i2a9L0tOwPdTfYnLxspFfARqUIYaFTbt7BrNKZX0/1C0SpEz6qIknG3Mgv3MwbwIOqqV MtbhO0RKWO0C47XfOpVHNkjUugOxaAebcu3EyQPBuFghV9W3eICl4Gu86y4Xs2YxoA96 /DqA== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=mYFMvHighpxQrW24VN/XpSSXp0gG09M4cv3mXdwNlWQ=; b=afOzMHBGcL/VVymgYSkokAT2AYG2DPvNZcCqm3ouJ0GemDzMe3CNGfF9yrzs9vS6e7 jsAzOmkdm//6kRTVtVZRFd7BtshN6gfW+YjGpCHSdIKWcF3Ps9RM0SBcK+aTTqqHI/RF /CdbZ0v7D0BeOb+K9JaSdZun2AEgajxdLEWJ6DHlFKgVxIelz5iZyi3/qj7Aj4D0f5t+ Dh3YRoKP9pgL/kA9ShvRb1VW2JDhA4PlqwJZpmSoLcnCPI1F4C54opedyh2fenKzoV3c R4E840dVE1r+gYkAJZs/canfdw7B4rX011d76fdKNDt1bYxozQmi9870bfAZiUrXO8r5 vDfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=Z6LdcI+x; 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 f15-20020a0564021e8f00b0042de64ca253si1302640edf.397.2022.06.01.01.23.39; Wed, 01 Jun 2022 01:24:04 -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=Z6LdcI+x; 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 S239659AbiE3Pkt (ORCPT + 99 others); Mon, 30 May 2022 11:40:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239425AbiE3Pkf (ORCPT ); Mon, 30 May 2022 11:40:35 -0400 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 81BEE20904A for ; Mon, 30 May 2022 07:47:42 -0700 (PDT) Received: by mta-64-225.siemens.flowmailer.net with ESMTPSA id 202205301446269420c907b95aae74bb for ; Mon, 30 May 2022 16:46:26 +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; bh=mYFMvHighpxQrW24VN/XpSSXp0gG09M4cv3mXdwNlWQ=; b=Z6LdcI+xXgD/tbhjrxtMIUR6Ua1gv0H/B801UgQ3msHPBKRepKGffn4ZAjjzbk6JG8iwIu ZpXhi83LiN+cRC4lXmF0+tVev/wEE+U9tDFb2wGkkuA0QQ0aXnsEW4lSEydQSy91ZLA5rXWe 2D1dfkCZitV2JTHyxIshFcl16vMkY=; 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 1/9] tty: n_gsm: fix user open not possible at responder until initiator open Date: Mon, 30 May 2022 16:45:04 +0200 Message-Id: <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.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=unavailable 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 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") Cc: stable@vger.kernel.org Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) Renamed gsm_dlci_wait_open() to gsm_dlci_set_opening() and reworded its documentation accordingly to reflect its function. This was done due to the review comment on v2. Link: https://lore.kernel.org/all/YoZtlq3RkNU56xFx@kroah.com/ Link: https://lore.kernel.org/all/20220519070757.2096-1-daniel.starke@siemens.com/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index fd8b86dde525..63314fe5e43b 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -1493,6 +1493,8 @@ static void gsm_dlci_close(struct gsm_dlci *dlci) if (debug & 8) pr_debug("DLCI %d goes closed.\n", dlci->addr); dlci->state = DLCI_CLOSED; + /* Prevent us from sending data before the link is up again */ + dlci->constipated = true; if (dlci->addr != 0) { tty_port_tty_hangup(&dlci->port, false); spin_lock_irqsave(&dlci->lock, flags); @@ -1522,6 +1524,7 @@ static void gsm_dlci_open(struct gsm_dlci *dlci) del_timer(&dlci->t1); /* This will let a tty open continue */ dlci->state = DLCI_OPEN; + dlci->constipated = false; if (debug & 8) pr_debug("DLCI %d goes open.\n", dlci->addr); /* Send current modem state */ @@ -1602,6 +1605,25 @@ static void gsm_dlci_begin_open(struct gsm_dlci *dlci) mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); } +/** + * 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 = DLCI_OPENING; + break; + default: + break; + } +} + /** * gsm_dlci_begin_close - start channel open procedure * @dlci: DLCI to open @@ -1745,10 +1767,13 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr) dlci->addr = addr; dlci->adaption = gsm->adaption; dlci->state = DLCI_CLOSED; - if (addr) + if (addr) { dlci->data = gsm_dlci_data; - else + /* Prevent us from sending data before the link is up */ + dlci->constipated = true; + } else { dlci->data = gsm_dlci_command; + } gsm->dlci[addr] = dlci; return dlci; } @@ -3163,6 +3188,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); } -- 2.34.1