Skip to contentSkip to conversation

scsi: pm80xx: Add __nonstring annotations for unterminated strings

PATCH Applied Kees Cook 3 participants 4 messages Mar 10, 2025 – Apr 12, 2025

Subsystems (2)

v1 of 3 Applied Latest is v3 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 scsi: pm80xx: Add __nonstring annotations for unterminated strings

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.

---
 drivers/scsi/pm8001/pm8001_ctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/pm8001/pm8001_ctl.c +1 -1
index 85ff95c6543a..7618f9cc9986 100644
@@ -644,7 +644,7 @@ static DEVICE_ATTR(gsm_log, S_IRUGO, pm8001_ctl_gsm_log_show, NULL);
 #define FLASH_CMD_SET_NVMD    0x02
 
 struct flash_command {
-     u8      command[8];
+     u8      command[8] __nonstring;
      int     code;
 };
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 25 lines · Kees Cook

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.

---
 drivers/scsi/pm8001/pm8001_ctl.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/pm8001/pm8001_ctl.c +0 -0
index 85ff95c6543a..7618f9cc9986 100644
@@ -644,7 +644,7 @@ static DEVICE_ATTR(gsm_log, S_IRUGO,
 pm8001_ctl_gsm_log_show, NULL);
  #define FLASH_CMD_SET_NVMD    0x02
Quoted 4 lines


 struct flash_command {
-     u8      command[8];
+     u8      command[8] __nonstring;

This looks a bit suboptimal ... is there anywhere in the kernel u8[] is actually used for real strings? In which case it would seem the better place to put the annotation is in the typedef for u8 arrays.

Regards,

James

author
#2 lore raw
Quoted 18 lines · James Bottomley
Quoted 17 lines · Kees Cook

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.

---
 drivers/scsi/pm8001/pm8001_ctl.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 8 lines
drivers/scsi/pm8001/pm8001_ctl.c +0 -0
index 85ff95c6543a..7618f9cc9986 100644
@@ -644,7 +644,7 @@ static DEVICE_ATTR(gsm_log, S_IRUGO,
 pm8001_ctl_gsm_log_show, NULL);
  #define FLASH_CMD_SET_NVMD    0x02
Quoted 4 lines


 struct flash_command {
-     u8      command[8];
+     u8      command[8] __nonstring;

This looks a bit suboptimal ... is there anywhere in the kernel u8[] is actually used for real strings? In which case it would seem the better place to put the annotation is in the typedef for u8 arrays.

I answered this in a merged thread[1]. Can this get picked up?

Thanks!

-Kees

[1] https://lore.kernel.org/lkml/202503111520.CF7527A@keescook/

Signature · 1 line
Kees Cook
#3 lore raw

Kees,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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.

Applied to 6.16/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen