* [PATCH] md/bcache: Mark __nonstring look-up table @ 2025-04-16 22:01 Kees Cook 2025-04-17 4:13 ` Coly Li 2025-04-17 6:16 ` Ard Biesheuvel 0 siblings, 2 replies; 7+ messages in thread From: Kees Cook @ 2025-04-16 22:01 UTC (permalink / raw) To: Coly Li Cc: Kees Cook, Kent Overstreet, 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 to silence the GCC warning. Signed-off-by: Kees Cook <kees@kernel.org> --- Cc: Coly Li <colyli@kernel.org> Cc: Kent Overstreet <kent.overstreet@linux.dev> Cc: linux-bcache@vger.kernel.org --- drivers/md/bcache/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index e42f1400cea9..577d048170fe 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -546,7 +546,7 @@ 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] 7+ messages in thread
* Re: [PATCH] md/bcache: Mark __nonstring look-up table 2025-04-16 22:01 [PATCH] md/bcache: Mark __nonstring look-up table Kees Cook @ 2025-04-17 4:13 ` Coly Li 2025-04-17 6:16 ` Ard Biesheuvel 1 sibling, 0 replies; 7+ messages in thread From: Coly Li @ 2025-04-17 4:13 UTC (permalink / raw) To: Kees Cook Cc: Coly Li, Kent Overstreet, linux-bcache, linux-kernel, linux-hardening > 2025年4月17日 06:01,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 to silence the GCC warning. > > Signed-off-by: Kees Cook <kees@kernel.org> > --- > Cc: Coly Li <colyli@kernel.org> > Cc: Kent Overstreet <kent.overstreet@linux.dev> > Cc: linux-bcache@vger.kernel.org <mailto:linux-bcache@vger.kernel.org> It looks good to me. Thanks for the fix up. Coly Li > --- > drivers/md/bcache/super.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c > index e42f1400cea9..577d048170fe 100644 > --- a/drivers/md/bcache/super.c > +++ b/drivers/md/bcache/super.c > @@ -546,7 +546,7 @@ 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 [flat|nested] 7+ messages in thread
* Re: [PATCH] md/bcache: Mark __nonstring look-up table 2025-04-16 22:01 [PATCH] md/bcache: Mark __nonstring look-up table Kees Cook 2025-04-17 4:13 ` Coly Li @ 2025-04-17 6:16 ` Ard Biesheuvel 2025-04-17 7:10 ` Kees Cook 1 sibling, 1 reply; 7+ messages in thread From: Ard Biesheuvel @ 2025-04-17 6:16 UTC (permalink / raw) To: Kees Cook Cc: Coly Li, Kent Overstreet, linux-bcache, linux-kernel, linux-hardening On Thu, 17 Apr 2025 at 00:01, Kees Cook <kees@kernel.org> wrote: > > 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 to silence the GCC warning. > > Signed-off-by: Kees Cook <kees@kernel.org> > --- > Cc: Coly Li <colyli@kernel.org> > Cc: Kent Overstreet <kent.overstreet@linux.dev> > Cc: linux-bcache@vger.kernel.org > --- > drivers/md/bcache/super.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c > index e42f1400cea9..577d048170fe 100644 > --- a/drivers/md/bcache/super.c > +++ b/drivers/md/bcache/super.c > @@ -546,7 +546,7 @@ 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"; > Just static const char zero_uuid[16] = {}; should work fine here too. No need for the initializer. > return uuid_find(c, zero_uuid); > } > -- > 2.34.1 > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] md/bcache: Mark __nonstring look-up table 2025-04-17 6:16 ` Ard Biesheuvel @ 2025-04-17 7:10 ` Kees Cook 2025-04-17 13:11 ` Coly Li 0 siblings, 1 reply; 7+ messages in thread From: Kees Cook @ 2025-04-17 7:10 UTC (permalink / raw) To: Ard Biesheuvel Cc: Coly Li, Kent Overstreet, linux-bcache, linux-kernel, linux-hardening On April 16, 2025 11:16:45 PM PDT, Ard Biesheuvel <ardb@kernel.org> wrote: >On Thu, 17 Apr 2025 at 00:01, Kees Cook <kees@kernel.org> wrote: >> >> 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 to silence the GCC warning. >> >> Signed-off-by: Kees Cook <kees@kernel.org> >> --- >> Cc: Coly Li <colyli@kernel.org> >> Cc: Kent Overstreet <kent.overstreet@linux.dev> >> Cc: linux-bcache@vger.kernel.org >> --- >> drivers/md/bcache/super.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c >> index e42f1400cea9..577d048170fe 100644 >> --- a/drivers/md/bcache/super.c >> +++ b/drivers/md/bcache/super.c >> @@ -546,7 +546,7 @@ 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"; >> > >Just > >static const char zero_uuid[16] = {}; > >should work fine here too. No need for the initializer. 🤦 Yes. This is what I get for fixing dozens of these. I'll send a v2... -Kees -- Kees Cook ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] md/bcache: Mark __nonstring look-up table 2025-04-17 7:10 ` Kees Cook @ 2025-04-17 13:11 ` Coly Li 2025-04-17 14:08 ` Ard Biesheuvel 0 siblings, 1 reply; 7+ messages in thread From: Coly Li @ 2025-04-17 13:11 UTC (permalink / raw) To: Kees Cook Cc: Ard Biesheuvel, Coly Li, Kent Overstreet, linux-bcache, linux-kernel, linux-hardening > 2025年4月17日 15:10,Kees Cook <kees@kernel.org> 写道: > > > > On April 16, 2025 11:16:45 PM PDT, Ard Biesheuvel <ardb@kernel.org> wrote: >> On Thu, 17 Apr 2025 at 00:01, Kees Cook <kees@kernel.org> wrote: >>> >>> 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 to silence the GCC warning. >>> >>> Signed-off-by: Kees Cook <kees@kernel.org> >>> --- >>> Cc: Coly Li <colyli@kernel.org> >>> Cc: Kent Overstreet <kent.overstreet@linux.dev> >>> Cc: linux-bcache@vger.kernel.org >>> --- >>> drivers/md/bcache/super.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c >>> index e42f1400cea9..577d048170fe 100644 >>> --- a/drivers/md/bcache/super.c >>> +++ b/drivers/md/bcache/super.c >>> @@ -546,7 +546,7 @@ 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"; >>> >> >> Just >> >> static const char zero_uuid[16] = {}; >> >> should work fine here too. No need for the initializer. > > 🤦 Yes. This is what I get for fixing dozens of these. I'll send a v2... Can we do this, static const char zero_uuid[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; I like the explicit array element number 16, and the explicit uuid content by obvious zero (‘0’) symbols. They provide redundant information. Not sure whether GCC 15 complains or not. Thanks. Coly Li ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] md/bcache: Mark __nonstring look-up table 2025-04-17 13:11 ` Coly Li @ 2025-04-17 14:08 ` Ard Biesheuvel 2025-04-17 14:17 ` Coly Li 0 siblings, 1 reply; 7+ messages in thread From: Ard Biesheuvel @ 2025-04-17 14:08 UTC (permalink / raw) To: Coly Li Cc: Kees Cook, Coly Li, Kent Overstreet, linux-bcache, linux-kernel, linux-hardening On Thu, 17 Apr 2025 at 15:12, Coly Li <i@coly.li> wrote: > > > > > 2025年4月17日 15:10,Kees Cook <kees@kernel.org> 写道: > > > > > > > > On April 16, 2025 11:16:45 PM PDT, Ard Biesheuvel <ardb@kernel.org> wrote: > >> On Thu, 17 Apr 2025 at 00:01, Kees Cook <kees@kernel.org> wrote: > >>> > >>> 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 to silence the GCC warning. > >>> > >>> Signed-off-by: Kees Cook <kees@kernel.org> > >>> --- > >>> Cc: Coly Li <colyli@kernel.org> > >>> Cc: Kent Overstreet <kent.overstreet@linux.dev> > >>> Cc: linux-bcache@vger.kernel.org > >>> --- > >>> drivers/md/bcache/super.c | 2 +- > >>> 1 file changed, 1 insertion(+), 1 deletion(-) > >>> > >>> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c > >>> index e42f1400cea9..577d048170fe 100644 > >>> --- a/drivers/md/bcache/super.c > >>> +++ b/drivers/md/bcache/super.c > >>> @@ -546,7 +546,7 @@ 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"; > >>> > >> > >> Just > >> > >> static const char zero_uuid[16] = {}; > >> > >> should work fine here too. No need for the initializer. > > > > 🤦 Yes. This is what I get for fixing dozens of these. I'll send a v2... > > > Can we do this, > > static const char zero_uuid[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; > > I like the explicit array element number 16, and the explicit uuid content by obvious zero (‘0’) symbols. They provide redundant information. > Not sure whether GCC 15 complains or not. > Even the {} initializer is entirely redundant, given that the variable has static linkage, and so C guarantees that it will be zero initialized. Could you use NULL_GUID and be done with it? ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] md/bcache: Mark __nonstring look-up table 2025-04-17 14:08 ` Ard Biesheuvel @ 2025-04-17 14:17 ` Coly Li 0 siblings, 0 replies; 7+ messages in thread From: Coly Li @ 2025-04-17 14:17 UTC (permalink / raw) To: Ard Biesheuvel, Kent Overstreet Cc: Kees Cook, Coly Li, linux-bcache, linux-kernel, linux-hardening > 2025年4月17日 22:08,Ard Biesheuvel <ardb@kernel.org> 写道: > > On Thu, 17 Apr 2025 at 15:12, Coly Li <i@coly.li> wrote: >> >> >> >>> 2025年4月17日 15:10,Kees Cook <kees@kernel.org> 写道: >>> >>> >>> >>> On April 16, 2025 11:16:45 PM PDT, Ard Biesheuvel <ardb@kernel.org> wrote: >>>> On Thu, 17 Apr 2025 at 00:01, Kees Cook <kees@kernel.org> wrote: >>>>> >>>>> 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 to silence the GCC warning. >>>>> >>>>> Signed-off-by: Kees Cook <kees@kernel.org> >>>>> --- >>>>> Cc: Coly Li <colyli@kernel.org> >>>>> Cc: Kent Overstreet <kent.overstreet@linux.dev> >>>>> Cc: linux-bcache@vger.kernel.org >>>>> --- >>>>> drivers/md/bcache/super.c | 2 +- >>>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>>> >>>>> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c >>>>> index e42f1400cea9..577d048170fe 100644 >>>>> --- a/drivers/md/bcache/super.c >>>>> +++ b/drivers/md/bcache/super.c >>>>> @@ -546,7 +546,7 @@ 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"; >>>>> >>>> >>>> Just >>>> >>>> static const char zero_uuid[16] = {}; >>>> >>>> should work fine here too. No need for the initializer. >>> >>> 🤦 Yes. This is what I get for fixing dozens of these. I'll send a v2... >> >> >> Can we do this, >> >> static const char zero_uuid[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; >> >> I like the explicit array element number 16, and the explicit uuid content by obvious zero (‘0’) symbols. They provide redundant information. >> Not sure whether GCC 15 complains or not. >> > > Even the {} initializer is entirely redundant, given that the variable > has static linkage, and so C guarantees that it will be zero > initialized. > > Could you use NULL_GUID and be done with it? I feel the “static” here is an optimization to avoid initializing zero_uuid again …. Kent, Am I right? Coly Li ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-04-17 16:50 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-04-16 22:01 [PATCH] md/bcache: Mark __nonstring look-up table Kees Cook 2025-04-17 4:13 ` Coly Li 2025-04-17 6:16 ` Ard Biesheuvel 2025-04-17 7:10 ` Kees Cook 2025-04-17 13:11 ` Coly Li 2025-04-17 14:08 ` Ard Biesheuvel 2025-04-17 14:17 ` 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).