net: ethtool: prevent flow steering to RSS contexts which don't exist
authorJakub Kicinski <kuba@kernel.org>
Thu, 6 Feb 2025 23:53:28 +0000 (15:53 -0800)
committerJakub Kicinski <kuba@kernel.org>
Mon, 10 Feb 2025 16:26:50 +0000 (08:26 -0800)
Since commit 42dc431f5d0e ("ethtool: rss: prevent rss ctx deletion
when in use") we prevent removal of RSS contexts pointed to by
existing flow rules. Core should also prevent creation of rules
which point to RSS context which don't exist in the first place.

Reviewed-by: Joe Damato <jdamato@fastly.com>
Link: https://patch.msgid.link/20250206235334.1425329-2-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ethtool/ioctl.c

index 7609ce2b2c5e2ead90aceab08b6610955914340b..98b7dcea207a64d96192bf8e7008a23b53465ba7 100644 (file)
@@ -993,10 +993,14 @@ static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
                return rc;
 
        /* Nonzero ring with RSS only makes sense if NIC adds them together */
-       if (cmd == ETHTOOL_SRXCLSRLINS && info.fs.flow_type & FLOW_RSS &&
-           !ops->cap_rss_rxnfc_adds &&
-           ethtool_get_flow_spec_ring(info.fs.ring_cookie))
-               return -EINVAL;
+       if (cmd == ETHTOOL_SRXCLSRLINS && info.fs.flow_type & FLOW_RSS) {
+               if (!ops->cap_rss_rxnfc_adds &&
+                   ethtool_get_flow_spec_ring(info.fs.ring_cookie))
+                       return -EINVAL;
+
+               if (!xa_load(&dev->ethtool->rss_ctx, info.rss_context))
+                       return -EINVAL;
+       }
 
        if (cmd == ETHTOOL_SRXFH && ops->get_rxfh) {
                struct ethtool_rxfh_param rxfh = {};