Re: [PATCH net v3 1/2] net: ethtool: reject an out of range hwtstamp provider index

From: Kory Maincent

Date: Fri Sep 25 2026 - 13:59:35 EST




On 9/25/26 16:07, Nicolai Buchwitz wrote:
Hi Kory

On 25.9.2026 15:55, Kory Maincent wrote:

[...]

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

I think you can simply do this:
[ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX] =
    NLA_POLICY_MAX(NLA_U32, INT_MAX),

That was my initial thought, but unfortunately it doesn't work. struct nla_policy's
.max is s16 and INT_MAX is truncated to -1. It ends up as U64_MAX in the range check
and in the end nothing gets rejected.

    include/vdso/limits.h:8:25: warning: overflow in conversion from 'int'
    to 'short int' changes value from '2147483647' to '-1' [-Woverflow]

Indeed.
Reviewed-by: Kory Maincent <kory.maincent@xxxxxxxxxxx>

Thank you!

--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com