Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp1110178pxb; Fri, 18 Feb 2022 00:32:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJz6k6FNpJ+7xH8MVfpDVWmPIysGeRP7U7zkl97teJ/Yvb6kCQ3gx6Bdmv0IFm+VByveb0qQ X-Received: by 2002:a17:902:6b8b:b0:14d:66c4:f704 with SMTP id p11-20020a1709026b8b00b0014d66c4f704mr6592526plk.53.1645173150489; Fri, 18 Feb 2022 00:32:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645173150; cv=none; d=google.com; s=arc-20160816; b=sYXTJHHP7l9tM/398o4CTw7zTpod6HPUkLNJwvYq7qE9Dg+5XDHm7gPPRZtvgKqJzB l7HBQJKbhCiweR9xQoweIfoNVKEkrrZdVaJxD/3ZHDWBJNVj+wnK+6eCY/BvKcGv3yAT jBa5RqWhAnpGe9GNQmZQzJoRFmXCzgkzyOLDFNHyHTdXahQ6D8pL/D6MwKk0ZxDDDEl7 V5MfeBujyRUfWKENlKpOFBuXOfE8zSeoihjxmoR7rogqgbzfOzzYaPK9gZBBXAUcKEjF VzBpNAsU8F6eMLcR8voHX2Ps8wQuCL1SERVYr8LJfmvleKPGu5SwyYZyNwC1SSBy1bZZ wFug== 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=KfUFvuO54gY4cbXI1dahueFHMXJHTWnwzef7BbWNc6c=; b=o5TpcuvQctvrwNrR/wEzteehE3F3A2AkfZ7OocIheQ+0s4xN6c0z4RQ/QXIygQICVB RyhNyuFZ/++3Kevd7u0F2BlZoRGuo6ubi+JbBvvZnlwHNKhgxVAvldJojNplOcbsyYPb PRmsThsZHhFHauAWD+PGntrxN8gZw0+56dfLkPZ/bOtUgULSiyLr2c12QwffIW9NE7Tl JUnOTwZluHKKKgnMQ+0/d0IfK4F3rph3046djLFFvlLrxo69JNcxu07K04q9Tn6vabsf 78MilFuUEvp1TkJsbD9rmSYNOhXjurLmn527zc5ylJcPy3harBvDmwJYHjyzGJhC5N4S wS0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=O9UGHGSP; 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 j18si7455899plj.459.2022.02.18.00.32.15; Fri, 18 Feb 2022 00:32:30 -0800 (PST) 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=O9UGHGSP; 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 S232131AbiBRHdN (ORCPT + 99 others); Fri, 18 Feb 2022 02:33:13 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232132AbiBRHdB (ORCPT ); Fri, 18 Feb 2022 02:33:01 -0500 X-Greylist: delayed 65 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 17 Feb 2022 23:32:40 PST Received: from mta-65-225.siemens.flowmailer.net (mta-65-225.siemens.flowmailer.net [185.136.65.225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F26A2299270 for ; Thu, 17 Feb 2022 23:32:40 -0800 (PST) Received: by mta-65-225.siemens.flowmailer.net with ESMTPSA id 20220218073130a85e878b6b62c314ae for ; Fri, 18 Feb 2022 08:31:31 +0100 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=KfUFvuO54gY4cbXI1dahueFHMXJHTWnwzef7BbWNc6c=; b=O9UGHGSPxTOF7scuo6CPUtYXJN/BNroeFPeWw68r05IIkpuLCMUTQ+YM62Sw4TQ/IDu4E6 tr1lDndb7aPSzVIeb3YPuxqHaRKeyZy5ts+slkOrcnOUX8B6OpnoohbrbkOc+lp89iwqjSHW Q4kcxhQBCaGhHgWy/FwaoGW0n8SjI=; From: daniel.starke@siemens.com To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH 6/7] tty: n_gsm: fix wrong modem processing in convergence layer type 2 Date: Thu, 17 Feb 2022 23:31:22 -0800 Message-Id: <20220218073123.2121-6-daniel.starke@siemens.com> In-Reply-To: <20220218073123.2121-1-daniel.starke@siemens.com> References: <20220218073123.2121-1-daniel.starke@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-7517: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,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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 The function gsm_process_modem() exists to handle modem status bits of incoming frames. This includes incoming MSC (modem status command) frames and convergence layer type 2 data frames. The function, however, was only designed to handle MSC frames as it expects the command length. Within gsm_dlci_data() it is wrongly assumed that this is the same as the data frame length. This is only true if the data frame contains only 1 byte of payload. This patch names the length parameter of gsm_process_modem() in a generic manner to reflect its association. It also corrects all calls to the function to handle the variable number of modem status octets correctly in both cases. Fixes: 7263287af93d ("tty: n_gsm: Fixed logic to decode break signal from modem status") Cc: stable@vger.kernel.org Signed-off-by: Daniel Starke --- drivers/tty/n_gsm.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 0b1808e3a912..e41508062154 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -1017,25 +1017,25 @@ static void gsm_control_reply(struct gsm_mux *gsm, int cmd, const u8 *data, * @tty: virtual tty bound to the DLCI * @dlci: DLCI to affect * @modem: modem bits (full EA) - * @clen: command length + * @slen: number of signal octets * * Used when a modem control message or line state inline in adaption * layer 2 is processed. Sort out the local modem state and throttles */ static void gsm_process_modem(struct tty_struct *tty, struct gsm_dlci *dlci, - u32 modem, int clen) + u32 modem, int slen) { int mlines = 0; u8 brk = 0; int fc; - /* The modem status command can either contain one octet (v.24 signals) - or two octets (v.24 signals + break signals). The length field will - either be 2 or 3 respectively. This is specified in section - 5.4.6.3.7 of the 27.010 mux spec. */ + /* The modem status command can either contain one octet (V.24 signals) + * or two octets (V.24 signals + break signals). This is specified in + * section 5.4.6.3.7 of the 07.10 mux spec. + */ - if (clen == 2) + if (slen == 1) modem = modem & 0x7f; else { brk = modem & 0x7f; @@ -1092,6 +1092,7 @@ static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen) unsigned int brk = 0; struct gsm_dlci *dlci; int len = clen; + int slen; const u8 *dp = data; struct tty_struct *tty; @@ -1111,6 +1112,7 @@ static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen) return; dlci = gsm->dlci[addr]; + slen = len; while (gsm_read_ea(&modem, *dp++) == 0) { len--; if (len == 0) @@ -1127,7 +1129,7 @@ static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen) modem |= (brk & 0x7f); } tty = tty_port_tty_get(&dlci->port); - gsm_process_modem(tty, dlci, modem, clen); + gsm_process_modem(tty, dlci, modem, slen); if (tty) { tty_wakeup(tty); tty_kref_put(tty); @@ -1593,6 +1595,7 @@ static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen) struct tty_struct *tty; unsigned int modem = 0; int len = clen; + int slen = 0; if (debug & 16) pr_debug("%d bytes for tty\n", len); @@ -1605,12 +1608,14 @@ static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen) case 2: /* Asynchronous serial with line state in each frame */ while (gsm_read_ea(&modem, *data++) == 0) { len--; + slen++; if (len == 0) return; } + slen++; tty = tty_port_tty_get(port); if (tty) { - gsm_process_modem(tty, dlci, modem, clen); + gsm_process_modem(tty, dlci, modem, slen); tty_kref_put(tty); } fallthrough; -- 2.25.1