lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <76ba2536-8137-4665-a8b5-46b74899bb22@intel.com>
Date: Wed, 12 Mar 2025 15:57:45 -0700
From: Jacob Keller <jacob.e.keller@...el.com>
To: Kees Cook <kees@...nel.org>, Nicolas Ferre <nicolas.ferre@...rochip.com>
CC: Claudiu Beznea <claudiu.beznea@...on.dev>, Andrew Lunn
	<andrew+netdev@...n.ch>, "David S. Miller" <davem@...emloft.net>, "Eric
 Dumazet" <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>, Paolo Abeni
	<pabeni@...hat.com>, <netdev@...r.kernel.org>,
	<linux-kernel@...r.kernel.org>, <linux-hardening@...r.kernel.org>
Subject: Re: [PATCH v3] net: macb: Add __nonstring annotations for
 unterminated strings



On 3/12/2025 1:07 PM, 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 correctly identify the char array as "not a C string"
> and thereby eliminate the warning:
> 
> In file included from ../drivers/net/ethernet/cadence/macb_main.c:42:
> ../drivers/net/ethernet/cadence/macb.h:1070:35: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (33 chars into 32 available) [-Wunterminated-string-initialization]
>  1070 |         GEM_STAT_TITLE(TX1519CNT, "tx_greater_than_1518_byte_frames"),
>       |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../drivers/net/ethernet/cadence/macb.h:1050:24: note: in definition of macro 'GEM_STAT_TITLE_BITS'
>  1050 |         .stat_string = title,                           \
>       |                        ^~~~~
> ../drivers/net/ethernet/cadence/macb.h:1070:9: note: in expansion of macro 'GEM_STAT_TITLE'
>  1070 |         GEM_STAT_TITLE(TX1519CNT, "tx_greater_than_1518_byte_frames"),
>       |         ^~~~~~~~~~~~~~
> ../drivers/net/ethernet/cadence/macb.h:1097:35: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (33 chars into 32 available) [-Wunterminated-string-initialization]
>  1097 |         GEM_STAT_TITLE(RX1519CNT, "rx_greater_than_1518_byte_frames"),
>       |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../drivers/net/ethernet/cadence/macb.h:1050:24: note: in definition of macro 'GEM_STAT_TITLE_BITS'
>  1050 |         .stat_string = title,                           \
>       |                        ^~~~~
> ../drivers/net/ethernet/cadence/macb.h:1097:9: note: in expansion of macro 'GEM_STAT_TITLE'
>  1097 |         GEM_STAT_TITLE(RX1519CNT, "rx_greater_than_1518_byte_frames"),
>       |         ^~~~~~~~~~~~~~
> 
> Since these strings are copied with memcpy() they do not need to be
> NUL terminated, and can use __nonstring:
> 
>                         memcpy(p, gem_statistics[i].stat_string,
>                                ETH_GSTRING_LEN);
> 
> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
> Signed-off-by: Kees Cook <kees@...nel.org>
> ---

Reviewed-by: Jacob Keller <jacob.e.keller@...el.com>

>  v3: improve commit message (Bill), drop whitespace change (Bill)
>  v2: https://lore.kernel.org/lkml/20250311224412.it.153-kees@kernel.org/
>  v1: https://lore.kernel.org/lkml/20250310222415.work.815-kees@kernel.org/
> Cc: Nicolas Ferre <nicolas.ferre@...rochip.com>
> Cc: Claudiu Beznea <claudiu.beznea@...on.dev>
> Cc: Andrew Lunn <andrew+netdev@...n.ch>
> Cc: "David S. Miller" <davem@...emloft.net>
> Cc: Eric Dumazet <edumazet@...gle.com>
> Cc: Jakub Kicinski <kuba@...nel.org>
> Cc: Paolo Abeni <pabeni@...hat.com>
> Cc: netdev@...r.kernel.org
> ---
>  drivers/net/ethernet/cadence/macb.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
> index 2847278d9cd4..d2a4c180d6a6 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;
>  };


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