netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: macb: Truncate TX1519CNT for trailing NUL
@ 2025-03-10 22:24 Kees Cook
  2025-03-11  7:27 ` Michal Swiatkowski
  2025-03-11 14:12 ` Andrew Lunn
  0 siblings, 2 replies; 5+ messages in thread
From: Kees Cook @ 2025-03-10 22:24 UTC (permalink / raw)
  To: Nicolas Ferre
  Cc: Kees Cook, Claudiu Beznea, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	linux-hardening

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 <nicolas.ferre@microchip.com>
Cc: Claudiu Beznea <claudiu.beznea@tuxon.dev>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>
---
 drivers/net/ethernet/cadence/macb.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index 2847278d9cd4..9a6acb97c82d 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -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",
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: macb: Truncate TX1519CNT for trailing NUL
  2025-03-10 22:24 [PATCH] net: macb: Truncate TX1519CNT for trailing NUL Kees Cook
@ 2025-03-11  7:27 ` Michal Swiatkowski
  2025-03-11 22:38   ` Kees Cook
  2025-03-11 14:12 ` Andrew Lunn
  1 sibling, 1 reply; 5+ messages in thread
From: Michal Swiatkowski @ 2025-03-11  7:27 UTC (permalink / raw)
  To: Kees Cook
  Cc: Nicolas Ferre, Claudiu Beznea, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	linux-hardening

On Mon, Mar 10, 2025 at 03:24:16PM -0700, Kees Cook wrote:
> 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 <nicolas.ferre@microchip.com>
> Cc: Claudiu Beznea <claudiu.beznea@tuxon.dev>
> Cc: Andrew Lunn <andrew+netdev@lunn.ch>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
>  drivers/net/ethernet/cadence/macb.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
> index 2847278d9cd4..9a6acb97c82d 100644
> --- a/drivers/net/ethernet/cadence/macb.h
> +++ b/drivers/net/ethernet/cadence/macb.h
> @@ -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

> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: macb: Truncate TX1519CNT for trailing NUL
  2025-03-10 22:24 [PATCH] net: macb: Truncate TX1519CNT for trailing NUL Kees Cook
  2025-03-11  7:27 ` Michal Swiatkowski
@ 2025-03-11 14:12 ` Andrew Lunn
  2025-03-11 22:41   ` Kees Cook
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2025-03-11 14:12 UTC (permalink / raw)
  To: Kees Cook
  Cc: Nicolas Ferre, Claudiu Beznea, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	linux-hardening

On Mon, Mar 10, 2025 at 03:24:16PM -0700, Kees Cook wrote:
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: macb: Truncate TX1519CNT for trailing NUL
  2025-03-11  7:27 ` Michal Swiatkowski
@ 2025-03-11 22:38   ` Kees Cook
  0 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2025-03-11 22:38 UTC (permalink / raw)
  To: Michal Swiatkowski
  Cc: Nicolas Ferre, Claudiu Beznea, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	linux-hardening

On Tue, Mar 11, 2025 at 08:27:45AM +0100, Michal Swiatkowski wrote:
> On Mon, Mar 10, 2025 at 03:24:16PM -0700, Kees Cook wrote:
> > 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 <nicolas.ferre@microchip.com>
> > Cc: Claudiu Beznea <claudiu.beznea@tuxon.dev>
> > Cc: Andrew Lunn <andrew+netdev@lunn.ch>
> > Cc: "David S. Miller" <davem@davemloft.net>
> > Cc: Eric Dumazet <edumazet@google.com>
> > Cc: Jakub Kicinski <kuba@kernel.org>
> > Cc: Paolo Abeni <pabeni@redhat.com>
> > Cc: netdev@vger.kernel.org
> > Signed-off-by: Kees Cook <kees@kernel.org>
> > ---
> >  drivers/net/ethernet/cadence/macb.h | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
> > index 2847278d9cd4..9a6acb97c82d 100644
> > --- a/drivers/net/ethernet/cadence/macb.h
> > +++ b/drivers/net/ethernet/cadence/macb.h
> > @@ -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.

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!

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: macb: Truncate TX1519CNT for trailing NUL
  2025-03-11 14:12 ` Andrew Lunn
@ 2025-03-11 22:41   ` Kees Cook
  0 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2025-03-11 22:41 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Nicolas Ferre, Claudiu Beznea, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	linux-hardening

On Tue, Mar 11, 2025 at 03:12:00PM +0100, Andrew Lunn wrote:
> On Mon, Mar 10, 2025 at 03:24:16PM -0700, Kees Cook wrote:
> > 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.

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.

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-03-11 22:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-10 22:24 [PATCH] net: macb: Truncate TX1519CNT for trailing NUL Kees Cook
2025-03-11  7:27 ` Michal Swiatkowski
2025-03-11 22:38   ` Kees Cook
2025-03-11 14:12 ` Andrew Lunn
2025-03-11 22:41   ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).