History

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.

Jakub Kicinski committed 3 months ago

Commit 77e80af1 parent a7c44611 file · +8 −4Browse files

Unified · Split

net/ethtool/tsconfig.c+8−4
@@ -359,8 +359,10 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base, · 358 unmodified lines
359 if (ret < 0)359 if (ret < 0)
360 goto err_free_hwprov;360 goto err_free_hwprov;
361 361
362 /* Select only one tx type at a time */362 /* Select exactly one tx type at a time */
363 if (ffs(req_tx_type) != fls(req_tx_type)) {363 if (hweight32(req_tx_type) != 1) {
364 NL_SET_BAD_ATTR(info->extack,
365 tb[ETHTOOL_A_TSCONFIG_TX_TYPES]);
364 ret = -EINVAL;366 ret = -EINVAL;
365 goto err_free_hwprov;367 goto err_free_hwprov;
366 }368 }
@@ -380,8 +382,10 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base, · 13 unmodified lines
380 if (ret < 0)382 if (ret < 0)
381 goto err_free_hwprov;383 goto err_free_hwprov;
382 384
383 /* Select only one rx filter at a time */385 /* Select exactly one rx filter at a time */
384 if (ffs(req_rx_filter) != fls(req_rx_filter)) {386 if (hweight32(req_rx_filter) != 1) {
387 NL_SET_BAD_ATTR(info->extack,
388 tb[ETHTOOL_A_TSCONFIG_RX_FILTERS]);
385 ret = -EINVAL;389 ret = -EINVAL;
386 goto err_free_hwprov;390 goto err_free_hwprov;
387 }391 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t