diff mbox series

[net-next,1/7] net: ethtool: prevent flow steering to RSS contexts which don't exist

Message ID 20250206235334.1425329-2-kuba@kernel.org (mailing list archive)
State Accepted
Commit de7f7582dff292832fbdeaeff34e6b2ee6f9f95f
Delegated to: Netdev Maintainers
Headers show
Series eth: fbnic: support RSS contexts and ntuple filters | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: andrew@lunn.ch
netdev/build_clang success Errors and warnings before: 2 this patch: 2
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-07--21-00 (tests: 890)

Commit Message

Jakub Kicinski Feb. 6, 2025, 11:53 p.m. UTC
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.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: ecree.xilinx@gmail.com
CC: gal@nvidia.com
---
 net/ethtool/ioctl.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Joe Damato Feb. 7, 2025, 7:27 p.m. UTC | #1
On Thu, Feb 06, 2025 at 03:53:28PM -0800, Jakub Kicinski wrote:
> 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.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> CC: ecree.xilinx@gmail.com
> CC: gal@nvidia.com
> ---
>  net/ethtool/ioctl.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)

Reviewed-by: Joe Damato <jdamato@fastly.com>
Gal Pressman Feb. 9, 2025, 8:17 a.m. UTC | #2
On 07/02/2025 1:53, Jakub Kicinski wrote:
> Since commit 42dc431f5d0e ("ethtool: rss: prevent rss ctx deletion
> when in use") we prevent removal of RSS contexts pointed to by

Nit: I would try to avoid the line break in the middle of the cited commit.

> existing flow rules. Core should also prevent creation of rules
> which point to RSS context which don't exist in the first place.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> CC: ecree.xilinx@gmail.com
> CC: gal@nvidia.com
> ---
>  net/ethtool/ioctl.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
> index 7609ce2b2c5e..98b7dcea207a 100644
> --- a/net/ethtool/ioctl.c
> +++ b/net/ethtool/ioctl.c
> @@ -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 */

This comment should be moved inside the if statement.

> -	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))

Accessing rss_ctx without rss_lock?

> +			return -EINVAL;
> +	}
>  
>  	if (cmd == ETHTOOL_SRXFH && ops->get_rxfh) {
>  		struct ethtool_rxfh_param rxfh = {};
Jakub Kicinski Feb. 12, 2025, 6:39 p.m. UTC | #3
On Sun, 9 Feb 2025 10:17:30 +0200 Gal Pressman wrote:
> >  	/* Nonzero ring with RSS only makes sense if NIC adds them together */  
> 
> This comment should be moved inside the if statement.

Will follow up, sorry.

> > -	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))  
> 
> Accessing rss_ctx without rss_lock?

Yes, same as ethtool_get_max_rxnfc_channel(). Since we'd have to drop
the lock instantly after the check the whole rule addition wouldn't 
be atomic under that lock, anyway. IOW the xa_load() access is safe
in itself, and I couldn't think of practical use for taking the rss
lock.
diff mbox series

Patch

diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 7609ce2b2c5e..98b7dcea207a 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -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 = {};