Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1209641iob; Wed, 4 May 2022 17:32:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyADwjMImS+PO7cQFkBxnCVcmKjR8Y8Ss3ynN+7SLA/wtaenSmppRHIOlGHmEzplsNIdU5g X-Received: by 2002:a17:902:d4c2:b0:15e:aec8:6a6e with SMTP id o2-20020a170902d4c200b0015eaec86a6emr14662053plg.57.1651710769517; Wed, 04 May 2022 17:32:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651710769; cv=none; d=google.com; s=arc-20160816; b=X8ab+SMJNvqHvImxu1K5z2A8y211QwxhH+soZPfN79mPxJCyjgtcGbVuTQPOOGBQVc 9lTCUlbAvCIzTi49qnKQwB0QGO0OSsnMTPE4tdB7mcD0UEdl47C0rhJMgwHOR1p0SMhY N9lPxHELJqoU8mMZnptJxyu4k3kgPK72JU5dqF3LFfrQ8SveEFe5KdTE0WL1+yvR8PbD cdwcxlnoEFogfPiw0Ox3ZHfJJtLKKx4bkGJFeToEAeYm48aBoLM3vKkq2FChyY9ctHyW wQpid6yw6l7I+4K30JUswifm2Vs4rMSb1RJsPSFmtsxnKTKCBcT1/nVa49j6mKe1yseg Ljhw== 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=WhPoFtDqvizzbQvy78qyPCfyT2+pn8RfDo9Ps91P4Fg=; b=b0go/lLyuFa/8enhBH5lr/LmTi1/ME62gpNYVxE9VHlV4kpyy3dV9QjDpF+hs0rYkU k1uyK/y2XeyS5WD/K1HC2POtNowLyRFVqtDnE/trdJttkya7C17pPr/spFJqmGcvnvZj IqgnSAu9TFYAuB+Q5r5FRrKJkNLF8IzV5b3hfskD3VVnBpxB1yC59IsOvnTgSTlYU8U9 HxZrw1CWtmXcmY6BaPU6CoCMz3maImmHHrAcgkBuMRGyqHDLq1FyJph1hTALT33y5Mdh KHlDJc5RY+296716NKm4BHBfoZp2UwVDoKdMNoCNxgjAAzNvm6sN0yb18FJgzC+Q4qLO 8eQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HXTJjvhQ; 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 d17-20020aa78691000000b004fb142acb57si20042051pfo.160.2022.05.04.17.32.34; Wed, 04 May 2022 17:32:49 -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=HXTJjvhQ; 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 S1359688AbiEDRxn (ORCPT + 99 others); Wed, 4 May 2022 13:53:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357861AbiEDRPY (ORCPT ); Wed, 4 May 2022 13:15:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9192B554B4; Wed, 4 May 2022 09:59:05 -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 EA2ED61770; Wed, 4 May 2022 16:59:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A43CFC385A4; Wed, 4 May 2022 16:59:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683543; bh=QsbfSUtuE/rLYIXT6Iqtf1hrjl1h8nMpkg8dsxIdisc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HXTJjvhQHoq2iKohn/+yZze9HQDW9pBRZOhV+W1pKIe6vcTAi+Czxb4bFcFViVAld 14W/YGe7gQoYFkyOs/ObPFP4hQ9Hbq7mCfLzlWr1kuyDDyQnfEA2nHog9MgDiGmool B3xaaCVkNHE42chyF4jOIwFBXJiM9H5Ok/ovziJQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Starke Subject: [PATCH 5.17 214/225] tty: n_gsm: fix wrong signal octets encoding in MSC Date: Wed, 4 May 2022 18:47:32 +0200 Message-Id: <20220504153129.063028650@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153110.096069935@linuxfoundation.org> References: <20220504153110.096069935@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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 commit 317f86af7f5d19f286ed2d181cbaef4a188c7f19 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. The value of the modem status command (MSC) frame contains an address field, control signal and optional break signal octet. The address field is encoded as described in chapter 5.2.1.2 with only one octet (may be extended to more in future versions of the standard). Whereas the control signal and break signal octet are always one byte each. This is strange at first glance as it makes the EA bit redundant. However, the same two octets are also encoded as header in convergence layer type 2 as described in chapter 5.5.2. No header length field is given and the only way to test if there is an optional break signal octet is via the EA flag which extends the control signal octet with a break signal octet. Now it becomes obvious how the EA bit for those two octets shall be encoded in the MSC frame. The current implementation treats the signal octet different for MSC frame and convergence layer type 2 header even though the standard describes it for both in the same way. Use the EA bit to encode the signal octets not only in the convergence layer type 2 header but also in the MSC frame in the same way with either 1 or 2 bytes in case of an optional break signal. Adjust the receiving path accordingly in gsm_control_modem(). Fixes: 3ac06b905655 ("tty: n_gsm: Fix for modems with brk in modem status control") Cc: stable@vger.kernel.org Signed-off-by: Daniel Starke Link: https://lore.kernel.org/r/20220414094225.4527-13-daniel.starke@siemens.com Signed-off-by: Greg Kroah-Hartman --- drivers/tty/n_gsm.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -1094,7 +1094,6 @@ static void gsm_control_modem(struct gsm { unsigned int addr = 0; unsigned int modem = 0; - unsigned int brk = 0; struct gsm_dlci *dlci; int len = clen; int slen; @@ -1124,17 +1123,8 @@ static void gsm_control_modem(struct gsm return; } len--; - if (len > 0) { - while (gsm_read_ea(&brk, *dp++) == 0) { - len--; - if (len == 0) - return; - } - modem <<= 7; - modem |= (brk & 0x7f); - } tty = tty_port_tty_get(&dlci->port); - gsm_process_modem(tty, dlci, modem, slen); + gsm_process_modem(tty, dlci, modem, slen - len); if (tty) { tty_wakeup(tty); tty_kref_put(tty); @@ -2963,8 +2953,10 @@ static int gsmtty_modem_update(struct gs int len = 2; modembits[0] = (dlci->addr << 2) | 2 | EA; /* DLCI, Valid, EA */ - modembits[1] = (gsm_encode_modem(dlci) << 1) | EA; - if (brk) { + if (!brk) { + modembits[1] = (gsm_encode_modem(dlci) << 1) | EA; + } else { + modembits[1] = gsm_encode_modem(dlci) << 1; modembits[2] = (brk << 4) | 2 | EA; /* Length, Break, EA */ len++; }