Skip to contentSkip to conversation

net: macb: Truncate TX1519CNT for trailing NUL

PATCH In review Kees Cook 3 participants 5 messages Mar 10, 2025 – Mar 11, 2025

Subsystems (3)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 net: macb: Truncate TX1519CNT for trailing NUL

GCC 15's -Wunterminated-string-initialization saw that this string was being truncated. Adjust the initializer so that the needed final NUL character will be present.

Cc Nicolas Ferre <[email protected]>
Cc Claudiu Beznea <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
---
 drivers/net/ethernet/cadence/macb.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb.h +2 -1
index 2847278d9cd4..9a6acb97c82d 100644
@@ -1067,7 +1067,8 @@ static const struct gem_statistic gem_statistics[] = {
 	GEM_STAT_TITLE(TX256CNT, "tx_256_511_byte_frames"),
 	GEM_STAT_TITLE(TX512CNT, "tx_512_1023_byte_frames"),
 	GEM_STAT_TITLE(TX1024CNT, "tx_1024_1518_byte_frames"),
-	GEM_STAT_TITLE(TX1519CNT, "tx_greater_than_1518_byte_frames"),
+	GEM_STAT_TITLE(TX1519CNT, "tx_greater_than_1518_byte_frame"),
+
 	GEM_STAT_TITLE_BITS(TXURUNCNT, "tx_underrun",
 			    GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_TXFIFOERR)),
 	GEM_STAT_TITLE_BITS(SNGLCOLLCNT, "tx_single_collision_frames",
Signature · 1 line
2.34.1
#1 lore raw
Quoted 22 lines · Kees Cook

GCC 15's -Wunterminated-string-initialization saw that this string was being truncated. Adjust the initializer so that the needed final NUL character will be present.

Cc Nicolas Ferre <[email protected]>
Cc Claudiu Beznea <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
---
 drivers/net/ethernet/cadence/macb.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb.h +0 -0
index 2847278d9cd4..9a6acb97c82d 100644

drivers/net/ethernet/cadence/macb.h static const struct gem_statistic gem_statistics[] = { · line 1074

Quoted 9 lines
drivers/net/ethernet/cadence/macb.h +2 -1
@@ -1067,7 +1067,8 @@ static const struct gem_statistic gem_statistics[] = {
 	GEM_STAT_TITLE(TX256CNT, "tx_256_511_byte_frames"),
 	GEM_STAT_TITLE(TX512CNT, "tx_512_1023_byte_frames"),
 	GEM_STAT_TITLE(TX1024CNT, "tx_1024_1518_byte_frames"),
-	GEM_STAT_TITLE(TX1519CNT, "tx_greater_than_1518_byte_frames"),
+	GEM_STAT_TITLE(TX1519CNT, "tx_greater_than_1518_byte_frame"),
+
 	GEM_STAT_TITLE_BITS(TXURUNCNT, "tx_underrun",
 			    GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_TXFIFOERR)),
 	GEM_STAT_TITLE_BITS(SNGLCOLLCNT, "tx_single_collision_frames",

"rx_greater_than_1518_byte_frames" is also 32, probably you should fix that too.

Thanks

Quoted 3 lines
Signature · 1 line
2.34.1
author
#2 lore raw
Quoted 27 lines · Michal Swiatkowski
Quoted 26 lines · Kees Cook

GCC 15's -Wunterminated-string-initialization saw that this string was being truncated. Adjust the initializer so that the needed final NUL character will be present.

Cc Nicolas Ferre <[email protected]>
Cc Claudiu Beznea <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
---
 drivers/net/ethernet/cadence/macb.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb.h +0 -1
index 2847278d9cd4..9a6acb97c82d 100644
@@ -1067,7 +1067,8 @@ static const struct gem_statistic gem_statistics[] = {
 	GEM_STAT_TITLE(TX256CNT, "tx_256_511_byte_frames"),
 	GEM_STAT_TITLE(TX512CNT, "tx_512_1023_byte_frames"),
 	GEM_STAT_TITLE(TX1024CNT, "tx_1024_1518_byte_frames"),
-	GEM_STAT_TITLE(TX1519CNT, "tx_greater_than_1518_byte_frames"),
Quoted 8 lines

drivers/net/ethernet/cadence/macb.h static const struct gem_statistic gem_statistics[] = { · line 1074

Quoted 5 lines
drivers/net/ethernet/cadence/macb.h +2 -0
+	GEM_STAT_TITLE(TX1519CNT, "tx_greater_than_1518_byte_frame"),
+
 	GEM_STAT_TITLE_BITS(TXURUNCNT, "tx_underrun",
 			    GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_TXFIFOERR)),
 	GEM_STAT_TITLE_BITS(SNGLCOLLCNT, "tx_single_collision_frames",

"rx_greater_than_1518_byte_frames" is also 32, probably you should fix that too.

Ah! So it is, thank you. I must have missed it while grinding through all the warnings I was working on. I will adjust this!

Signature · 1 line
Kees Cook
#3 lore raw
In reply to Kees Cook
Quoted 3 lines · Kees Cook

GCC 15's -Wunterminated-string-initialization saw that this string was being truncated. Adjust the initializer so that the needed final NUL character will be present.

This is where we get into the ugliness of the ethtool API for strings. It is not actually NUL terminated. The code uses memcpy(), see:

https://elixir.bootlin.com/linux/v6.13.6/source/drivers/net/ethernet/cadence/macb_main.c#L3193

The kAPI is that userspace provides a big buffer, and the kernel then copies these strings into the buffer at 32 byte offsets. There is no requirement for a NUL between them since they are all 32 bytes long.

Andrew

author
#4 lore raw
Quoted 5 lines · Andrew Lunn
Quoted 3 lines · Kees Cook

GCC 15's -Wunterminated-string-initialization saw that this string was being truncated. Adjust the initializer so that the needed final NUL character will be present.

Quoted 8 lines

This is where we get into the ugliness of the ethtool API for strings. It is not actually NUL terminated. The code uses memcpy(), see:

https://elixir.bootlin.com/linux/v6.13.6/source/drivers/net/ethernet/cadence/macb_main.c#L3193

The kAPI is that userspace provides a big buffer, and the kernel then copies these strings into the buffer at 32 byte offsets. There is no requirement for a NUL between them since they are all 32 bytes long.

Oh right! Yes, I always forget these are not NUL terminated. Okay, I will resend this with a proper __nonstring annotation. I see the title use in drivers/net/ethernet/cadence/macb_main.c and can confirm it's not using C String APIs.

Signature · 1 line
Kees Cook