Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3114710rwb; Mon, 15 Aug 2022 18:28:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR5dfRJk6lIwhXAkOU6fJh5ginaRlrEoFp6s4QkFq3XimAIvPXo+SZ77cv6Kl0dYE7Yj9aqK X-Received: by 2002:a63:cf4f:0:b0:429:9cea:5a4a with SMTP id b15-20020a63cf4f000000b004299cea5a4amr1744265pgj.508.1660613295926; Mon, 15 Aug 2022 18:28:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660613295; cv=none; d=google.com; s=arc-20160816; b=vombArro3XdVj0xpw0FjC+lcS1VXxZVgTB2zCptWU0LPtPADcBZdMhNnvt3axNS9zY 4IANP1jYgYgwSTDykK/gbC5tpwg7eyKKlZDK+vgdUEtpc0LWT7DAhBj+PiyLBYYYTn80 avg4ERoiIntimcayxXuPmgCbArWD+WKgh5UupTcGXjhZpZ0w03UUZvpQx5nCpfKjtWEt GLoqyUyQmJExw8AEIp4sPyAbje2tmTUUqVpmw3l9WYBOAnyEiWpbMjUkPL2N6JHIYrjA SK698y1QLFyR1ezKTilbGWwQIClCi/RLonCN3aYHwTNMgbVIYbhP1YVvYPtmLPRGWHLG uicA== 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=OhJgVdIMA8bwUuJAYyGzW9rHz2KGrCgX32LfzlN4SY8=; b=xbQV/NWPEAv/ISNhqqw4eDe+9DuHgip0c5s7RUImrFjVdJ66lxbK+a6UrDEdVZOC/6 cr4KURICjnwct5SLVCOCLaLQP/8GCqaPqoG29cYQnR8FJBkJmzZPnCzG2cYACFnsT1h5 Q8MxD9tQCncPhpLCq/rm0WvD7WOo0dvbx8T5aWylW3vk9yr6ifup+R6BXEIPl++RJTgq VMbH2nKipbQ3QUcsQTMUGg5X4g6qDZr0c7CY4FDxsgS+RLWj6PGrfgdvi+jwIR4eEwMw 0yOOWO7Dy1uGvNnu+82N6mK2ykuPvz8YLqkd8Lm6wFb5N/M8jb6WKeQUzSTjFlanIeBD WODw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JpEbhb1Z; 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 d20-20020a170902729400b001713d5d096esi12528207pll.14.2022.08.15.18.28.05; Mon, 15 Aug 2022 18:28:15 -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=JpEbhb1Z; 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 S233397AbiHPAnC (ORCPT + 99 others); Mon, 15 Aug 2022 20:43:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348485AbiHPAlN (ORCPT ); Mon, 15 Aug 2022 20:41:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 213C018EC03; Mon, 15 Aug 2022 13:39:10 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 0EF0C60F60; Mon, 15 Aug 2022 20:39:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECBA0C433C1; Mon, 15 Aug 2022 20:39:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595948; bh=W7ZbxTzbrjgCfgA37ZBvfWuULqJ8CDX3u2gcrKBCC/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JpEbhb1ZL0Wqrszv+yQN3fgXIwGFI8NDVxfF+HKgdvhBtfYs6FrSF+ai+To6RIeku 181Xc9zNbIjEMKHytLSzDrSy+6fuZ1dlKQhNDl1RxCn7g7U+CzBiqvwL5NKdnmCCTu Gier+D646mksChVj3vuU6MY++hM4rYvbI8k1thQw= 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.19 0925/1157] tty: n_gsm: fix user open not possible at responder until initiator open Date: Mon, 15 Aug 2022 20:04:41 +0200 Message-Id: <20220815180516.467099678@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 [ 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@siemens.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 fd4d24f61c46..5a0fd35ce1f9 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 = 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); @@ -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 = DLCI_OPEN; + dlci->constipated = 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 *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 @@ -1762,10 +1784,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; } @@ -3174,6 +3199,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.35.1