* [PATCH] scsi: pm80xx: Add __nonstring annotations for unterminated strings
@ 2025-03-10 22:25 Kees Cook
2025-03-10 22:38 ` James Bottomley
0 siblings, 1 reply; 4+ messages in thread
From: Kees Cook @ 2025-03-10 22:25 UTC (permalink / raw)
To: Jack Wang
Cc: Kees Cook, James E.J. Bottomley, Martin K. Petersen, linux-scsi,
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: Jack Wang <jinpu.wang@cloud.ionos.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>
---
drivers/scsi/pm8001/pm8001_ctl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/pm8001/pm8001_ctl.c b/drivers/scsi/pm8001/pm8001_ctl.c
index 85ff95c6543a..7618f9cc9986 100644
--- a/drivers/scsi/pm8001/pm8001_ctl.c
+++ b/drivers/scsi/pm8001/pm8001_ctl.c
@@ -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;
};
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] scsi: pm80xx: Add __nonstring annotations for unterminated strings
2025-03-10 22:25 [PATCH] scsi: pm80xx: Add __nonstring annotations for unterminated strings Kees Cook
@ 2025-03-10 22:38 ` James Bottomley
2025-04-07 18:37 ` Kees Cook
0 siblings, 1 reply; 4+ messages in thread
From: James Bottomley @ 2025-03-10 22:38 UTC (permalink / raw)
To: Kees Cook, Jack Wang
Cc: Martin K. Petersen, linux-scsi, linux-kernel, linux-hardening
On Mon, 2025-03-10 at 15:25 -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: Jack Wang <jinpu.wang@cloud.ionos.com>
> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
> Cc: linux-scsi@vger.kernel.org
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
> drivers/scsi/pm8001/pm8001_ctl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/pm8001/pm8001_ctl.c
> b/drivers/scsi/pm8001/pm8001_ctl.c
> index 85ff95c6543a..7618f9cc9986 100644
> --- a/drivers/scsi/pm8001/pm8001_ctl.c
> +++ b/drivers/scsi/pm8001/pm8001_ctl.c
> @@ -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;
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] scsi: pm80xx: Add __nonstring annotations for unterminated strings
2025-03-10 22:38 ` James Bottomley
@ 2025-04-07 18:37 ` Kees Cook
2025-04-12 1:55 ` Martin K. Petersen
0 siblings, 1 reply; 4+ messages in thread
From: Kees Cook @ 2025-04-07 18:37 UTC (permalink / raw)
To: James Bottomley
Cc: Jack Wang, Martin K. Petersen, linux-scsi, linux-kernel,
linux-hardening
On Mon, Mar 10, 2025 at 06:38:01PM -0400, James Bottomley wrote:
> On Mon, 2025-03-10 at 15:25 -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: Jack Wang <jinpu.wang@cloud.ionos.com>
> > Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
> > Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
> > Cc: linux-scsi@vger.kernel.org
> > Signed-off-by: Kees Cook <kees@kernel.org>
> > ---
> > drivers/scsi/pm8001/pm8001_ctl.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/scsi/pm8001/pm8001_ctl.c
> > b/drivers/scsi/pm8001/pm8001_ctl.c
> > index 85ff95c6543a..7618f9cc9986 100644
> > --- a/drivers/scsi/pm8001/pm8001_ctl.c
> > +++ b/drivers/scsi/pm8001/pm8001_ctl.c
> > @@ -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;
>
> 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/
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] scsi: pm80xx: Add __nonstring annotations for unterminated strings
2025-04-07 18:37 ` Kees Cook
@ 2025-04-12 1:55 ` Martin K. Petersen
0 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2025-04-12 1:55 UTC (permalink / raw)
To: Kees Cook
Cc: James Bottomley, Jack Wang, Martin K. Petersen, linux-scsi,
linux-kernel, linux-hardening
Kees,
>> > 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!
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-12 1:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-10 22:25 [PATCH] scsi: pm80xx: Add __nonstring annotations for unterminated strings Kees Cook
2025-03-10 22:38 ` James Bottomley
2025-04-07 18:37 ` Kees Cook
2025-04-12 1:55 ` Martin K. Petersen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox