Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp287650iof; Mon, 6 Jun 2022 03:34:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIRk6qmtHYvt+oxTeHFAXg6pjDGyO3Od9QUjvHBBD8QlSlsTnezpcQuqzeXehAIQOhf/un X-Received: by 2002:a05:6a00:10cc:b0:506:e0:d6c3 with SMTP id d12-20020a056a0010cc00b0050600e0d6c3mr23827740pfu.33.1654511697643; Mon, 06 Jun 2022 03:34:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654511697; cv=none; d=google.com; s=arc-20160816; b=cbPGUXMPsT7gQ9Y6eMqmwDgPcF+H7aYSNtwDKoOLHJMm2BuMAilfcWONZTRlHdf6Z3 wRvYOlyE5uGWIWf759gDXrvEAfthkd0twISVmFwhH7kfgoyxpftOulPYhpgVp1OhDNHr QSX7fuNrmLjtiWqc4thanLkBnsFtu5m1zC/9dzoC1I52wAnfej5wDNE6mkAd5XrT3dgr Suavoz1wsfn/LmDugnFnYQyoyarjRYlNerP3D4Ek9IIIKw8sgzWSil6E76PdoJ4ZyFuo HUuTBzTZx8SnYcOjS90m3tbDgNUgk5dcgMHtiOf8c9sImztTuD/zaMW3Y5Dbmjwy4uHP ZTYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/MZ+rh4imNnod79lX65+5CqpBRk5HxfaQdCNDQni9jg=; b=bJva628JXQJcZEezh+Qft2z9/kf/Fcg5T1CuytqpPfXckI5vRzSUjDLBqnDG8uYFFt 8TG10/H5PVWBFuZ8MsShoyiAAG3MMpGRC1LFZ3noEyP0jBA0VDh3LeFm3JSl11B+KA0u 1hLrtSnPl1Z0N6DD3wje53SE+y52yaajkQInRel5yvjNCZN62S3cobJ5r8sTD2iCqNLo caVtC3vkQbbR3a10Y2HKKP2eJLvtifqL+7/eXINYjqKdGNqiAe+BQuyguhWVQJJOcLOq tutuFtlcWUkxkcHSVz7Ogpf9hO5xOUbKqyUVzFM10vYzjn7Swwa8urWkyuCxYLW8N4lt TW7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="AqkQC/tC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id bf20-20020a17090b0b1400b001e285f0889esi22727790pjb.35.2022.06.06.03.34.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 03:34:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="AqkQC/tC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9C67CFB433; Mon, 6 Jun 2022 03:13:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233695AbiFFKIs (ORCPT + 99 others); Mon, 6 Jun 2022 06:08:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233479AbiFFKGG (ORCPT ); Mon, 6 Jun 2022 06:06:06 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41F561207C1; Mon, 6 Jun 2022 03:06:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654509963; x=1686045963; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VcmEhh33jjTVe3ALqkigMTRIMktLH1f2shl4rAVdsNo=; b=AqkQC/tCmQaRPkmD8xPghrPUconYc5+bo4flPgoKUClgpcwaURf7ui9f AnP41louFP+sLyKdnxl53cy3ka69Ks7lRrO5g9khfWvlirQR4dMalAS3M /TAjnsxaY/D0odmZwFWUuDl1KlHE2F5FjOru+M6Dwhj1eKan83wjcTvl+ IlZO345kwectIf8mWJKxHorsSkFn3tb0h1wwHjdyCKrtsgU+EHq+wlM95 /YZNRrE+4SfE3JcRkcJ89/zOIcBfLL1/fT4Iaig/N8bLVOIHhrqJm5Xb+ YjEtgaWIZonReeBXMj/yBpIGS/YylueQy487rtzp1BCjk1jnWRjs4Zkvc A==; X-IronPort-AV: E=McAfee;i="6400,9594,10369"; a="362987076" X-IronPort-AV: E=Sophos;i="5.91,280,1647327600"; d="scan'208";a="362987076" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jun 2022 03:06:03 -0700 X-IronPort-AV: E=Sophos;i="5.91,280,1647327600"; d="scan'208";a="635523814" Received: from amkossek-mobl1.ger.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.252.57.11]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jun 2022 03:06:01 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-serial@vger.kernel.org, Greg KH , Jiri Slaby , linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH 24/36] serial: return -EINVAL for non-legacy RS485 flags Date: Mon, 6 Jun 2022 13:04:21 +0300 Message-Id: <20220606100433.13793-25-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220606100433.13793-1-ilpo.jarvinen@linux.intel.com> References: <20220606100433.13793-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to be add new flags more cleanly and safely, return -EINVAL from TIOCSRS485 ioctl for the flags bits which are not among the current legacy ones. This might cause a regression for userspace as those non-flag bits do not currently trigger -EINVAL. However, it would only occur if the userspace is sending garbage bits so perhaps we'll get away with this change. Signed-off-by: Ilpo Järvinen --- drivers/tty/serial/serial_core.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 6be538720564..621fc15e2e54 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1276,6 +1276,27 @@ static int uart_get_icount(struct tty_struct *tty, return 0; } +#define SER_RS485_LEGACY_FLAGS (SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | \ + SER_RS485_RTS_AFTER_SEND | SER_RS485_RX_DURING_TX | \ + SER_RS485_TERMINATE_BUS) + +static int uart_check_rs485_flags(struct uart_port *port, struct serial_rs485 *rs485) +{ + u32 flags = rs485->flags; + + /* Don't return -EINVAL for unsupported legacy flags */ + flags &= ~SER_RS485_LEGACY_FLAGS; + + /* + * For any bit outside of the legacy ones that is not supported by + * the driver, return -EINVAL. + */ + if (flags & ~port->rs485_supported->flags) + return -EINVAL; + + return 0; +} + static void uart_sanitize_serial_rs485(struct uart_port *port, struct serial_rs485 *rs485) { u32 supported_flags = port->rs485_supported->flags; @@ -1375,6 +1396,9 @@ static int uart_set_rs485_config(struct uart_port *port, if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user))) return -EFAULT; + ret = uart_check_rs485_flags(port, &rs485); + if (ret) + return ret; uart_sanitize_serial_rs485(port, &rs485); spin_lock_irqsave(&port->lock, flags); -- 2.30.2