Skip to contentSkip to conversation

crypto: Annotate crypto strings with nonstring

PATCH Applied Kees Cook 2 participants 2 messages May 29, 2025 – Jun 10, 2025

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 crypto: Annotate crypto strings with nonstring

Annotate various keys, ivs, and other byte arrays with __nonstring so that static initializers will not complain about truncating the trailing NUL byte under GCC 15 with -Wunterminated-string-initialization enabled. Silences many warnings like:

../lib/crypto/aesgcm.c:642:27: warning: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (13 chars into 12 available) [-Wunterminated-string-initialization]
642 | .iv = "\xca\xfe\xba\xbe\xfa\xce\xdb\xad"

      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---
Cc: Herbert Xu <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: <[email protected]>

---
 lib/crypto/aescfb.c |  8 ++++----
 lib/crypto/aesgcm.c | 46 ++++++++++++++++++++++-----------------------
 2 files changed, 27 insertions(+), 27 deletions(-)
lib/crypto/aescfb.c +4 -4
index 437613265e14..2f09ae92ffa0 100644
@@ -106,11 +106,11 @@ MODULE_LICENSE("GPL");
  */
 
 static struct {
-	u8	ptext[64];
-	u8	ctext[64];
+	u8	ptext[64] __nonstring;
+	u8	ctext[64] __nonstring;
 
-	u8	key[AES_MAX_KEY_SIZE];
-	u8	iv[AES_BLOCK_SIZE];
+	u8	key[AES_MAX_KEY_SIZE] __nonstring;
+	u8	iv[AES_BLOCK_SIZE] __nonstring;
 
 	int	klen;
 	int	len;
lib/crypto/aesgcm.c +23 -23

162 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer Applied
#1 lore raw
Quoted 16 lines · Kees Cook

Annotate various keys, ivs, and other byte arrays with __nonstring so that static initializers will not complain about truncating the trailing NUL byte under GCC 15 with -Wunterminated-string-initialization enabled. Silences many warnings like:

../lib/crypto/aesgcm.c:642:27: warning: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (13 chars into 12 available) [-Wunterminated-string-initialization]
642 | .iv = "\xca\xfe\xba\xbe\xfa\xce\xdb\xad"

      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---
Cc: Herbert Xu <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: <[email protected]>

Quoted 4 lines
---
 lib/crypto/aescfb.c |  8 ++++----
 lib/crypto/aesgcm.c | 46 ++++++++++++++++++++++-----------------------
 2 files changed, 27 insertions(+), 27 deletions(-)

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-fixes

Thanks!

- Eric