ethtool: tsconfig: reject zero-valued tx_type and rx_filter bitsets
Subsystems (3)
Jakub Kicinski
maintainerPATCH 1/1 ethtool: tsconfig: reject zero-valued tx_type and rx_filter bitsets
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.
---
CC: [email protected]
CC: [email protected]
--- net/ethtool/tsconfig.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
net/ethtool/tsconfig.c +8 -4
@@ -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; }
Signature · 1 line
2.55.0
Quoted 6 lines · Jakub Kicinski
The ffs()/fls() guard in
ethnl_set_tsconfig()was meant to enforce that the user selects exactly onetx_type(and onerx_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.
Quoted 8 lines
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 <[email protected]>
Andrew
Quoted 13 lines · Jakub Kicinski
The ffs()/fls() guard in
ethnl_set_tsconfig()was meant to enforce that the user selects exactly onetx_type(and onerx_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.
Quoted 7 lines
Signed-off-by Jakub Kicinski <[email protected]>---
CC: [email protected]
CC: [email protected]--- net/ethtool/tsconfig.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
Quoted 41 lines · Jakub Kicinski
The ffs()/fls() guard in
ethnl_set_tsconfig()was meant to enforce that the user selects exactly onetx_type(and onerx_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 <[email protected]>---
CC: [email protected]
CC: [email protected]--- net/ethtool/tsconfig.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)net/ethtool/tsconfig.c +4
-2@@ -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;
net/ethtool/tsconfig.c static int ethnl_set_tsconfig(struct ethnl_req_info *req_base, · line 391
Quoted 10 lines
net/ethtool/tsconfig.c +4
-2-/* 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; }
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 6 lines · On Wed, 12 Aug 2026 09:22:30 -0700 you wrote:
The ffs()/fls() guard in
ethnl_set_tsconfig()was meant to enforce that the user selects exactly onetx_type(and onerx_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.
Quoted 6 lines
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.[...]
Here is the summary with links:
- [net-next] ethtool: tsconfig: reject zero-valued tx_type and rx_filter bitsets
https://git.kernel.org/netdev/net-next/c/77e80af7d2d4
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html