Skip to content

Commit e202196

Browse files
keesebiggers
authored andcommitted
lib/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" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent 19272b3 commit e202196

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

lib/crypto/aescfb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ MODULE_LICENSE("GPL");
106106
*/
107107

108108
static struct {
109-
u8 ptext[64];
110-
u8 ctext[64];
109+
u8 ptext[64] __nonstring;
110+
u8 ctext[64] __nonstring;
111111

112-
u8 key[AES_MAX_KEY_SIZE];
113-
u8 iv[AES_BLOCK_SIZE];
112+
u8 key[AES_MAX_KEY_SIZE] __nonstring;
113+
u8 iv[AES_BLOCK_SIZE] __nonstring;
114114

115115
int klen;
116116
int len;

lib/crypto/aesgcm.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,19 @@ MODULE_LICENSE("GPL");
205205
* Test code below. Vectors taken from crypto/testmgr.h
206206
*/
207207

208-
static const u8 __initconst ctext0[16] =
208+
static const u8 __initconst ctext0[16] __nonstring =
209209
"\x58\xe2\xfc\xce\xfa\x7e\x30\x61"
210210
"\x36\x7f\x1d\x57\xa4\xe7\x45\x5a";
211211

212212
static const u8 __initconst ptext1[16];
213213

214-
static const u8 __initconst ctext1[32] =
214+
static const u8 __initconst ctext1[32] __nonstring =
215215
"\x03\x88\xda\xce\x60\xb6\xa3\x92"
216216
"\xf3\x28\xc2\xb9\x71\xb2\xfe\x78"
217217
"\xab\x6e\x47\xd4\x2c\xec\x13\xbd"
218218
"\xf5\x3a\x67\xb2\x12\x57\xbd\xdf";
219219

220-
static const u8 __initconst ptext2[64] =
220+
static const u8 __initconst ptext2[64] __nonstring =
221221
"\xd9\x31\x32\x25\xf8\x84\x06\xe5"
222222
"\xa5\x59\x09\xc5\xaf\xf5\x26\x9a"
223223
"\x86\xa7\xa9\x53\x15\x34\xf7\xda"
@@ -227,7 +227,7 @@ static const u8 __initconst ptext2[64] =
227227
"\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57"
228228
"\xba\x63\x7b\x39\x1a\xaf\xd2\x55";
229229

230-
static const u8 __initconst ctext2[80] =
230+
static const u8 __initconst ctext2[80] __nonstring =
231231
"\x42\x83\x1e\xc2\x21\x77\x74\x24"
232232
"\x4b\x72\x21\xb7\x84\xd0\xd4\x9c"
233233
"\xe3\xaa\x21\x2f\x2c\x02\xa4\xe0"
@@ -239,7 +239,7 @@ static const u8 __initconst ctext2[80] =
239239
"\x4d\x5c\x2a\xf3\x27\xcd\x64\xa6"
240240
"\x2c\xf3\x5a\xbd\x2b\xa6\xfa\xb4";
241241

242-
static const u8 __initconst ptext3[60] =
242+
static const u8 __initconst ptext3[60] __nonstring =
243243
"\xd9\x31\x32\x25\xf8\x84\x06\xe5"
244244
"\xa5\x59\x09\xc5\xaf\xf5\x26\x9a"
245245
"\x86\xa7\xa9\x53\x15\x34\xf7\xda"
@@ -249,7 +249,7 @@ static const u8 __initconst ptext3[60] =
249249
"\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57"
250250
"\xba\x63\x7b\x39";
251251

252-
static const u8 __initconst ctext3[76] =
252+
static const u8 __initconst ctext3[76] __nonstring =
253253
"\x42\x83\x1e\xc2\x21\x77\x74\x24"
254254
"\x4b\x72\x21\xb7\x84\xd0\xd4\x9c"
255255
"\xe3\xaa\x21\x2f\x2c\x02\xa4\xe0"
@@ -261,17 +261,17 @@ static const u8 __initconst ctext3[76] =
261261
"\x5b\xc9\x4f\xbc\x32\x21\xa5\xdb"
262262
"\x94\xfa\xe9\x5a\xe7\x12\x1a\x47";
263263

264-
static const u8 __initconst ctext4[16] =
264+
static const u8 __initconst ctext4[16] __nonstring =
265265
"\xcd\x33\xb2\x8a\xc7\x73\xf7\x4b"
266266
"\xa0\x0e\xd1\xf3\x12\x57\x24\x35";
267267

268-
static const u8 __initconst ctext5[32] =
268+
static const u8 __initconst ctext5[32] __nonstring =
269269
"\x98\xe7\x24\x7c\x07\xf0\xfe\x41"
270270
"\x1c\x26\x7e\x43\x84\xb0\xf6\x00"
271271
"\x2f\xf5\x8d\x80\x03\x39\x27\xab"
272272
"\x8e\xf4\xd4\x58\x75\x14\xf0\xfb";
273273

274-
static const u8 __initconst ptext6[64] =
274+
static const u8 __initconst ptext6[64] __nonstring =
275275
"\xd9\x31\x32\x25\xf8\x84\x06\xe5"
276276
"\xa5\x59\x09\xc5\xaf\xf5\x26\x9a"
277277
"\x86\xa7\xa9\x53\x15\x34\xf7\xda"
@@ -281,7 +281,7 @@ static const u8 __initconst ptext6[64] =
281281
"\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57"
282282
"\xba\x63\x7b\x39\x1a\xaf\xd2\x55";
283283

284-
static const u8 __initconst ctext6[80] =
284+
static const u8 __initconst ctext6[80] __nonstring =
285285
"\x39\x80\xca\x0b\x3c\x00\xe8\x41"
286286
"\xeb\x06\xfa\xc4\x87\x2a\x27\x57"
287287
"\x85\x9e\x1c\xea\xa6\xef\xd9\x84"
@@ -293,17 +293,17 @@ static const u8 __initconst ctext6[80] =
293293
"\x99\x24\xa7\xc8\x58\x73\x36\xbf"
294294
"\xb1\x18\x02\x4d\xb8\x67\x4a\x14";
295295

296-
static const u8 __initconst ctext7[16] =
296+
static const u8 __initconst ctext7[16] __nonstring =
297297
"\x53\x0f\x8a\xfb\xc7\x45\x36\xb9"
298298
"\xa9\x63\xb4\xf1\xc4\xcb\x73\x8b";
299299

300-
static const u8 __initconst ctext8[32] =
300+
static const u8 __initconst ctext8[32] __nonstring =
301301
"\xce\xa7\x40\x3d\x4d\x60\x6b\x6e"
302302
"\x07\x4e\xc5\xd3\xba\xf3\x9d\x18"
303303
"\xd0\xd1\xc8\xa7\x99\x99\x6b\xf0"
304304
"\x26\x5b\x98\xb5\xd4\x8a\xb9\x19";
305305

306-
static const u8 __initconst ptext9[64] =
306+
static const u8 __initconst ptext9[64] __nonstring =
307307
"\xd9\x31\x32\x25\xf8\x84\x06\xe5"
308308
"\xa5\x59\x09\xc5\xaf\xf5\x26\x9a"
309309
"\x86\xa7\xa9\x53\x15\x34\xf7\xda"
@@ -313,7 +313,7 @@ static const u8 __initconst ptext9[64] =
313313
"\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57"
314314
"\xba\x63\x7b\x39\x1a\xaf\xd2\x55";
315315

316-
static const u8 __initconst ctext9[80] =
316+
static const u8 __initconst ctext9[80] __nonstring =
317317
"\x52\x2d\xc1\xf0\x99\x56\x7d\x07"
318318
"\xf4\x7f\x37\xa3\x2a\x84\x42\x7d"
319319
"\x64\x3a\x8c\xdc\xbf\xe5\xc0\xc9"
@@ -325,7 +325,7 @@ static const u8 __initconst ctext9[80] =
325325
"\xb0\x94\xda\xc5\xd9\x34\x71\xbd"
326326
"\xec\x1a\x50\x22\x70\xe3\xcc\x6c";
327327

328-
static const u8 __initconst ptext10[60] =
328+
static const u8 __initconst ptext10[60] __nonstring =
329329
"\xd9\x31\x32\x25\xf8\x84\x06\xe5"
330330
"\xa5\x59\x09\xc5\xaf\xf5\x26\x9a"
331331
"\x86\xa7\xa9\x53\x15\x34\xf7\xda"
@@ -335,7 +335,7 @@ static const u8 __initconst ptext10[60] =
335335
"\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57"
336336
"\xba\x63\x7b\x39";
337337

338-
static const u8 __initconst ctext10[76] =
338+
static const u8 __initconst ctext10[76] __nonstring =
339339
"\x52\x2d\xc1\xf0\x99\x56\x7d\x07"
340340
"\xf4\x7f\x37\xa3\x2a\x84\x42\x7d"
341341
"\x64\x3a\x8c\xdc\xbf\xe5\xc0\xc9"
@@ -347,7 +347,7 @@ static const u8 __initconst ctext10[76] =
347347
"\x76\xfc\x6e\xce\x0f\x4e\x17\x68"
348348
"\xcd\xdf\x88\x53\xbb\x2d\x55\x1b";
349349

350-
static const u8 __initconst ptext11[60] =
350+
static const u8 __initconst ptext11[60] __nonstring =
351351
"\xd9\x31\x32\x25\xf8\x84\x06\xe5"
352352
"\xa5\x59\x09\xc5\xaf\xf5\x26\x9a"
353353
"\x86\xa7\xa9\x53\x15\x34\xf7\xda"
@@ -357,7 +357,7 @@ static const u8 __initconst ptext11[60] =
357357
"\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57"
358358
"\xba\x63\x7b\x39";
359359

360-
static const u8 __initconst ctext11[76] =
360+
static const u8 __initconst ctext11[76] __nonstring =
361361
"\x39\x80\xca\x0b\x3c\x00\xe8\x41"
362362
"\xeb\x06\xfa\xc4\x87\x2a\x27\x57"
363363
"\x85\x9e\x1c\xea\xa6\xef\xd9\x84"
@@ -369,7 +369,7 @@ static const u8 __initconst ctext11[76] =
369369
"\x25\x19\x49\x8e\x80\xf1\x47\x8f"
370370
"\x37\xba\x55\xbd\x6d\x27\x61\x8c";
371371

372-
static const u8 __initconst ptext12[719] =
372+
static const u8 __initconst ptext12[719] __nonstring =
373373
"\x42\xc1\xcc\x08\x48\x6f\x41\x3f"
374374
"\x2f\x11\x66\x8b\x2a\x16\xf0\xe0"
375375
"\x58\x83\xf0\xc3\x70\x14\xc0\x5b"
@@ -461,7 +461,7 @@ static const u8 __initconst ptext12[719] =
461461
"\x59\xfa\xfa\xaa\x44\x04\x01\xa7"
462462
"\xa4\x78\xdb\x74\x3d\x8b\xb5";
463463

464-
static const u8 __initconst ctext12[735] =
464+
static const u8 __initconst ctext12[735] __nonstring =
465465
"\x84\x0b\xdb\xd5\xb7\xa8\xfe\x20"
466466
"\xbb\xb1\x12\x7f\x41\xea\xb3\xc0"
467467
"\xa2\xb4\x37\x19\x11\x58\xb6\x0b"
@@ -559,9 +559,9 @@ static struct {
559559
const u8 *ptext;
560560
const u8 *ctext;
561561

562-
u8 key[AES_MAX_KEY_SIZE];
563-
u8 iv[GCM_AES_IV_SIZE];
564-
u8 assoc[20];
562+
u8 key[AES_MAX_KEY_SIZE] __nonstring;
563+
u8 iv[GCM_AES_IV_SIZE] __nonstring;
564+
u8 assoc[20] __nonstring;
565565

566566
int klen;
567567
int clen;

0 commit comments

Comments
 (0)