From patchwork Sat Dec 9 12:58:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 752453 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=kunbus.com header.i=@kunbus.com header.b="IEZv6+qq" Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2043.outbound.protection.outlook.com [40.107.7.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B90F710D8; Sat, 9 Dec 2023 04:59:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DwGjeDt+HZ4pv0n0fE2VlrLzZcuz/qoqZrXMaTF9iZHStnKNSdLPxH6ARySb5Jw1jXkSvKNqtqVL3og30UtLQiMpyTQ5S2lTnj9NNN1PCNYP0Q2gvFufxcN7AsozpBE0kWr1+vNkBdhIpfRSV4s2lu/skq7xjBMqZvmrRiXnOAa3EkmarvtM/QuUSoWS6BSVFYtDlPZVx44n9ixPALjVhut12fKl2AhbwP6tdzEPiUNY+oTDrjiQxsHien23fC95KHM0cgR4SQyZpv0yRBYYIj58nKSfbj+CStqhNk4/xYqbgjQ7VmqsoBGXDLTsjTIME/bOlNb0VdoxQY9n/6II7w== 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=giTj5RrPHXa3a+Lx1xc7jw4vgGwf3+BKO1xkJ+5ZPDo=; b=JtaQAz+xe4nUuz2IFVNs/NueDn5wpxO0+pcEGL72H42K7nyAiOAWeMgDFlOlR5EjkOiXrvjYiX8f/OixVuQ7JBrj79ug+9f7A7znzZwP/n7l+J4e0ev59vRxuSloeyrl42e7mrrF7+ucG9Rf07jrvi5+HE9LkazlFX07o9+8nyupc70yb5Q+kLSGZMKxDvE7pQ6hFjhyYtjgAzfRYjRteYHMVZQPsyLUkn1DiCdROFItmJ4qN+Wfw5kyhsb2TLHv1dpdOzN2U8xR+GEodFZnE0zYo21BRhg0Wy524C7H04cxLPYbZJLMwfayVDdjRmy59/pm+jOfmrH7FSKftNfXgQ== 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=giTj5RrPHXa3a+Lx1xc7jw4vgGwf3+BKO1xkJ+5ZPDo=; b=IEZv6+qqSpeGVls0ymRynD9cbAk+3O6ET6NS9ugFaSnJiXkvzr3W7mkAwHr+fTIby2Qvp4bub0pj6OcqA67GHY+bpblQIX3eW3Ki6CJW7TgyVAMhCtIP7DLuti5Y5iuPdmc2knr/O1bhggwNR7Jc1aZ7SmmK9X9xk8wXMoAr6GU= 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 PR3P193MB0555.EURP193.PROD.OUTLOOK.COM (2603:10a6:102:31::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.29; Sat, 9 Dec 2023 12:59:19 +0000 Received: from VI1P193MB0413.EURP193.PROD.OUTLOOK.COM ([fe80::653f:d0f3:e7f6:8c06]) by VI1P193MB0413.EURP193.PROD.OUTLOOK.COM ([fe80::653f:d0f3:e7f6:8c06%5]) with mapi id 15.20.7068.029; Sat, 9 Dec 2023 12:59:18 +0000 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com Cc: u.kleine-koenig@pengutronix.de, shawnguo@kernel.org, s.hauer@pengutronix.de, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, cniedermaier@dh-electronics.com, hugo@hugovil.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 v5 4/7] serial: core: make sure RS485 cannot be enabled when it is not supported Date: Sat, 9 Dec 2023 13:58:33 +0100 Message-ID: <20231209125836.16294-5-l.sanfilippo@kunbus.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231209125836.16294-1-l.sanfilippo@kunbus.com> References: <20231209125836.16294-1-l.sanfilippo@kunbus.com> X-ClientProxiedBy: FR3P281CA0070.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:4b::22) To VI1P193MB0413.EURP193.PROD.OUTLOOK.COM (2603:10a6:803:4e::14) Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1P193MB0413:EE_|PR3P193MB0555:EE_ X-MS-Office365-Filtering-Correlation-Id: 3f929983-ff7a-4f98-d96f-08dbf8b6a7e9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TMnn2UGZpEGMBSgFA+R7ZeE0qTIQJ9xMCvKxabWdl3GX60XEi8JslXdmWppGwzWy0YKL6bVNCCKiwjIlh/bKaMeavLj9vzgYnj+hO0jlIDTr2tyrul+g3H0+0bt5MOToxNTgLGpckrBHeXkbcshITa+wO2gzkvZ2/W/T977427HUP8O8wTtYW+oD4GtX03MUOV3ngl8LaZsaI9vZz1EE0uetJkM/0mow146VJLI6WeOCqMu+5m7I4UBhYjAb0wQQ3/iSKcZG4Tn/pzUazsafv4jscoWeiOVz5EaeNbrcTQwQb/cynlxXUB2nYhGcgjHNYafMrn82hA3PuynJ56Kt/thUBuuVnDZlMck6DRtLEHuGhG57tGBtUKD7P72zgcWtK3DqEnEqIk7NPokJzGVpEeh/KfCO8HShrR4r52wBNU9+XaE/cXf/suC36mpicbLBE50n1rnEzfz6pMRZsK21WQTLFPazkgT5n/gjibwkkxYRdaZDexwwbIAIi8eVnP6+tG6FCxJYE+Hp8KfS3ICp6xxW5bsGu7Qc/AJArD0qRyrHhtqcij9hzqyWyNqAgnwI 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)(39830400003)(366004)(376002)(396003)(346002)(136003)(230922051799003)(186009)(1800799012)(64100799003)(451199024)(2616005)(1076003)(478600001)(6506007)(6666004)(52116002)(6512007)(41300700001)(83380400001)(5660300002)(2906002)(4326008)(8676002)(8936002)(7416002)(6486002)(66946007)(316002)(66476007)(66556008)(38100700002)(86362001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /kb+AFq7Shdeot/IU9p+Hch3qin+YP1i3I8EbG+HDPp2fEC4HBqvwSqpPPQCulFsQcLY38c1eDzqD2z7XWR6hzkcITt+CmvshCoP7PkgHacBl4YNm2KoG4BlPQKBPVn3IARf7hC31bBOglc/DswB/4SY07i3Yjsa/sCm9BEvxEYcPT5HFzUN6/mYCGyP48LoHi+3DOgYKEyI+1J/owkP25oaIuYJ0J0U6YzLqoA8bJg91JOr6g2mEquE88EQ4KhldfqXwj0HHjj4XpJUQeUGopeyen52lk0WmE5t11Oyin9c2wAW2kxVuMhb0ZFLTbXMxe1ttnuDevdFORuHPrz742t5BH8HRR7hGY3CpGEqjtfiRum4eqcVzCFb6aShgiJhndwq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qxb1Y6osaAZu6xIDL7alCZu3tYiI8iTB3JOiy5cSYAVcWP/o59BoqOBmUZzCqVqhG+1Z+cpxMVwpIeAB72AG0GFElWWtfUpLKoIFlcQ22+g+huiHt7mUKdbbEf7QOl0C1sgirp3xs4cBGOqH8jGrFpCJDQTnQRov6I9tztQzTDv3yqtuJRZROip7TDP/BcRGc6rrcgvBdTIREp X-OriginatorOrg: kunbus.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3f929983-ff7a-4f98-d96f-08dbf8b6a7e9 X-MS-Exchange-CrossTenant-AuthSource: VI1P193MB0413.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2023 12:59:18.9258 (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: PZbWvp9aAfEst6+gLAp4bp7CQo0Iu/fWI+YPr/GECft0qxGPO+kyMdzvb4Jpo3ht9oA3swxB/F6ea3elCG+fqQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3P193MB0555 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: Shawn Guo Cc: Sascha Hauer 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 4eae1406cb6c..661074ab8edb 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1448,6 +1448,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; + uart_port_lock_irqsave(port, &flags); aux = port->rs485; uart_port_unlock_irqrestore(port, flags); @@ -1465,7 +1468,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)))