net: ethtool: reject an out of range hwtstamp provider index

A provider index of 0xFFFFFFFF picks a provider on hardware that has
none. phc_index is an int where -1 means no PHC, and the u32 from user
space ends up as -1, so the two match.

TSINFO_GET uses -1 for "no provider requested" and answers with the
default provider instead of an error.

Reject the value in the netlink policy, which covers every comparison
site.

Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
Reviewed-by: Kory Maincent <kory.maincent@bootlin.com>
Link: https://patch.msgid.link/20260925135237.3432266-2-nb@tipi-net.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Nicolai Buchwitz 2026-09-25 15:52:35 +02:00 committed by Jakub Kicinski
parent 0a1a3898ab
commit 67da300938

View File

@ -5,9 +5,15 @@
#include "netlink.h"
/* phc_index is an int and -1 means no PHC, so keep the request non-negative */
static const struct netlink_range_validation ethnl_ts_prov_index_range = {
.max = INT_MAX,
};
static const struct nla_policy
ethnl_ts_hwtst_prov_policy[ETHTOOL_A_TS_HWTSTAMP_PROVIDER_MAX + 1] = {
[ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX] = { .type = NLA_U32 },
[ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX] =
NLA_POLICY_FULL_RANGE(NLA_U32, &ethnl_ts_prov_index_range),
[ETHTOOL_A_TS_HWTSTAMP_PROVIDER_QUALIFIER] =
NLA_POLICY_MAX(NLA_U32, HWTSTAMP_PROVIDER_QUALIFIER_CNT - 1)
};