linux-bcache.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] md/bcache: Mark __nonstring look-up table
@ 2025-04-18 20:21 Kees Cook
  2025-04-19  3:55 ` Coly Li
  0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2025-04-18 20:21 UTC (permalink / raw)
  To: Coly Li
  Cc: Kees Cook, Kent Overstreet, Ard Biesheuvel, linux-bcache,
	linux-kernel, linux-hardening

GCC 15's new -Wunterminated-string-initialization notices that the 16
character lookup table "zero_uuid" (which is not used as a C-String)
needs to be marked as "nonstring":

drivers/md/bcache/super.c: In function 'uuid_find_empty':
drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]
  549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add the annotation (since it is not used as a C-String), and switch the
initializer to an array of bytes.

Signed-off-by: Kees Cook <kees@kernel.org>
---
 v2: use byte array initializer (colyli)
 v1: https://lore.kernel.org/all/20250416220135.work.394-kees@kernel.org/
Cc: Coly Li <colyli@kernel.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: linux-bcache@vger.kernel.org
---
 drivers/md/bcache/super.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index e42f1400cea9..a76ce92502ed 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -546,7 +546,8 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
 
 static struct uuid_entry *uuid_find_empty(struct cache_set *c)
 {
-	static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+	static const char zero_uuid[] __nonstring =
+		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 
 	return uuid_find(c, zero_uuid);
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] md/bcache: Mark __nonstring look-up table
  2025-04-18 20:21 [PATCH v2] md/bcache: Mark __nonstring look-up table Kees Cook
@ 2025-04-19  3:55 ` Coly Li
  2025-05-08  3:01   ` Coly Li
  0 siblings, 1 reply; 5+ messages in thread
From: Coly Li @ 2025-04-19  3:55 UTC (permalink / raw)
  To: Kees Cook
  Cc: Coly Li, Kent Overstreet, Ard Biesheuvel, linux-bcache,
	linux-kernel, linux-hardening



> 2025年4月19日 04:21,Kees Cook <kees@kernel.org> 写道:
> 
> GCC 15's new -Wunterminated-string-initialization notices that the 16
> character lookup table "zero_uuid" (which is not used as a C-String)
> needs to be marked as "nonstring":
> 
> drivers/md/bcache/super.c: In function 'uuid_find_empty':
> drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]
>  549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
>      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Add the annotation (since it is not used as a C-String), and switch the
> initializer to an array of bytes.
> 
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
> v2: use byte array initializer (colyli)
> v1: https://lore.kernel.org/all/20250416220135.work.394-kees@kernel.org/
> Cc: Coly Li <colyli@kernel.org>
> Cc: Kent Overstreet <kent.overstreet@linux.dev>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: linux-bcache@vger.kernel.org
> ---
> drivers/md/bcache/super.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index e42f1400cea9..a76ce92502ed 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -546,7 +546,8 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
> 
> static struct uuid_entry *uuid_find_empty(struct cache_set *c)
> {
> - static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
> + static const char zero_uuid[] __nonstring =

I notice zero_uuid[16] changes to zero_uuid[], then the element number information is removed.

Is it OK for GCC 15 to only add __nonstring and keep zero_uuid[16]?

Thanks.

Coly Li 


> + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
> 
> return uuid_find(c, zero_uuid);
> }
> -- 
> 2.34.1
> 
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] md/bcache: Mark __nonstring look-up table
  2025-04-19  3:55 ` Coly Li
@ 2025-05-08  3:01   ` Coly Li
  2025-05-08 15:58     ` Kees Cook
  0 siblings, 1 reply; 5+ messages in thread
From: Coly Li @ 2025-05-08  3:01 UTC (permalink / raw)
  To: Kees Cook
  Cc: Coly Li, Kent Overstreet, Ard Biesheuvel, linux-bcache,
	linux-kernel, linux-hardening



