* [PATCH v2] net: macb: Add __nonstring annotations for unterminated strings
@ 2025-03-11 22:44 Kees Cook
2025-03-11 23:04 ` Bill Wendling
2025-03-18 11:49 ` Simon Horman
0 siblings, 2 replies; 4+ messages in thread
From: Kees Cook @ 2025-03-11 22:44 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
When a character array without a terminating NUL character has a static
initializer, GCC 15's -Wunterminated-string-initialization will only
warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
with __nonstring to and correctly identify the char array as "not a C
string" and thereby eliminate the warning.
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
Signed-off-by: Kees Cook <kees@kernel.org>
---
v1: https://lore.kernel.org/lkml/20250310222415.work.815-kees@kernel.org/
v2: switch to __nonstring annotation
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
---
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..003483073223 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -1027,7 +1027,7 @@ struct gem_stats {
* this register should contribute to.
*/
struct gem_statistic {
- char stat_string[ETH_GSTRING_LEN];
+ char stat_string[ETH_GSTRING_LEN] __nonstring;
int offset;
u32 stat_bits;
};
@@ -1068,6 +1068,7 @@ static const struct gem_statistic gem_statistics[] = {
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_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] 4+ messages in thread
* Re: [PATCH v2] net: macb: Add __nonstring annotations for unterminated strings
2025-03-11 22:44 [PATCH v2] net: macb: Add __nonstring annotations for unterminated strings Kees Cook
@ 2025-03-11 23:04 ` Bill Wendling
2025-03-12 17:07 ` Kees Cook
2025-03-18 11:49 ` Simon Horman
1 sibling, 1 reply; 4+ messages in thread
From: Bill Wendling @ 2025-03-11 23:04 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 Tue, Mar 11, 2025 at 3:44 PM Kees Cook <kees@kernel.org> wrote:
>
> When a character array without a terminating NUL character has a static
> initializer, GCC 15's -Wunterminated-string-initialization will only
> warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
> with __nonstring to and correctly identify the char array as "not a C
s/__nonstring to and correctly/__nonstring to correctly/ ?
> string" and thereby eliminate the warning.
>
> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
> v1: https://lore.kernel.org/lkml/20250310222415.work.815-kees@kernel.org/
> v2: switch to __nonstring annotation
> 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
> ---
> 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..003483073223 100644
> --- a/drivers/net/ethernet/cadence/macb.h
> +++ b/drivers/net/ethernet/cadence/macb.h
> @@ -1027,7 +1027,7 @@ struct gem_stats {
> * this register should contribute to.
> */
> struct gem_statistic {
> - char stat_string[ETH_GSTRING_LEN];
> + char stat_string[ETH_GSTRING_LEN] __nonstring;
> int offset;
> u32 stat_bits;
> };
> @@ -1068,6 +1068,7 @@ static const struct gem_statistic gem_statistics[] = {
> 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"),
> +
Is this an errant inclusion? :-)
Reviewed-by: Bill Wendling <morbo@google.com>
> 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 [flat|nested] 4+ messages in thread
* Re: [PATCH v2] net: macb: Add __nonstring annotations for unterminated strings
2025-03-11 23:04 ` Bill Wendling
@ 2025-03-12 17:07 ` Kees Cook
0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2025-03-12 17:07 UTC (permalink / raw)
To: Bill Wendling
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 04:04:24PM -0700, Bill Wendling wrote:
> On Tue, Mar 11, 2025 at 3:44 PM Kees Cook <kees@kernel.org> wrote:
> >
> > When a character array without a terminating NUL character has a static
> > initializer, GCC 15's -Wunterminated-string-initialization will only
> > warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
> > with __nonstring to and correctly identify the char array as "not a C
>
> s/__nonstring to and correctly/__nonstring to correctly/ ?
Whoops. Rewriting glitch. Yes, "and" should be dropped. I will fix this
locally for all the patches with the same language and send v3 for this
one.
>
> > string" and thereby eliminate the warning.
> >
> > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> > Signed-off-by: Kees Cook <kees@kernel.org>
> > ---
> > v1: https://lore.kernel.org/lkml/20250310222415.work.815-kees@kernel.org/
> > v2: switch to __nonstring annotation
> > 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
> > ---
> > 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..003483073223 100644
> > --- a/drivers/net/ethernet/cadence/macb.h
> > +++ b/drivers/net/ethernet/cadence/macb.h
> > @@ -1027,7 +1027,7 @@ struct gem_stats {
> > * this register should contribute to.
> > */
> > struct gem_statistic {
> > - char stat_string[ETH_GSTRING_LEN];
> > + char stat_string[ETH_GSTRING_LEN] __nonstring;
> > int offset;
> > u32 stat_bits;
> > };
> > @@ -1068,6 +1068,7 @@ static const struct gem_statistic gem_statistics[] = {
> > 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"),
> > +
>
> Is this an errant inclusion? :-)
Ah, yeah, I had removed the truncation change but the whitespace change
stuck around. Also fixing!
>
> Reviewed-by: Bill Wendling <morbo@google.com>
Thanks!
-Kees
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] net: macb: Add __nonstring annotations for unterminated strings
2025-03-11 22:44 [PATCH v2] net: macb: Add __nonstring annotations for unterminated strings Kees Cook
2025-03-11 23:04 ` Bill Wendling
@ 2025-03-18 11:49 ` Simon Horman
1 sibling, 0 replies; 4+ messages in thread
From: Simon Horman @ 2025-03-18 11:49 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 Tue, Mar 11, 2025 at 03:44:16PM -0700, Kees Cook wrote:
> When a character array without a terminating NUL character has a static
> initializer, GCC 15's -Wunterminated-string-initialization will only
> warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
> with __nonstring to and correctly identify the char array as "not a C
> string" and thereby eliminate the warning.
>
> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
> v1: https://lore.kernel.org/lkml/20250310222415.work.815-kees@kernel.org/
> v2: switch to __nonstring annotation
> 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
> ---
> 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..003483073223 100644
> --- a/drivers/net/ethernet/cadence/macb.h
> +++ b/drivers/net/ethernet/cadence/macb.h
> @@ -1027,7 +1027,7 @@ struct gem_stats {
> * this register should contribute to.
> */
> struct gem_statistic {
> - char stat_string[ETH_GSTRING_LEN];
> + char stat_string[ETH_GSTRING_LEN] __nonstring;
Hi Kees, all,
I see where this is going, and I have no objections to it.
But a member called *_string which is annotated as __nonstring
does seem a somewhat unintuitive.
> int offset;
> u32 stat_bits;
> };
> @@ -1068,6 +1068,7 @@ static const struct gem_statistic gem_statistics[] = {
> 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_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 [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-18 11:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-11 22:44 [PATCH v2] net: macb: Add __nonstring annotations for unterminated strings Kees Cook
2025-03-11 23:04 ` Bill Wendling
2025-03-12 17:07 ` Kees Cook
2025-03-18 11:49 ` Simon Horman
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).