Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp865541pxb; Tue, 1 Feb 2022 12:03:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJy6X3zHxvHA5rFD0/eWVoRwqHQ72mew7FVuR0+xfNV9UmgQSpmZj1sdD8m+2ODOqDyyVo1A X-Received: by 2002:a17:902:9a06:: with SMTP id v6mr10311308plp.109.1643745786699; Tue, 01 Feb 2022 12:03:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643745786; cv=none; d=google.com; s=arc-20160816; b=h4DsZik6dt3O5/g2qA1tUFlIjwADJuCICCFpRlpSqcu3ncTRsAsx0A+uYEh9hu7BcJ CHSWrB9Ul34iLUZD4gGce8uOBKK/OT/yhGmY/QlnexClFdHK+VTRMrhn0DqHEiKE47AE PfWUuMm4gULH5x0xcdEquVdftDfAXD7iZ3jBT9PghJNp2TCwgsiVGBPWAbyKwbrQ5w9a SmVHACEBgPpfBvE69qSwDocwhyqhYKUb1kl8Ahu+KYLa9kOMCqc7iePF3+sCZR6ikIrv Q4sAISa9+oe1BTQSad8Ga11HcnbgAyAzgHbWDo8HS4/WSQckxa2nqXnTLu/48c/hcSfh 2TtQ== 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=JHFTll9vN8sMsDCOp0GNF1Ty66QsLM0I+o1vBpkGS6A=; b=x1jLYBcuAtSIacQCko2iP8d/CpSESv3UelLOql0EE8IAbovp48G5Zp1C4pEB4lw0GT fWUJtaionhMmDP9Ru6z2u99W236PSMFW9g+5jHG5o/UsbHYt07MHndifFM2Eqlw61Abs HZ2JhnIx4qIpcLB1q9ZagTw0Lx50e4nNIGsX1Hk4fYhOqe2EllFV9QnN6YdSh/654HUT rdrfWdn1a1ZhaOIaMsRwsSTfTTCxwd4PmQJFReZpQbgdTl0aPIKBWDVyiW+y/txXljF+ Xd7DFCJa1snyAwQL0p7ytlEd7dq3fGqKopnPouHkXN8qhlSa1HGCL9qNhsx47yCkKPTt EArA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HapNBTCI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u190si16670208pgd.227.2022.02.01.12.02.55; Tue, 01 Feb 2022 12:03:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HapNBTCI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S240494AbiAaLOE (ORCPT + 99 others); Mon, 31 Jan 2022 06:14:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377564AbiAaLKM (ORCPT ); Mon, 31 Jan 2022 06:10:12 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CED51C06173B; Mon, 31 Jan 2022 03:08:52 -0800 (PST) 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 6C34361139; Mon, 31 Jan 2022 11:08:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42055C340E8; Mon, 31 Jan 2022 11:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643627331; bh=l5n9EoLiSTCIVosUiCFzhvPYXWqO3rq1EB8MKnb1+N0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HapNBTCIMn7iLagp5bh0WvwXNjO3zvHzAxJvUQaJHKeOtbcqYrMlTSPLSJ7n0uZf9 8jp43CrJ9ig35YLNLwmUP3dBZkcUXgA8iRa+4hW+QLe7ZQOWjD2iABn873whyskUsq SuGMEl8fXLFfxLtbxhVAKLVi16HVAL1CkdhLzIGI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Starke Subject: [PATCH 5.15 049/171] tty: n_gsm: fix SW flow control encoding/handling Date: Mon, 31 Jan 2022 11:55:14 +0100 Message-Id: <20220131105231.689275464@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220131105229.959216821@linuxfoundation.org> References: <20220131105229.959216821@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: daniel.starke@siemens.com commit 8838b2af23caf1ff0610caef2795d6668a013b2d upstream. n_gsm is based on the 3GPP 07.010 and its newer version is the 3GPP 27.010. See https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1516 The changes from 07.010 to 27.010 are non-functional. Therefore, I refer to the newer 27.010 here. Chapter 5.2.7.3 states that DC1 (XON) and DC3 (XOFF) are the control characters defined in ISO/IEC 646. These shall be quoted if seen in the data stream to avoid interpretation as flow control characters. ISO/IEC 646 refers to the set of ISO standards described as the ISO 7-bit coded character set for information interchange. Its final version is also known as ITU T.50. See https://www.itu.int/rec/T-REC-T.50-199209-I/en To abide the standard it is needed to quote DC1 and DC3 correctly if these are seen as data bytes and not as control characters. The current implementation already tries to enforce this but fails to catch all defined cases. 3GPP 27.010 chapter 5.2.7.3 clearly states that the most significant bit shall be ignored for DC1 and DC3 handling. The current implementation handles only the case with the most significant bit set 0. Cases in which DC1 and DC3 have the most significant bit set 1 are left unhandled. This patch fixes this by masking the data bytes with ISO_IEC_646_MASK (only the 7 least significant bits set 1) before comparing them with XON (a.k.a. DC1) and XOFF (a.k.a. DC3) when testing which byte values need quotation via byte stuffing. Fixes: e1eaea46bb40 ("tty: n_gsm line discipline") Cc: stable@vger.kernel.org Signed-off-by: Daniel Starke Link: https://lore.kernel.org/r/20220120101857.2509-1-daniel.starke@siemens.com Signed-off-by: Greg Kroah-Hartman --- drivers/tty/n_gsm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -318,6 +318,7 @@ static struct tty_driver *gsm_tty_driver #define GSM1_ESCAPE_BITS 0x20 #define XON 0x11 #define XOFF 0x13 +#define ISO_IEC_646_MASK 0x7F static const struct tty_port_operations gsm_port_ops; @@ -527,7 +528,8 @@ static int gsm_stuff_frame(const u8 *inp int olen = 0; while (len--) { if (*input == GSM1_SOF || *input == GSM1_ESCAPE - || *input == XON || *input == XOFF) { + || (*input & ISO_IEC_646_MASK) == XON + || (*input & ISO_IEC_646_MASK) == XOFF) { *output++ = GSM1_ESCAPE; *output++ = *input++ ^ GSM1_ESCAPE_BITS; olen++;