> 2025年4月19日 11:55,Coly Li <i@coly.li> 写道:
> 
> 
> 
>> 2025年4月19日 04:21,Kees Cook <kees@kernel.org> 写道:
>> 
>> GCC 15's new -Wunterminated-string-initialization notices that the 16
>> character lookup table "zero_uuid" (which is not used as a C-String)
>> needs to be marked as "nonstring":
>> 
>> drivers/md/bcache/super.c: In function 'uuid_find_empty':
>> drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]
>> 549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
>>     |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> 
>> Add the annotation (since it is not used as a C-String), and switch the
>> initializer to an array of bytes.
>> 
>> Signed-off-by: Kees Cook <kees@kernel.org>
>> ---
>> v2: use byte array initializer (colyli)
>> v1: https://lore.kernel.org/all/20250416220135.work.394-kees@kernel.org/
>> Cc: Coly Li <colyli@kernel.org>
>> Cc: Kent Overstreet <kent.overstreet@linux.dev>
>> Cc: Ard Biesheuvel <ardb@kernel.org>
>> Cc: linux-bcache@vger.kernel.org
>> ---
>> drivers/md/bcache/super.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>> 
>> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
>> index e42f1400cea9..a76ce92502ed 100644
>> --- a/drivers/md/bcache/super.c
>> +++ b/drivers/md/bcache/super.c
>> @@ -546,7 +546,8 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
>> 
>> static struct uuid_entry *uuid_find_empty(struct cache_set *c)
>> {
>> - static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
>> + static const char zero_uuid[] __nonstring =
> 

Hi Kees,

> I notice zero_uuid[16] changes to zero_uuid[], then the element number information is removed.
> 
> Is it OK for GCC 15 to only add __nonstring and keep zero_uuid[16]?

Ping ?

You are expert here, I need your opinion.

Thanks.

Coly Li



>> + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
>> 
>> return uuid_find(c, zero_uuid);
>> }
>> -- 
>> 2.34.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] md/bcache: Mark __nonstring look-up table
  2025-05-08  3:01   ` Coly Li
@ 2025-05-08 15:58     ` Kees Cook
  2025-05-08 15:59       ` Coly Li
  0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2025-05-08 15:58 UTC (permalink / raw)
  To: Coly Li
  Cc: Coly Li, Kent Overstreet, Ard Biesheuvel, linux-bcache,
	linux-kernel, linux-hardening

On Thu, May 08, 2025 at 11:01:34AM +0800, Coly Li wrote:
> 
> > 2025年4月19日 11:55,Coly Li <i@coly.li> 写道:
> > 
> > 
> > 
> >> 2025年4月19日 04:21,Kees Cook <kees@kernel.org> 写道:
> >> 
> >> GCC 15's new -Wunterminated-string-initialization notices that the 16
> >> character lookup table "zero_uuid" (which is not used as a C-String)
> >> needs to be marked as "nonstring":
> >> 
> >> drivers/md/bcache/super.c: In function 'uuid_find_empty':
> >> drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]
> >> 549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
> >>     |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> 
> >> Add the annotation (since it is not used as a C-String), and switch the
> >> initializer to an array of bytes.
> >> 
> >> Signed-off-by: Kees Cook <kees@kernel.org>
> >> ---
> >> v2: use byte array initializer (colyli)
> >> v1: https://lore.kernel.org/all/20250416220135.work.394-kees@kernel.org/
> >> Cc: Coly Li <colyli@kernel.org>
> >> Cc: Kent Overstreet <kent.overstreet@linux.dev>
> >> Cc: Ard Biesheuvel <ardb@kernel.org>
> >> Cc: linux-bcache@vger.kernel.org
> >> ---
> >> drivers/md/bcache/super.c | 3 ++-
> >> 1 file changed, 2 insertions(+), 1 deletion(-)
> >> 
> >> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> >> index e42f1400cea9..a76ce92502ed 100644
> >> --- a/drivers/md/bcache/super.c
> >> +++ b/drivers/md/bcache/super.c
> >> @@ -546,7 +546,8 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
> >> 
> >> static struct uuid_entry *uuid_find_empty(struct cache_set *c)
> >> {
> >> - static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
> >> + static const char zero_uuid[] __nonstring =
> > 
> 
> Hi Kees,
> 
> > I notice zero_uuid[16] changes to zero_uuid[], then the element number information is removed.
> > 
> > Is it OK for GCC 15 to only add __nonstring and keep zero_uuid[16]?

Either way is fine. I can update the patch to use the "[16]" again if
you'd like?

-Kees

> Ping ?
> 
> You are expert here, I need your opinion.
> 
> Thanks.
> 
> Coly Li
> 
> 
> 
> >> + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
> >> 
> >> return uuid_find(c, zero_uuid);
> >> }
> >> -- 
> >> 2.34.1
> 
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] md/bcache: Mark __nonstring look-up table
  2025-05-08 15:58     ` Kees Cook
