* [PATCH] wifi: mwifiex: Add __nonstring annotations for unterminated strings
@ 2025-03-10 22:23 Kees Cook
2025-03-25 22:40 ` Brian Norris
0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2025-03-10 22:23 UTC (permalink / raw)
To: Brian Norris
Cc: Kees Cook, Francesco Dolcini, Johannes Berg, Thomas Gleixner,
Greg Kroah-Hartman, Allison Randal, linux-wireless, 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]
Cc: Brian Norris <briannorris@chromium.org>
Cc: Francesco Dolcini <francesco@dolcini.it>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Allison Randal <allison@lohutok.net>
Cc: linux-wireless@vger.kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>
---
drivers/net/wireless/marvell/mwifiex/cfp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/wireless/marvell/mwifiex/cfp.c b/drivers/net/wireless/marvell/mwifiex/cfp.c
index d39092b99212..d7fd79214bcf 100644
--- a/drivers/net/wireless/marvell/mwifiex/cfp.c
+++ b/drivers/net/wireless/marvell/mwifiex/cfp.c
@@ -150,7 +150,7 @@ static const u16 ac_mcs_rate_nss2[8][10] = {
struct region_code_mapping {
u8 code;
- u8 region[IEEE80211_COUNTRY_STRING_LEN];
+ u8 region[IEEE80211_COUNTRY_STRING_LEN] __nonstring;
};
static struct region_code_mapping region_code_mapping_t[] = {
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] wifi: mwifiex: Add __nonstring annotations for unterminated strings
2025-03-10 22:23 [PATCH] wifi: mwifiex: Add __nonstring annotations for unterminated strings Kees Cook
@ 2025-03-25 22:40 ` Brian Norris
0 siblings, 0 replies; 2+ messages in thread
From: Brian Norris @ 2025-03-25 22:40 UTC (permalink / raw)
To: Kees Cook
Cc: Francesco Dolcini, Johannes Berg, Thomas Gleixner,
Greg Kroah-Hartman, Allison Randal, linux-wireless, linux-kernel,
linux-hardening
On Mon, Mar 10, 2025 at 03:23:32PM -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]
> Cc: Brian Norris <briannorris@chromium.org>
> Cc: Francesco Dolcini <francesco@dolcini.it>
> Cc: Johannes Berg <johannes@sipsolutions.net>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Allison Randal <allison@lohutok.net>
> Cc: linux-wireless@vger.kernel.org
> Signed-off-by: Kees Cook <kees@kernel.org>
This code is kinda weird, because only 2 bytes actually end up used, and
yet we explicitly initialize it with 3 non-NUL bytes.
This solutions seems fine though, as it is indeed not a C string and
does not desire nor rely on a NUL byte:
Acked-by: Brian Norris <briannorris@chromium.org>
Looks like Johannes already applied it anyway.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-25 22:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-10 22:23 [PATCH] wifi: mwifiex: Add __nonstring annotations for unterminated strings Kees Cook
2025-03-25 22:40 ` Brian Norris
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).