1fdf2f1dbd340a687e36f7dc1a57a9859a076dbe
[openwrt/staging/xback.git] /
1 From 71e5da46e78c1cd24e2feed251a2845327447ad8 Mon Sep 17 00:00:00 2001
2 From: Kees Cook <kees@kernel.org>
3 Date: Wed, 21 May 2025 23:27:04 +0200
4 Subject: wireguard: global: add __nonstring annotations for unterminated
5 strings
6
7 When a character array without a terminating NUL character has a static
8 initializer, GCC 15's -Wunterminated-string-initialization will only
9 warn if the array lacks the "nonstring" attribute[1]. Mark the arrays
10 with __nonstring to correctly identify the char array as "not a C string"
11 and thereby eliminate the warning:
12
13 ../drivers/net/wireguard/cookie.c:29:56: warning: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (9 chars into 8 available) [-Wunterminated-string-initialization]
14 29 | static const u8 mac1_key_label[COOKIE_KEY_LABEL_LEN] = "mac1----";
15 | ^~~~~~~~~~
16 ../drivers/net/wireguard/cookie.c:30:58: warning: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (9 chars into 8 available) [-Wunterminated-string-initialization]
17 30 | static const u8 cookie_key_label[COOKIE_KEY_LABEL_LEN] = "cookie--";
18 | ^~~~~~~~~~
19 ../drivers/net/wireguard/noise.c:28:38: warning: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (38 chars into 37 available) [-Wunterminated-string-initialization]
20 28 | static const u8 handshake_name[37] = "Noise_IKpsk2_25519_ChaChaPoly_BLAKE2s";
21 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 ../drivers/net/wireguard/noise.c:29:39: warning: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (35 chars into 34 available) [-Wunterminated-string-initialization]
23 29 | static const u8 identifier_name[34] = "WireGuard v1 zx2c4 Jason@zx2c4.com";
24 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25
26 The arrays are always used with their fixed size, so use __nonstring.
27
28 Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 [1]
29 Signed-off-by: Kees Cook <kees@kernel.org>
30 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
31 Link: https://patch.msgid.link/20250521212707.1767879-3-Jason@zx2c4.com
32 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
33 ---
34 drivers/net/wireguard/cookie.c | 4 ++--
35 drivers/net/wireguard/noise.c | 4 ++--
36 2 files changed, 4 insertions(+), 4 deletions(-)
37
38 --- a/drivers/net/wireguard/cookie.c
39 +++ b/drivers/net/wireguard/cookie.c
40 @@ -26,8 +26,8 @@ void wg_cookie_checker_init(struct cooki
41 }
42
43 enum { COOKIE_KEY_LABEL_LEN = 8 };
44 -static const u8 mac1_key_label[COOKIE_KEY_LABEL_LEN] = "mac1----";
45 -static const u8 cookie_key_label[COOKIE_KEY_LABEL_LEN] = "cookie--";
46 +static const u8 mac1_key_label[COOKIE_KEY_LABEL_LEN] __nonstring = "mac1----";
47 +static const u8 cookie_key_label[COOKIE_KEY_LABEL_LEN] __nonstring = "cookie--";
48
49 static void precompute_key(u8 key[NOISE_SYMMETRIC_KEY_LEN],
50 const u8 pubkey[NOISE_PUBLIC_KEY_LEN],
51 --- a/drivers/net/wireguard/noise.c
52 +++ b/drivers/net/wireguard/noise.c
53 @@ -25,8 +25,8 @@
54 * <- e, ee, se, psk, {}
55 */
56
57 -static const u8 handshake_name[37] = "Noise_IKpsk2_25519_ChaChaPoly_BLAKE2s";
58 -static const u8 identifier_name[34] = "WireGuard v1 zx2c4 Jason@zx2c4.com";
59 +static const u8 handshake_name[37] __nonstring = "Noise_IKpsk2_25519_ChaChaPoly_BLAKE2s";
60 +static const u8 identifier_name[34] __nonstring = "WireGuard v1 zx2c4 Jason@zx2c4.com";
61 static u8 handshake_init_hash[NOISE_HASH_LEN] __ro_after_init;
62 static u8 handshake_init_chaining_key[NOISE_HASH_LEN] __ro_after_init;
63 static atomic64_t keypair_counter = ATOMIC64_INIT(0);