From patchwork Wed Oct 11 18:15:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 732393 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C4CFCDB477 for ; Wed, 11 Oct 2023 18:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235128AbjJKSQZ (ORCPT ); Wed, 11 Oct 2023 14:16:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235132AbjJKSQS (ORCPT ); Wed, 11 Oct 2023 14:16:18 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2048.outbound.protection.outlook.com [40.107.22.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DCDCCC; Wed, 11 Oct 2023 11:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SlTzpTC8AATVaJOegdOeFwuXchrUbHiyLGrrrwd/l/bqrccBIckkXFfg1Oz3CuoGz7UOBc32dfnkEKhSikMsF3UtwRmySfrsfxAJo25FcwXvc8lFM26LmAr5r7Xa1T6zEkQf86kw64ChWnAEazMulgUWprUKzl0F1wQwwEtcOm9m9mFVF0E2IZmMPsRqOvXq3nzHgxZnvZPDvoDo64RBfyKHV9st5ZObMIhZh3dv+YHY1mLd61wmRpq66yPeeUsZ+KnGFt3GlmRdh3wf5Q/xSLBta3KBKLRyw4/iw9ePJ5J4c10G6Up+snRDelHoFxFCQN+EprrW7vbSr8aqg+9spQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TJ5/eJP8FSTSE85vf+YgYI2YYEXaQjMZKL7yA99JX58=; b=NBLgAoDMSmCfBpfit9+AEkAJ/JXtK0R5RUhjM+dpUk1x3dcH5xZKkUiYRC7XzuIuVuF596d3E79yhWaJeUPGRTKdqudlZnkDZvULWxvHYVaOzNiW6hBp3mWj8qPmpy6OuFKPXYp4TmdCfn1yeclOsoGMPS7meZHsbEng4URRo5fKFZIw1RvjrJCx7Nscd/AR1EUO9sSSnm8fJVOfayPBYS43stVtKEcT3iJLBgWXe3J3EZG4JyH0L14CMo1bMuPi/YIXPLliIw7xVmeWBBTQyz097wSD3qqr7eHeQ9z0iTwzJJIy8QG2e+SSVgEQrYJ80Iuc5+8YkP3LCFjUbYa/Fg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=kunbus.com; dmarc=pass action=none header.from=kunbus.com; dkim=pass header.d=kunbus.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kunbus.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TJ5/eJP8FSTSE85vf+YgYI2YYEXaQjMZKL7yA99JX58=; b=fll4aLeTaiE1OqtZpWYA3II6GUfQ/V1RKc+rTzBXsSPcY45IlJ9vVK5pkygAzp7EZj5ODn6ClYTHi52sTO8gAOC5CvVB5EFB9HfpvlrJ4EChDUyGijBHzVIwPHwG3SYGhntwRedmr7lUxTRPiKD/l2orRl5PKrSoEIaIhIR37vs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=kunbus.com; Received: from VI1P193MB0413.EURP193.PROD.OUTLOOK.COM (2603:10a6:803:4e::14) by AS8P193MB1925.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:3fa::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.38; Wed, 11 Oct 2023 18:16:12 +0000 Received: from VI1P193MB0413.EURP193.PROD.OUTLOOK.COM ([fe80::550d:2425:c0ed:3e59]) by VI1P193MB0413.EURP193.PROD.OUTLOOK.COM ([fe80::550d:2425:c0ed:3e59%3]) with mapi id 15.20.6863.032; Wed, 11 Oct 2023 18:16:12 +0000 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com Cc: shawnguo@kernel.org, s.hauer@pengutronix.de, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, cniedermaier@dh-electronics.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com, Lino Sanfilippo , stable@vger.kernel.org Subject: [PATCH v3 4/6] serial: core: make sure RS485 cannot be enabled when it is not supported Date: Wed, 11 Oct 2023 20:15:42 +0200 Message-Id: <20231011181544.7893-5-l.sanfilippo@kunbus.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231011181544.7893-1-l.sanfilippo@kunbus.com> References: <20231011181544.7893-1-l.sanfilippo@kunbus.com> X-ClientProxiedBy: FR3P281CA0163.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a2::9) To VI1P193MB0413.EURP193.PROD.OUTLOOK.COM (2603:10a6:803:4e::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1P193MB0413:EE_|AS8P193MB1925:EE_ X-MS-Office365-Filtering-Correlation-Id: f4a7bee1-354d-414b-8db6-08dbca862677 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1JXLIC83BsW85iEufFa2RRHTVcjnmYU8mMIQn6OAa94EOBOeK9vXa++pjVA11e6zrIGD7lvSGD4rBtmXDDE0aO8PyuAI5XoOs1eNlbI1WSnt2VwSNukQLnaQyi9KFRkp7qncwIQO1tnz84naTj04CSgrQ08MG8eJSokOHCCMhIzVBEoGrGImylrlMaiq/ZEraNJRxXlYRM6zaxZVwuxjaegpphURRy1b76htfv/i1N+45fqs9iHkkZik49mUfVwHh5+RFlS8B7T9vYOknjV2tx7VPQQE19qW5Kil/NrpzFeZBeJIXPP9g8DoM9QnkO/yykSCLmF44JIaYOD3RGlBQYmfCcZTxery/Upjq8fy5GUCArlRkBO7TvT1/QDnWSW98eeEt2VXr6jz/I71zAd6Ua1NVlBfsl/TtncOnyfrk8mo0z+IlZxfa/AOq1028NPYFxrLrJpM2Iqb9n9T6w51Zj7YhiXPVmCjhMWguOYo1h5vFmm8Qi6WeYB0wCTjcJPqJtNFPNRWteWd6wd5/qHQbeAkB0UaBlJY/vV9upgGifGXbXhuSWsA5ZIZrerep7Q+ X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1P193MB0413.EURP193.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230031)(366004)(39840400004)(396003)(346002)(376002)(136003)(230922051799003)(451199024)(1800799009)(186009)(64100799003)(36756003)(6666004)(52116002)(83380400001)(6506007)(6486002)(6512007)(1076003)(2616005)(4326008)(41300700001)(2906002)(478600001)(8676002)(8936002)(5660300002)(7416002)(66556008)(316002)(66946007)(66476007)(86362001)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7BRi2tYxfBa5bDJU+ZHMrI/poYhAUMY5Q/Da3aeM45p+hFBUgL9opQiqFZwV/NGlaus7B2MggFO4VTvVWa7Pzf0Zqk85IsUs5/vOZ9f2dwjYrNq3q1fn+GsSCfrns/51YUrv/fACjCFKo+9VgS2iXTrSOw3k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6Ao0wab1FVg/WfcNoFSb3ynz1bf7PbFHiLPKxAnGA/gHmFN0NvDYlrPFGm7kyJFIlqLCn7y3uyoUpBIRUlCOr/PZNznKcUPFIOJ1nBR137gtX5Ve64+4oh98udYUcxzxpo292+zt2obY5ttpy8BTCdewp1KaJaedL82kJgs6s9LZaUH3T7IcTgXjwyKhKclYCwGxSwM2/aD8LRRH0eaDffAQDkWBFn/uc2tBuFPysWwaUlohbkidsZYCjCCqBL67yR7wE+Rkrydb2nBxVwQtCBjEHXJHfjZoVn6+dOHeXTXkJNJ6fXi0Fcmguc9oCv5w/k0dFQNPFj+gwzCqgV4dqXjYOAGN1D5dZ2S6dQx78V5TJxWI4L6RMMfixd7n5JZ/Tf5IWq5BBTe2JL2i+VJmvLp3ZETp6HmpBOoQEG1L8vqjWiEIY9jEI X-OriginatorOrg: kunbus.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4a7bee1-354d-414b-8db6-08dbca862677 X-MS-Exchange-CrossTenant-AuthSource: VI1P193MB0413.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2023 18:16:12.3864 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: aaa4d814-e659-4b0a-9698-1c671f11520b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: WE7OCKWKnzBs4RaaoKuG7ICatYY7wgRS7+ZweWkilPi32dvZOLaePMycwh3ECbz5oyg/wtfGTSmjeGHL0YJX6g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8P193MB1925 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Some uart drivers specify a rs485_config() function and then decide later to disable RS485 support for some reason (e.g. imx and ar933). In these cases userspace may be able to activate RS485 via TIOCSRS485 nevertheless, since in uart_set_rs485_config() an existing rs485_config() function indicates that RS485 is supported. Make sure that this is not longer possible by checking the uarts rs485_supported.flags instead and bailing out if SER_RS485_ENABLED is not set. Furthermore instead of returning an empty structure return -ENOTTY if the RS485 configuration is requested via TIOCGRS485 but RS485 is not supported. This has a small impact on userspace visibility but it is consistent with the -ENOTTY error for TIOCGRS485. Fixes: e849145e1fdd ("serial: ar933x: Fill in rs485_supported") Fixes: 55e18c6b6d42 ("serial: imx: Remove serial_rs485 sanitization") Cc: stable@vger.kernel.org Signed-off-by: Lino Sanfilippo --- drivers/tty/serial/serial_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index f4feebf8200f..dca09877fabc 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1432,6 +1432,9 @@ static int uart_get_rs485_config(struct uart_port *port, unsigned long flags; struct serial_rs485 aux; + if (!(port->rs485_supported.flags & SER_RS485_ENABLED)) + return -ENOTTY; + spin_lock_irqsave(&port->lock, flags); aux = port->rs485; spin_unlock_irqrestore(&port->lock, flags); @@ -1449,7 +1452,7 @@ static int uart_set_rs485_config(struct tty_struct *tty, struct uart_port *port, int ret; unsigned long flags; - if (!port->rs485_config) + if (!(port->rs485_supported.flags & SER_RS485_ENABLED)) return -ENOTTY; if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user)))