Skip to contentSkip to conversation

net: ethtool: fix wrong type used in struct kernel_ethtool_ts_info

PATCH Applied Russell King (Oracle) 5 participants 6 messages Sep 7, 2025 – Sep 11, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: ethtool: fix wrong type used in struct kernel_ethtool_ts_info

In C, enumerated types do not have a defined size, apart from being compatible with one of the standard types. This allows an ABI / compiler to choose the type of an enum depending on the values it needs to store, and storing larger values in it can lead to undefined behaviour.

The tx_type and rx_filters members of struct kernel_ethtool_ts_info are defined as enumerated types, but are bit arrays, where each bit is defined by the enumerated type. This means they typically store values in excess of the maximum value of the enumerated type, in fact (1 << max_value) and thus must not be declared using the enumated type.

Fix both of these to use u32, as per the corresponding __u32 UAPI type.

Fixes 2111375b85ad ("net: Add struct kernel_ethtool_ts_info")
---
 include/linux/ethtool.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/ethtool.h +2 -2
index de5bd76a400c..d7d757e72554 100644
@@ -856,8 +856,8 @@ struct kernel_ethtool_ts_info {
 	enum hwtstamp_provider_qualifier phc_qualifier;
 	enum hwtstamp_source phc_source;
 	int phc_phyindex;
-	enum hwtstamp_tx_types tx_types;
-	enum hwtstamp_rx_filters rx_filters;
+	u32 tx_types;
+	u32 rx_filters;
 };
 
 /**
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · On Sun, 07 Sep 2025 21:43:20 +0100 "Russell King (Oracle)"…

In C, enumerated types do not have a defined size, apart from being compatible with one of the standard types. This allows an ABI / compiler to choose the type of an enum depending on the values it needs to store, and storing larger values in it can lead to undefined behaviour.

Quoted 8 lines

The tx_type and rx_filters members of struct kernel_ethtool_ts_info are defined as enumerated types, but are bit arrays, where each bit is defined by the enumerated type. This means they typically store values in excess of the maximum value of the enumerated type, in fact (1 << max_value) and thus must not be declared using the enumated type.

Fix both of these to use u32, as per the corresponding __u32 UAPI type.

Thank you!

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
maintainer
#2 lore raw
In reply to Russell King (Oracle)
Quoted 13 lines · On Sun, 07 Sep 2025 21:43:20 +0100 Russell King (Oracle) wrote:

In C, enumerated types do not have a defined size, apart from being compatible with one of the standard types. This allows an ABI / compiler to choose the type of an enum depending on the values it needs to store, and storing larger values in it can lead to undefined behaviour.

The tx_type and rx_filters members of struct kernel_ethtool_ts_info are defined as enumerated types, but are bit arrays, where each bit is defined by the enumerated type. This means they typically store values in excess of the maximum value of the enumerated type, in fact (1 << max_value) and thus must not be declared using the enumated type.

Quoted 3 lines

Fix both of these to use u32, as per the corresponding __u32 UAPI type.

Fixes 2111375b85ad ("net: Add struct kernel_ethtool_ts_info")

Do you feel strongly about this being a fix? (I can adjust when applying FWIW). It's clearly not great but I don't think storing a mask of enum values cause functional problems.

#3 lore raw
Quoted 14 lines · Jakub Kicinski
Quoted 13 lines · On Sun, 07 Sep 2025 21:43:20 +0100 Russell King (Oracle) wrote:

In C, enumerated types do not have a defined size, apart from being compatible with one of the standard types. This allows an ABI / compiler to choose the type of an enum depending on the values it needs to store, and storing larger values in it can lead to undefined behaviour.

The tx_type and rx_filters members of struct kernel_ethtool_ts_info are defined as enumerated types, but are bit arrays, where each bit is defined by the enumerated type. This means they typically store values in excess of the maximum value of the enumerated type, in fact (1 << max_value) and thus must not be declared using the enumated type.

Quoted 7 lines
Quoted 3 lines

Fix both of these to use u32, as per the corresponding __u32 UAPI type.

Fixes 2111375b85ad ("net: Add struct kernel_ethtool_ts_info")

Do you feel strongly about this being a fix? (I can adjust when applying FWIW). It's clearly not great but I don't think storing a mask of enum values cause functional problems.

Whether or not it causes problems depends whether we have any compilers that are used for the kernel which select the size of an enum type based on the value.

From what I recall, when EABI for ARM was being talked about, that compiler behaviour was certainly on the table. I opposed it - and we ended up with arm-linux and arm-none variants of EABI. Whether there's still a difference today, I'm not sure.

Even without Fixes: I think you'll find that the stable autosel bot will still pick this change up... it uses "AI".

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
maintainer
#4 lore raw
Quoted 2 lines · On Wed, 10 Sep 2025 13:46:55 +0100 Russell King (Oracle) wrote:

Even without Fixes: I think you'll find that the stable autosel bot will still pick this change up... it uses "AI".

yeah.. probably..

#5 lore raw
In reply to Russell King (Oracle)
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 6 lines · On Sun, 07 Sep 2025 21:43:20 +0100 you wrote:

In C, enumerated types do not have a defined size, apart from being compatible with one of the standard types. This allows an ABI / compiler to choose the type of an enum depending on the values it needs to store, and storing larger values in it can lead to undefined behaviour.

Quoted 8 lines

The tx_type and rx_filters members of struct kernel_ethtool_ts_info are defined as enumerated types, but are bit arrays, where each bit is defined by the enumerated type. This means they typically store values in excess of the maximum value of the enumerated type, in fact (1 << max_value) and thus must not be declared using the enumated type.

[...]

Here is the summary with links:
- [net] net: ethtool: fix wrong type used in struct kernel_ethtool_ts_info

    https://git.kernel.org/netdev/net/c/6fef6ae764be

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html