From patchwork Fri Mar 26 02:07:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 410000 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F25BC433E1 for ; Fri, 26 Mar 2021 02:08:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5624761A42 for ; Fri, 26 Mar 2021 02:08:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230308AbhCZCHr (ORCPT ); Thu, 25 Mar 2021 22:07:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:50762 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230187AbhCZCHg (ORCPT ); Thu, 25 Mar 2021 22:07:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 318C961A46; Fri, 26 Mar 2021 02:07:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616724455; bh=xr4wdKqvt3LlM8CGlrjdWm5U5X39X5Dj2+0QKh5YAA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hE2+7B5CSnRFYqZaj7JkJf/CFqpemsZua9He1uDqcfHXN56JtEvnua0/AuCd68XrY cTH99V3rpZAumNiop8J0TvYF1KXZ3eEtGpEDGS57QMgeOAiGntAxCGJBK5r1Q3pJoD SAuHFmp8MRIUm+a2vnSX2CZKq5qWjgNaZ5rRyh2jxI0EnSXizZpHO+8tLNuwjdylfV T9Tgj30MZemqO5i4GFJCk89Gf/BeFFETPLcVgoj4LPgKRHnQMoAFoT83HA4RNq4BeP d1yePk+TC6JngmGts2jw22CBZNTuv1Wd51gHS2t1OBb8NKREaoS2ucWG3NYtZYAU3N tzlx5tIcxCNKA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, ecree.xilinx@gmail.com, michael.chan@broadcom.com, paul.greenwalt@intel.com, rajur@chelsio.com, jaroslawx.gawin@intel.com, vkochan@marvell.com, alobakin@pm.me, snelson@pensando.io, shayagr@amazon.com, ayal@nvidia.com, shenjian15@huawei.com, saeedm@nvidia.com, mkubecek@suse.cz, andrew@lunn.ch, roopa@nvidia.com, Jakub Kicinski Subject: [PATCH net-next v2 3/6] ethtool: fec: sanitize ethtool_fecparam->reserved Date: Thu, 25 Mar 2021 19:07:24 -0700 Message-Id: <20210326020727.246828-4-kuba@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210326020727.246828-1-kuba@kernel.org> References: <20210326020727.246828-1-kuba@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org struct ethtool_fecparam::reserved is never looked at by the core. Make sure it's actually 0. Unfortunately we can't return an error because old ethtool doesn't zero-initialize the structure for SET. On GET we can be more verbose, there are no in tree (ab)users. Fix up the kdoc on the structure. Remove the mention of FEC bypass. Seems like a niche thing to configure in the first place. v2: - also mention the zero-init-on-SET kerfuffle in kdoc Signed-off-by: Jakub Kicinski Reviewed-by: Andrew Lunn --- include/uapi/linux/ethtool.h | 6 +++++- net/ethtool/ioctl.c | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h index 36bf435d232c..39a7d285b32b 100644 --- a/include/uapi/linux/ethtool.h +++ b/include/uapi/linux/ethtool.h @@ -1376,15 +1376,19 @@ struct ethtool_per_queue_op { }; /** * struct ethtool_fecparam - Ethernet forward error correction(fec) parameters * @cmd: Command number = %ETHTOOL_GFECPARAM or %ETHTOOL_SFECPARAM * @active_fec: FEC mode which is active on the port * @fec: Bitmask of supported/configured FEC modes - * @rsvd: Reserved for future extensions. i.e FEC bypass feature. + * @reserved: Reserved for future extensions, ignore on GET, write 0 for SET. + * + * Note that @reserved was never validated on input and ethtool user space + * left it uninitialized when calling SET. Hence going forward it can only be + * used to return a value to userspace with GET. */ struct ethtool_fecparam { __u32 cmd; /* bitmask of FEC modes */ __u32 active_fec; __u32 fec; __u32 reserved; diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 0788cc3b3114..be3549023d89 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -2564,14 +2564,17 @@ static int ethtool_get_fecparam(struct net_device *dev, void __user *useraddr) if (!dev->ethtool_ops->get_fecparam) return -EOPNOTSUPP; rc = dev->ethtool_ops->get_fecparam(dev, &fecparam); if (rc) return rc; + if (WARN_ON_ONCE(fecparam.reserved)) + fecparam.reserved = 0; + if (copy_to_user(useraddr, &fecparam, sizeof(fecparam))) return -EFAULT; return 0; } static int ethtool_set_fecparam(struct net_device *dev, void __user *useraddr) { @@ -2579,14 +2582,16 @@ static int ethtool_set_fecparam(struct net_device *dev, void __user *useraddr) if (!dev->ethtool_ops->set_fecparam) return -EOPNOTSUPP; if (copy_from_user(&fecparam, useraddr, sizeof(fecparam))) return -EFAULT; + fecparam.reserved = 0; + return dev->ethtool_ops->set_fecparam(dev, &fecparam); } /* The main entry point in this file. Called from net/core/dev_ioctl.c */ int dev_ethtool(struct net *net, struct ifreq *ifr) {