From patchwork Mon Dec 25 11:35:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 758365 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2052.outbound.protection.outlook.com [40.107.7.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DED1F51C27; Mon, 25 Dec 2023 11:36:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=kunbus.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kunbus.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=kunbus.com header.i=@kunbus.com header.b="w1ji+nWt" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uhgamo/qxh7U4Z+LczJ/SqVEWiWKp9PVxnvh7Bc8QErvHM/KD8X3PvpisX5PMntWfhiP1sG9yrEDnC3IHPc5Q7HgxywAeiY5Wwd3LFv6uuSf9ATLeVkKEg2cAawW6GasbB/ibJlOrHUJLwaUZE8NqxW+XCYFg6XiXwPqgvg7aAlE/9tNS5m5uhkLj/RZqOY++WSTlfV01DNTYjt/sA5IHzJj4d4iEk/1yDN1XMuRTwparwXmzQG37Hb1qv5juE1gnRSAskXvjxK37zWcjhRT6Zyvk5x+M9cmiGuaEaiFRjQ/D9s/KiHUsFUUhBZPp+hzxs1q8f3GOlQT0KEXtcpNVg== 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=ctoSUvaSE63QhX1RJ/Y+ZsAabtaxgzq3AnK1Gc9jmAU=; b=YEMr8QeaKZGTm8HbQlXVpdmzDBiXpH17KgOg5cBBGk0rBC6pEoBo0kSY8d8Gt0id4+MQvWMQiAE9qTK3Zq7EDB3MijfRSEfXIByCxZUfXwvy/ti4cK382w4iFdv2hPkHRa6FNtF/jcdhIBZQi7u9l7BkTcdofTI388g6HSktP3R3+xHUBEU/ym1JB2Iz/dKMl2ksupEFHTK4BzqQSvpqhSmO9bPIoPcadjUBWN90bZn4kwkjvXOiZLLbZmbjZtz7Y70D4k8QX6V38pjfAQKerPVgL4bsA/75302NW6KlQ/55oxsL7283ozp4+fdIjPV2BF3K8xiITm/+o5BOWLBcsA== 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=ctoSUvaSE63QhX1RJ/Y+ZsAabtaxgzq3AnK1Gc9jmAU=; b=w1ji+nWtf5OJqGPjcOFRHCeTrVoPQ3mBx+y4OXM7oA0O5Ufk82I4g3cXqBuRACBN7DVPcUqjsRZ6pZrfDIobGGhksKh95DMDw7x3q1BXmRmK+3mKTS0MBxem6ULkoZ5dn9lct5YIXXDeb5ucQpIOx8SB04yKqgaQRvy0Qy3P5CM= 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 AS8P193MB2061.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:44d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.26; Mon, 25 Dec 2023 11:35:55 +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.7113.026; Mon, 25 Dec 2023 11:35:55 +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 v6 4/7] serial: core: make sure RS485 cannot be enabled when it is not supported Date: Mon, 25 Dec 2023 12:35:20 +0100 Message-ID: <20231225113524.8800-5-l.sanfilippo@kunbus.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231225113524.8800-1-l.sanfilippo@kunbus.com> References: <20231225113524.8800-1-l.sanfilippo@kunbus.com> X-ClientProxiedBy: FR5P281CA0055.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f0::17) 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_|AS8P193MB2061:EE_ X-MS-Office365-Filtering-Correlation-Id: 25892f0c-64d6-4563-bcbf-08dc053da757 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dYRxqpEKapPguGhfz1jXmu2nZjVbz12ASsRhsva6mrhAblV5eZuvhRaB2wZ2B5sipOUJh0czw0Do8NVfAKDpJu71fB2qrJkjb7ypxUtcyMARfL2Vo7q0NFFifIhMmFEcTKqM+3uva2x8mDJjQNJuhh43zch4mj25s9VYZRYfUBIm5Kyb3wnJ6tuU31xXg89gaFX8K0/E8LUatxU/U6QfUMvew6is7hSw9SQH15coGbdpiAPKmsms+p5fxq3Vd8x3A3OIcfZpKLOok45NrNGmMdSNvjwAHJNAektupX9sx7l6B7yUfTG9DApfUEwUhVnkCtYC67DDTDfb3z+SwAjFwY2i4gvWGu4SoOhD1Z7Q8G2tkOMBgQMidrK/RFLnUBH0qUozGmRTvdsBS8M5CpHbzP5GrxtzInQW5fp8W80hgqd16uGew4i3R2EDdhKNinvG5U5MZTHzdmV+zBdz6yn9X5t7kCcWucpF5CVpHqySDF1s3ptQ7FfhsYU2RKsbwEFSnvhP+gvEqm1TD7bAHGV6/Qsg55k/btrfuZJ6ksr4NEeShvbCMjEyFYNlWSPR1WCv 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)(396003)(39830400003)(366004)(346002)(136003)(376002)(230922051799003)(186009)(451199024)(1800799012)(64100799003)(2616005)(6666004)(6486002)(478600001)(2906002)(8676002)(8936002)(5660300002)(36756003)(7416002)(52116002)(6512007)(6506007)(66556008)(66476007)(4326008)(66946007)(316002)(66574015)(83380400001)(86362001)(1076003)(41300700001)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Nq+lTjuMrl/0ERPmSiQXDa+o6JjX?= =?utf-8?q?Z63EQswZkM8YtWJBmu/wSxw+Te4C0pHHyFbyqHYcPtIQrEOi73fvWHdAWsVNTtrAF?= =?utf-8?q?1P2eSkqBiYFf5+qv3V+m53AVdCM4Kvv0GLBKy8xfpwPvciC/8oJ8KUos0567P+mx+?= =?utf-8?q?N+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y0jnD0isXXQYrM+Glxk0XVKpBOrboD+hG+0k4BQ2OwAQgT3x+9dztj00lxdnUd3YD?= =?utf-8?q?f46ghQPNFrv1LK6xn69U81dIKVtZ8Rv2y2L985CO4lJa7tDXvV6+DbxpsdJeitBmH?= =?utf-8?q?XY2Y6KW/VXIMe8GL4V4csE7+OAiwi21Tn4HFzrcTFik01vV2DZlRd+6qVP3n/f1NG?= =?utf-8?q?eVpITPEaoet45nmCYCw8TVd8nmIelfJk4QIttJVVZoO+BBqd3FMXSGdZDvEuf2YUZ?= =?utf-8?q?1GaWWAUXyWrTJqpGKNIz+7h5HJaNIXHD3aGQ2HKjZ7vwZvdrxlvF6GjgLw5QfYWTb?= =?utf-8?q?nAOEMEUfAwV40zzoqr5X1Q8qZwT7xE+WCGHGYMSxCgBORH3grh0QDuEveIgSOr4c9?= =?utf-8?q?Wl7xoKFldxaSfGwBhYm38FWVf6rhjpvoE/grE9zEwdlnnqV/aQkqtffTUAmjaqT3o?= =?utf-8?q?RPTOR7xcGvr2wOvLVZ3mvrLQ+JEGVrRJl1ukxnyHw58J0WsGPVkDI4hLD3b9fdfUt?= =?utf-8?q?s3KBAPK5rj46I5J6NiU+0KcSuFHk7QKKE4kI03OvZtKj+vKJV/rLGJo0U2ipXlg+/?= =?utf-8?q?7RWbr7ZU2Fr?= X-OriginatorOrg: kunbus.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25892f0c-64d6-4563-bcbf-08dc053da757 X-MS-Exchange-CrossTenant-AuthSource: VI1P193MB0413.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Dec 2023 11:35:53.9842 (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: 1QLWCILvtFq2cYHxzCXWSN4NIZeG86c6fn5TluajrhQJs1/vGnmwQoKr3rcknazHD830QXfUkLxApUYuw2KwlQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8P193MB2061 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 Reviewed-by: Ilpo Järvinen Signed-off-by: Lino Sanfilippo --- drivers/tty/serial/serial_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index f67fb6a04983..28bcbc686c67 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1469,7 +1469,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)))