Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next] ethtool: tsconfig: reject zero-valued tx_type and rx_filter bitsets
@ 2026-08-12 16:22 Jakub Kicinski
  2026-08-12 16:27 ` Andrew Lunn
  2026-08-12 18:37 ` Joe Damato
  0 siblings, 2 replies; 3+ messages in thread
From: Jakub Kicinski @ 2026-08-12 16:22 UTC (permalink / raw)
  To: davem
  Cc: netdev, edumazet, pabeni, andrew+netdev, horms, Jakub Kicinski,
	andrew, vadim.fedorenko

The ffs()/fls() guard in ethnl_set_tsconfig() was meant to enforce
that the user selects exactly one tx_type (and one rx_filter)
at a time (off / none are explicit types with non-zero values).
However, both ffs(0) and fls(0) return 0, so the guard passes
a zero-valued bitset through.

The subsequent ffs(req_tx_type) - 1 would produce -1, if user selected
no bit. net_hwtstamp_validate() catches the invalid -1 downstream,
but returns a generic error (-ERANGE) without telling the user
what went wrong. Return -EINVAL + extack instead.

Replace the ffs()/fls() comparison with a hweight32() == 1 check.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: andrew@lunn.ch
CC: vadim.fedorenko@linux.dev
---
 net/ethtool/tsconfig.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/ethtool/tsconfig.c b/net/ethtool/tsconfig.c
index 24b64862011f..6be3aa5d4bc1 100644
--- a/net/ethtool/tsconfig.c
+++ b/net/ethtool/tsconfig.c
@@ -359,8 +359,10 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base,
 		if (ret < 0)
 			goto err_free_hwprov;
 
-		/* Select only one tx type at a time */
-		if (ffs(req_tx_type) != fls(req_tx_type)) {
+		/* Select exactly one tx type at a time */
+		if (hweight32(req_tx_type) != 1) {
+			NL_SET_BAD_ATTR(info->extack,
+					tb[ETHTOOL_A_TSCONFIG_TX_TYPES]);
 			ret = -EINVAL;
 			goto err_free_hwprov;
 		}
@@ -380,8 +382,10 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base,
 		if (ret < 0)
 			goto err_free_hwprov;
 
-		/* Select only one rx filter at a time */
-		if (ffs(req_rx_filter) != fls(req_rx_filter)) {
+		/* Select exactly one rx filter at a time */
+		if (hweight32(req_rx_filter) != 1) {
+			NL_SET_BAD_ATTR(info->extack,
+					tb[ETHTOOL_A_TSCONFIG_RX_FILTERS]);
 			ret = -EINVAL;
 			goto err_free_hwprov;
 		}
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] ethtool: tsconfig: reject zero-valued tx_type and rx_filter bitsets
  2026-08-12 16:22 [PATCH net-next] ethtool: tsconfig: reject zero-valued tx_type and rx_filter bitsets Jakub Kicinski
@ 2026-08-12 16:27 ` Andrew Lunn
  2026-08-12 18:37 ` Joe Damato
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2026-08-12 16:27 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms,
	vadim.fedorenko

On Wed, Aug 12, 2026 at 09:22:30AM -0700, Jakub Kicinski wrote:
> The ffs()/fls() guard in ethnl_set_tsconfig() was meant to enforce
> that the user selects exactly one tx_type (and one rx_filter)
> at a time (off / none are explicit types with non-zero values).
> However, both ffs(0) and fls(0) return 0, so the guard passes
> a zero-valued bitset through.
> 
> The subsequent ffs(req_tx_type) - 1 would produce -1, if user selected
> no bit. net_hwtstamp_validate() catches the invalid -1 downstream,
> but returns a generic error (-ERANGE) without telling the user
> what went wrong. Return -EINVAL + extack instead.
> 
> Replace the ffs()/fls() comparison with a hweight32() == 1 check.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] ethtool: tsconfig: reject zero-valued tx_type and rx_filter bitsets
  2026-08-12 16:22 [PATCH net-next] ethtool: tsconfig: reject zero-valued tx_type and rx_filter bitsets Jakub Kicinski
  2026-08-12 16:27 ` Andrew Lunn
@ 2026-08-12 18:37 ` Joe Damato
  1 sibling, 0 replies; 3+ messages in thread
From: Joe Damato @ 2026-08-12 18:37 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, andrew,
	vadim.fedorenko

On Wed, Aug 12, 2026 at 09:22:30AM -0700, Jakub Kicinski wrote:
> The ffs()/fls() guard in ethnl_set_tsconfig() was meant to enforce
> that the user selects exactly one tx_type (and one rx_filter)
> at a time (off / none are explicit types with non-zero values).
> However, both ffs(0) and fls(0) return 0, so the guard passes
> a zero-valued bitset through.
> 
> The subsequent ffs(req_tx_type) - 1 would produce -1, if user selected
> no bit. net_hwtstamp_validate() catches the invalid -1 downstream,
> but returns a generic error (-ERANGE) without telling the user
> what went wrong. Return -EINVAL + extack instead.
> 
> Replace the ffs()/fls() comparison with a hweight32() == 1 check.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> CC: andrew@lunn.ch
> CC: vadim.fedorenko@linux.dev
> ---
>  net/ethtool/tsconfig.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)

Reviewed-by: Joe Damato <joe@dama.to>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-12 18:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-12 16:22 [PATCH net-next] ethtool: tsconfig: reject zero-valued tx_type and rx_filter bitsets Jakub Kicinski
2026-08-12 16:27 ` Andrew Lunn
2026-08-12 18:37 ` Joe Damato

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox