netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, ecree.xilinx@gmail.com,
	michael.chan@broadcom.com, damian.dybek@intel.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 <kuba@kernel.org>
Subject: [PATCH net-next 3/6] ethtool: fec: sanitize ethtool_fecparam->reserved
Date: Wed, 24 Mar 2021 18:11:57 -0700	[thread overview]
Message-ID: <20210325011200.145818-4-kuba@kernel.org> (raw)
In-Reply-To: <20210325011200.145818-1-kuba@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.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 include/uapi/linux/ethtool.h | 2 +-
 net/ethtool/ioctl.c          | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h
index 36bf435d232c..9e2682a67460 100644
--- a/include/uapi/linux/ethtool.h
+++ b/include/uapi/linux/ethtool.h
@@ -1376,15 +1376,15 @@ 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.
  */
 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)
 {
-- 
2.30.2


  parent reply	other threads:[~2021-03-25  1:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-25  1:11 [PATCH net-next 0/6] ethtool: clarify the ethtool FEC interface Jakub Kicinski
2021-03-25  1:11 ` [PATCH net-next 1/6] ethtool: fec: fix typo in kdoc Jakub Kicinski
2021-03-25 12:06   ` Andrew Lunn
2021-03-25  1:11 ` [PATCH net-next 2/6] ethtool: fec: remove long structure description Jakub Kicinski
2021-03-25 12:07   ` Andrew Lunn
2021-03-25  1:11 ` Jakub Kicinski [this message]
2021-03-25 12:22   ` [PATCH net-next 3/6] ethtool: fec: sanitize ethtool_fecparam->reserved Andrew Lunn
2021-03-25 16:02     ` Jakub Kicinski
2021-03-25  1:11 ` [PATCH net-next 4/6] ethtool: fec: sanitize ethtool_fecparam->active_fec Jakub Kicinski
2021-03-25 12:25   ` Andrew Lunn
2021-03-25  1:11 ` [PATCH net-next 5/6] ethtool: fec: sanitize ethtool_fecparam->fec Jakub Kicinski
2021-03-25 12:00   ` Dan Carpenter
2021-03-25 16:03     ` Jakub Kicinski
2021-03-25  1:12 ` [PATCH net-next 6/6] ethtool: clarify the ethtool FEC interface Jakub Kicinski
2021-03-29 11:56   ` Edward Cree
2021-03-29 12:32     ` Andrew Lunn
2021-03-29 17:39     ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210325011200.145818-4-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=alobakin@pm.me \
    --cc=andrew@lunn.ch \
    --cc=ayal@nvidia.com \
    --cc=damian.dybek@intel.com \
    --cc=davem@davemloft.net \
    --cc=ecree.xilinx@gmail.com \
    --cc=jaroslawx.gawin@intel.com \
    --cc=michael.chan@broadcom.com \
    --cc=mkubecek@suse.cz \
    --cc=netdev@vger.kernel.org \
    --cc=paul.greenwalt@intel.com \
    --cc=rajur@chelsio.com \
    --cc=roopa@nvidia.com \
    --cc=saeedm@nvidia.com \
    --cc=shayagr@amazon.com \
    --cc=shenjian15@huawei.com \
    --cc=snelson@pensando.io \
    --cc=vkochan@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).