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

Subsystems: networking [ethtool], networking [general], the rest

COLD16d IN NET-NEXT

Queued in net-next as 67da3009384f on 2026-09-29.

6 messages, 3 authors, 16d ago · open the first message on its own page

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

From: Nicolai Buchwitz <nb@tipi-net.de>
Date: 2026-09-25 13:53:10

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.

Fixes: b9e3f7dc9ed9 ("net: ethtool: tsinfo: Enhance tsinfo to support several hwtstamp by net topology")
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
NLA_POLICY_MAX does not fit here, .max in struct nla_policy is s16.

 net/ethtool/ts.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/net/ethtool/ts.h b/net/ethtool/ts.h
index d901a879a671..ab9805308353 100644
--- a/net/ethtool/ts.h
+++ b/net/ethtool/ts.h
@@ -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)
 };
base-commit: 11536ee3d3e0b1bd35b6f3f8df55a6053eb0c71d
-- 
2.53.0

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

From: Kory Maincent <kory.maincent@bootlin.com>
Date: 2026-09-25 13:56:08


On 9/25/26 15:52, Nicolai Buchwitz wrote:
quoted hunk
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.

Fixes: b9e3f7dc9ed9 ("net: ethtool: tsinfo: Enhance tsinfo to support several hwtstamp by net topology")
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
NLA_POLICY_MAX does not fit here, .max in struct nla_policy is s16.

  net/ethtool/ts.h | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/net/ethtool/ts.h b/net/ethtool/ts.h
index d901a879a671..ab9805308353 100644
--- a/net/ethtool/ts.h
+++ b/net/ethtool/ts.h
@@ -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)
  };
I think you can simply do this:
[ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX] =
	NLA_POLICY_MAX(NLA_U32, INT_MAX),
base-commit: 11536ee3d3e0b1bd35b6f3f8df55a6053eb0c71d
-- 
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

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

From: Nicolai Buchwitz <nb@tipi-net.de>
Date: 2026-09-25 14:07:25

Hi Kory

On 25.9.2026 15:55, Kory Maincent wrote:
[...]
quoted
  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]
[...]
Thanks,
Nicolai

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

From: Kory Maincent <kory.maincent@bootlin.com>
Date: 2026-09-25 17:57:32


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

On 25.9.2026 15:55, Kory Maincent wrote:
quoted
[...]
quoted
quoted
  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@bootlin.com>

Thank you!

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

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

From: patchwork-bot+netdevbpf@kernel.org
Date: 2026-09-29 02:30:08

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski [off-list ref]:

On Fri, 25 Sep 2026 15:52:35 +0200 you wrote:
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.

[...]
Here is the summary with links:
  - [net,v3,1/2] net: ethtool: reject an out of range hwtstamp provider index
    (no matching commit)
  - [net,v3,2/2] net: ethtool: let tsconfig reach a PHY-only timestamp provider
    https://git.kernel.org/netdev/net/c/036778a4fad1

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

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

From: patchwork-bot+netdevbpf@kernel.org
Date: 2026-09-29 02:40:15

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski [off-list ref]:

On Fri, 25 Sep 2026 15:52:35 +0200 you wrote:
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.

[...]
Here is the summary with links:
  - [net,v3,1/2] net: ethtool: reject an out of range hwtstamp provider index
    https://git.kernel.org/netdev/net-next/c/67da3009384f
  - [net,v3,2/2] net: ethtool: let tsconfig reach a PHY-only timestamp provider
    (no matching commit)

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help