@ 2025-05-08 15:59       ` Coly Li
  0 siblings, 0 replies; 5+ messages in thread
From: Coly Li @ 2025-05-08 15:59 UTC (permalink / raw)
  To: Kees Cook
  Cc: Coly Li, Kent Overstreet, Ard Biesheuvel, linux-bcache,
	linux-kernel, linux-hardening



> 2025年5月8日 23:58,Kees Cook <kees@kernel.org> 写道:
> 
> On Thu, May 08, 2025 at 11:01:34AM +0800, Coly Li wrote:
>> 
>>> 2025年4月19日 11:55,Coly Li <i@coly.li> 写道:
>>> 
>>> 
>>> 
>>>> 2025年4月19日 04:21,Kees Cook <kees@kernel.org> 写道:
>>>> 
>>>> GCC 15's new -Wunterminated-string-initialization notices that the 16
>>>> character lookup table "zero_uuid" (which is not used as a C-String)
>>>> needs to be marked as "nonstring":
>>>> 
>>>> drivers/md/bcache/super.c: In function 'uuid_find_empty':
>>>> drivers/md/bcache/super.c:549:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Wunterminated-string-initialization]
>>>> 549 |         static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
>>>>    |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>> 
>>>> Add the annotation (since it is not used as a C-String), and switch the
>>>> initializer to an array of bytes.
>>>> 
>>>> Signed-off-by: Kees Cook <kees@kernel.org>
>>>> ---
>>>> v2: use byte array initializer (colyli)
>>>> v1: https://lore.kernel.org/all/20250416220135.work.394-kees@kernel.org/
>>>> Cc: Coly Li <colyli@kernel.org>
>>>> Cc: Kent Overstreet <kent.overstreet@linux.dev>
>>>> Cc: Ard Biesheuvel <ardb@kernel.org>
>>>> Cc: linux-bcache@vger.kernel.org
>>>> ---
>>>> drivers/md/bcache/super.c | 3 ++-
>>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>>> 
>>>> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
>>>> index e42f1400cea9..a76ce92502ed 100644
>>>> --- a/drivers/md/bcache/super.c
>>>> +++ b/drivers/md/bcache/super.c
>>>> @@ -546,7 +546,8 @@ static struct uuid_entry *uuid_find(struct cache_set *c, const char *uuid)
>>>> 
>>>> static struct uuid_entry *uuid_find_empty(struct cache_set *c)
>>>> {
>>>> - static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
>>>> + static const char zero_uuid[] __nonstring =
>>> 
>> 
>> Hi Kees,
>> 
>>> I notice zero_uuid[16] changes to zero_uuid[], then the element number information is removed.
>>> 
>>> Is it OK for GCC 15 to only add __nonstring and keep zero_uuid[16]?
> 
> Either way is fine. I can update the patch to use the "[16]" again if
> you'd like?
> 

Yes please. Thanks in advance.

Coly Li


> 
>> Ping ?
>> 
>> You are expert here, I need your opinion.
>> 
>> Thanks.
>> 
>> Coly Li
>> 
>> 
>> 
>>>> + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
>>>> 
>>>> return uuid_find(c, zero_uuid);
>>>> }
>>>> -- 
>>>> 2.34.1
>> 
>> 
> 
> -- 
> Kees Cook


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-05-08 19:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-18 20:21 [PATCH v2] md/bcache: Mark __nonstring look-up table Kees Cook
2025-04-19  3:55 ` Coly Li
2025-05-08  3:01   ` Coly Li
2025-05-08 15:58     ` Kees Cook
2025-05-08 15:59       ` Coly Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).