Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3882142rdb; Mon, 11 Dec 2023 02:54:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGO8kmi/e45Bb1u2LEHEYTClZPfVUywouYN63GxF1VHSrH4yqBSGsSgNK6QZ19Q1e1uC+6+ X-Received: by 2002:a05:6a20:5523:b0:190:89fa:6b80 with SMTP id ko35-20020a056a20552300b0019089fa6b80mr3844831pzb.55.1702292040449; Mon, 11 Dec 2023 02:54:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702292040; cv=none; d=google.com; s=arc-20160816; b=mNPMjEpGSka11D5wgvewx9fKEGP9qAHAeyH0pMpZGsSZqQ93Qy+fOL8ItZCD7jnX+O PgFg0btrVuvucRuOzjxxAYBh2RlVWYjadNF7B8PZpAWakHcQZ5OZUlWDHBehXi2Y8iqJ ydV1C6Q+TMCMfDU5pWJUaaETYNXK+ngDLLXIrfSE+rccXEzkmhCVf0i0SsKhyVNMV1y0 ChqnlvT3DonDDk/jVoyBB3RvhcgrZUDRfVjgp7x1zXF1YG4bnf326bESUaP1FuQA63c5 x0pPokESrcqGacq44ov4Y+C5Qmx/b8CXdSk9bLSQQLv8tAv4DXQOjuSvAvXy4AQOTAcL Eyrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=JracLtVnE8cBh7G/c+RlpVkTIAjvI3znFyZgafbitnc=; fh=mDo9AJ/yd0LvLDNxlF7M3XLvHnGX9YNrpHW+lPaHt54=; b=JEw7hr0MLcRBDssExucBw02NWjhf31+qkszPkLjmradL02NiDmXBaNr3ZyouZskQRD 5JaWw0826AIZcSsE2uYb87c8os6P4N2JO5yz1n5lZlTsEG8Rlg5Z0MSDp1Slic97ag9b BY5sECr8gY0kHsriM+kc+YjRcLXb3Z0f8ESUDjkuIx+Ayfwpm9YablAVeTccjfu2lTZO ktGrbz7CRIYKt7D28TfabuvycJ5jbIhSfd2Dg/O0SysjqToqClhY8+XgEmEwUCG6tDUh +syxl98hNFQrnlgil0vd69iopmC+wFpgmaQr6DF3Msu+qq4IwOh5bPv6U4ctXtHy4UTY gCdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GGGQk718; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id bf15-20020a656d0f000000b005c699b49da1si5970879pgb.873.2023.12.11.02.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 02:54:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GGGQk718; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id F32028093429; Mon, 11 Dec 2023 02:53:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231872AbjLKKxm (ORCPT + 99 others); Mon, 11 Dec 2023 05:53:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbjLKKxk (ORCPT ); Mon, 11 Dec 2023 05:53:40 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D434F9A; Mon, 11 Dec 2023 02:53:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702292027; x=1733828027; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=ouVr0xABC0VbnKadiPp9N3JbAXoUMby9A2Sjw5UigG0=; b=GGGQk718QXtJgbl1nZKyfuk7gr/3KCUTbALkrOlvBBjy5hNag4weqanX OgSfkKA5NBD/gis9oGyz8cw5EKjVd7ZCzx1OA2PnNN+U7r+5B7G1bbQNk MqhRtYl1Q2Hdn/DfG3yLCRNZNC6tC0mwb4MeeaMld3V5iUYanmvaCVJFz eATKyjU6FlF6/FciIttKSlwtne8Lq2uGR2/Mih8jejf9oJole7ihXerjl ppG3E4aiwhjLJrV7ElC0X6GLyUVpkPSoNONT4exZ28o4Kn9q+fKh3Oigv i+ce5ka2jBo/zRv78AEpNaWiswXJb6AWGdokocfmoNLfoX4TcMV1WBEZV A==; X-IronPort-AV: E=McAfee;i="6600,9927,10920"; a="1467599" X-IronPort-AV: E=Sophos;i="6.04,267,1695711600"; d="scan'208";a="1467599" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 02:53:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,267,1695711600"; d="scan'208";a="21035894" Received: from lmckeon-mobl.ger.corp.intel.com ([10.252.48.111]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 02:53:42 -0800 Date: Mon, 11 Dec 2023 12:53:39 +0200 (EET) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: Lino Sanfilippo cc: Greg Kroah-Hartman , Jiri Slaby , 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, LKML , linux-serial , LinoSanfilippo@gmx.de, Lukas Wunner , p.rosenberger@kunbus.com, stable@vger.kernel.org Subject: Re: [PATCH v5 4/7] serial: core: make sure RS485 cannot be enabled when it is not supported In-Reply-To: <20231209125836.16294-5-l.sanfilippo@kunbus.com> Message-ID: <5a1f1e87-38c8-7f0-35bf-689ceff844ba@linux.intel.com> References: <20231209125836.16294-1-l.sanfilippo@kunbus.com> <20231209125836.16294-5-l.sanfilippo@kunbus.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-1804116021-1702292026=:1867" X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 11 Dec 2023 02:53:58 -0800 (PST) This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1804116021-1702292026=:1867 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8BIT On Sat, 9 Dec 2023, Lino Sanfilippo wrote: > 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))) Looking through debian code search entries for TIOCGRS485, this might actually fly... I'd suggest splitting this into two patches though. Reviewed-by: Ilpo J?rvinen -- i. --8323329-1804116021-1702292026=:1867--