From patchwork Sun Nov 19 11:28:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 745337 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 CE210C5ACB3 for ; Sun, 19 Nov 2023 11:33:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231926AbjKSLd0 (ORCPT ); Sun, 19 Nov 2023 06:33:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232100AbjKSLdM (ORCPT ); Sun, 19 Nov 2023 06:33:12 -0500 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2064.outbound.protection.outlook.com [40.107.104.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B91C619AA; Sun, 19 Nov 2023 03:30:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UNMcTDzvC3EETKyZMKdcgGIZRj+ruNlMyjouDE7yQcoLtfGa7SyvVLKmJBJGk9CEyVQiIlNALsGGBp4hL2dzrKFWAmkXRQ+0FnHImr+S5zUKEegRCSPpLzzXtVCetxULZuzyBYgrHpNl2m8nMGDZCaRjIfHkw7WqSxMwxr/VsePDRRnZGimnpUP22SubtohyS1zyl2c2iOhbJgoyNoNkRR09oND695nC5ehWkFCxH9CNuyN+b8TqAP/bz6bL7bTkJ5iAip2FfiBk5iZDZBIkUDzcKtsd9po2ibaUKqGUJhyN6dklisJVAxGcPL4bZKRjvJZ8iEqD0dJ9opU+nVeb0Q== 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=ebPnrpWvtNskQGU9VdxDDVTFT0EpFdJL+SfMBJwjsmI=; b=mlUgOkPlx9k06qQDPmwjgFhyAZN5mebBrFeoHOquEvl2IhS/jfuXX2Fat1wySwJrtfr7oW5m7zZikCTYjAV7SS7vZ47umfF8aqoVSaG0myUteAHTr9DHRzvY7TWS+gZBgU+GkJ+oeAvtJV8Sbu7RdKpuh0TR4fmVj1ZDZzUowSjA9JPAP+11MjKhru7O8fJ1YJv2wbxY4TLlizDmy2rRAS/EmMM0fTN4NPR3o3s16BSfcyAzxdvZtRq4ew8VtGDWYFzBK/Sz2zkzIo1PUBhILc+P4Ou2bpApU7tP+khBwocMHRoF8IqkKUjc9Ge19bnYF5GK+2Ih2/vuIlPTXj2n5A== 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=ebPnrpWvtNskQGU9VdxDDVTFT0EpFdJL+SfMBJwjsmI=; b=Z16GkgyaNMbGMuK/n02nZUR5hq1G67JIydjsTmfCIDsIu2rbCXrDdaqUDe8zLYzhcLMcj/9HfQblSvyA1u2/B8Iwt0K7Brg00KyWBYO4zs9ZfSQzP2CiDy0sAgqZJaplVxgYZ5D0Y6HBoxtL3ILiPzRpBMw6jtWlsDo059MBtV0= 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 AM8P193MB1060.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:1e5::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.26; Sun, 19 Nov 2023 11:30:01 +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.7002.025; Sun, 19 Nov 2023 11:30:01 +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, 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: [RESEND PATCH v4 4/7] serial: core: make sure RS485 cannot be enabled when it is not supported Date: Sun, 19 Nov 2023 12:28:52 +0100 Message-ID: <20231119112856.11587-5-l.sanfilippo@kunbus.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119112856.11587-1-l.sanfilippo@kunbus.com> References: <20231119112856.11587-1-l.sanfilippo@kunbus.com> X-ClientProxiedBy: FR5P281CA0007.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f2::17) To VI1P193MB0413.EURP193.PROD.OUTLOOK.COM (2603:10a6:803:4e::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1P193MB0413:EE_|AM8P193MB1060:EE_ X-MS-Office365-Filtering-Correlation-Id: e20746de-aae3-4516-5588-08dbe8f2de2d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jk/opv8mj/wscxDT/+tbinvNKNDSd7wnsNI+s8owrocjfKDfkWwpPihK3FJftWlY3fGUBTfa5spXA0yGm8lne4vDjnC53Lg3CVNSCL9YrId9gcM6Cwqc62A1LhEY98pzF8jbYTl62lgbUjE+ySmjTtnR9QSlVtVff2Rhqw7Z5CspNEfnwHhudAmS0ksN3rRyBk9WhPKJcloAsbSl4ofj5K3TpBR35Q7IwDGr2UrBXWPdZOqja7vgSvl78Gg7mJzThIgbEAmk40MFMxWooZBxnYAu61flz24AKqNCIwzdbCcq9EfvWpUyeUYIgQCZmxKZu7LC8G69DcEmpdcykQzfpOdnK6tVaaLR4Scc9ArstnjBOGbKpLBFt6kbrFfJUdzzRpGcDWEqPdDTrdkDkPfZaNGM7VUYd1gXPG1eDIUapH1hPzHpT/FDVDP5DSTe9pDzeYZOWouwlfErvc6MQYMsKYjf01ttmy1b+KUyFLLq7DfccGaG6eeOunqFTTnEGsi3Zpo1AmvtFrL0VK10LeVEUA4oERhW3l9e93HP9lqZYqdaQn8/XFfzC2HklKbotKba 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)(346002)(136003)(396003)(366004)(39830400003)(376002)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(6506007)(6512007)(52116002)(66946007)(66556008)(316002)(4326008)(8676002)(8936002)(66476007)(6486002)(478600001)(83380400001)(1076003)(2616005)(38100700002)(6666004)(5660300002)(7416002)(2906002)(86362001)(41300700001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: b6VbNiO0AfcJxUwn7ShxXTbW9IOAOHZp/rIMQ0ySsx6HnEEHwYQjgk0rnu1+RmN0f0g5a2pCbnSGiRmxAPKuY2KuU7LMRETHaqVchKuHoypijpT78OTfC/fRR6XO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pE04eXmwteX43kYCSPHdJ9R+q09AhF2I3cc6O27Vm+YOzw/SA9V2Oj7XrvR8H8M1PJb5B++iAJ9XpL6/fIdrGElxX0yXhr21EcOZcvaqFXIKZC2eSJWmunkd5TuEKqPoJ0jNwHkT6VJSvVp4H//obn7EC23NruIx0JOXwdafVoMP3yZjyYaFdvwH7obgZdf2dOwgcqyBKleoMMezLykDzs/6Qa+1ctSl8G+CcuERiweySk4B2X4U2A/koLR2ezzcJhdWNoz5LccH1rxal6+0aBc5KvwyRcwyE83s5u73Ds/nJROJHk969/Azuczuuid3E98Pc6BEbDCOne9Ymtco8iCyn6L9sotCNFH90yabw1DD1YZHo1tmgM3hJCjYwls9lNigruHet39kZ6RfUafKk+vOK9FE2tjm49poNvgh2DTWikICloWRgLrwtpx+qS1G/VQDSzQg+sCszw X-OriginatorOrg: kunbus.com X-MS-Exchange-CrossTenant-Network-Message-Id: e20746de-aae3-4516-5588-08dbe8f2de2d X-MS-Exchange-CrossTenant-AuthSource: VI1P193MB0413.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2023 11:30:01.1375 (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: ia8XkdAfzXIMiWZSRr1ER5Fvfnvcf4jGuJleTvzYVN0/BEUDe7KtWZtikC/fsiYGeEHPgA8HP9ZgvuxD6lVL6g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8P193MB1060 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: 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 b96fc2ba8596..b636e2ce6e8b 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1444,6 +1444,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); @@ -1461,7 +1464,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)))