From patchwork Thu Sep 28 22:12:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 727554 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 604DEE743CD for ; Thu, 28 Sep 2023 22:13:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232525AbjI1WN7 (ORCPT ); Thu, 28 Sep 2023 18:13:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232570AbjI1WNx (ORCPT ); Thu, 28 Sep 2023 18:13:53 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53DA91A3; Thu, 28 Sep 2023 15:13:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695939214; x=1696544014; i=linosanfilippo@gmx.de; bh=hg8w75pV0e3pjbzQLJFWM+TM+iujlrT3Ta4nBCXoDzs=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=im686yKF1Pr+8T9GT14YLKy2cCDauXeY+iT4ymje2THJJk7u9j7Uge8hyl3oEPMXJcAauQXmX91 AFDdVBb+GoRvcxTu/8Z+/sZWdYpJAuDUDLs8l3ZvEraTB25HeE+c2zKZpF16a+M8o002ZDwgXpKF7 nD3wPOHaLK+Y77jsEUGDMtf1hyrplNC9fCPi5ZmogKhgyzM+OG8C+CvHJjqWRd4EwiPuFDsmYp5Pv an0H6Og+HttTsjmC2b5ZvdzO5ffeXi3N5gRW7bTNwoo307Yvze2UNCOeFZDOPialnUFOSH0v8ZtV4 dgX33wM8Hq/ad5/AQUZ3Th2972O37BdVsZqA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from Venus.speedport.ip ([84.162.21.41]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mi2Jn-1rGM8d0T8j-00e39X; Fri, 29 Sep 2023 00:13:34 +0200 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: shawnguo@kernel.org, s.hauer@pengutronix.de, ilpo.jarvinen@linux.intel.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com, stable@vger.kernel.org Subject: [PATCH 5/6] serial: core: make sure RS485 is cannot be enabled when it is not supported Date: Fri, 29 Sep 2023 00:12:45 +0200 Message-Id: <20230928221246.13689-6-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230928221246.13689-1-LinoSanfilippo@gmx.de> References: <20230928221246.13689-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Od3l4xl/uII61q4WCOzbzrdpV4WzfRrpfpwW+63udSex6TYzbGi Yxm3kzO8B0/p69CY6IbF6VIwdpcOC33Yh2uLfiUs2hUzzB+NvbzOW9K2YruY4zacovT56Qp wL/RFiJJTxVqsTJyhS/Yoo3m+FZdjOkPZDyRzr8yEqSw7cWa5e5YcWFsyzcAe3qXgQ3pum4 pHQH9QaYtUL+pSUgFKF2Q== UI-OutboundReport: notjunk:1;M01:P0:RERU25vI7eg=;t4JI+TeEd/T7kk73bmESiZA6A3d e+nOfxVI8YqeYeQsHbIdBiVKShltFe6hCz0O3OHfJUgXga3s/L/1+YxP2bLkHWLgUmG/OT1mS 85HokF0MpWKcS1GPpiR5M9N/RwrKRtcWomL73hBQrIldlsLPCqH1hVpi7EI4Ty2kvzszI4frv RMic0di7sMBEKE/eZCC253W2uYY2438RJUUt5LOC13TqXEWWiuJdNEIvfC/HklzfBnQjuBokM a2nhL8W1DWZWAy/dPzKx7gHIP1XoT5ErCk6Ko+MgNRPiOqHHVrlKAapbTM2iAMO5HmeBHnEQx /jVqJfUan0e9tCw6ZYyfU67qrJu02q8E8x7D2JlwT7IB9h8dN6F7aRamWD8VWgD/0zjTa0LUG Bjs3XcSdH8btnkAkkrzZuVW7vGQH0AiN/QPkATOhmC8jNwX0NDxqgME0wN4v+NX38w4nrTg87 oyuwiZxDz1Cm0OlTRN1yfChU2qhpZ1H3BPtbQa4N64U/VXO6KHuDqExNpc+3Yig2pW9VZVN6c 7YCHKmPLq1Ptitz8p4S+4S2zY8IR0MAGcwB4uXG6PqIP9i3fFaxF7PqRdGSQuZrV/WRH/wNeZ zkhChi6kImrBx1ca/O1Sr4k2dUQpS0cLinZELGozGoG84xw+RpGncvtNhA5nqlIAl6YFu6kdY FUhi4JyEUY8GP79ZBl5xoD32lMEu8xrxvYfAHPgZ37dR06CT5nDCiciui79BEatfS4dL2gmdS m5X/UEkJzAbJiqumPWeHL4IHArpH6xpU3PsFUAyWo+LvmfLGU5WYj6MH0PNEGTI75OR01Gmel ncbbCyKwiEUjJsXhjAmpX/H589Sh6U3p8ucbCmxNT3yvVKmPH5jTCbVZ2kPmQP9Q0Gd6aKlV+ cC7Og39gUqsA3fr810DFj5a0P/vahgn67Q1dsAS3amoamgoi+/mQI3V66s+Qk0IC6m2Y6hUTg oxM+XA== Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Lino Sanfilippo 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. 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)))