Re: [PATCH v3] net: macb: Add __nonstring annotations for unterminated strings

From: Kees Cook
Date: Thu Mar 13 2025 - 13:44:21 EST


On Thu, Mar 13, 2025 at 02:25:09PM +0100, Andrew Lunn wrote:
> > struct gem_statistic {
> > - char stat_string[ETH_GSTRING_LEN];
> > + char stat_string[ETH_GSTRING_LEN] __nonstring;
>
> This general pattern of a char foo[ETH_GSTRING_LEN]' will appear
> throughout drivers/net/ethernet. Maybe Coccinelle can find them all
> and add the __nonstring ?

I had that same thought but then rediscovered ethtool_puts() and
ethtool_sprintf(), which operate on C Strings and write out C Strings...
so _some_ ethtool stats are being constructed in a way that we can't
just universally apply __nonstring to all ETH_GSTRING_LEN strings. :(

--
Kees Cook