linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memremap: Replace 0-length array with flexible array
@ 2023-01-05 22:01 Kees Cook
  2023-01-05 22:14 ` Gustavo A. R. Silva
  2023-01-05 22:14 ` Dan Williams
  0 siblings, 2 replies; 8+ messages in thread
From: Kees Cook @ 2023-01-05 22:01 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Kees Cook, Dan Williams, Alex Sierra, Felix Kuehling,
	Matthew Wilcox (Oracle),
	Shiyang Ruan, Gustavo A. R. Silva, linux-mm, Alistair Popple,
	Joao Martins, Mike Rapoport, linux-kernel, linux-hardening

Zero-length arrays are deprecated[1]. Replace struct ethtool_rxnfc's
"rule_locs" 0-length array with a flexible array. Detected with GCC 13,
using -fstrict-flex-arrays=3:

In file included from include/asm-generic/memory_model.h:5,
                 from arch/x86/include/asm/page.h:86,
                 from arch/x86/include/asm/thread_info.h:12,
                 from include/linux/thread_info.h:60,
                 from arch/x86/include/asm/preempt.h:9,
                 from include/linux/preempt.h:78,
                 from include/linux/spinlock.h:56,
                 from include/linux/mmzone.h:8,
                 from include/linux/gfp.h:7,
                 from include/linux/mm.h:7,
                 from mm/sparse-vmemmap.c:21:
In function 'reuse_compound_section',
    inlined from 'vmemmap_populate_compound_pages' at mm/sparse-vmemmap.c:407:6,
    inlined from '__populate_section_memmap' at mm/sparse-vmemmap.c:463:7:
mm/sparse-vmemmap.c:376:39: warning: array subscript <unknown> is outside array bounds of 'struct range[0]' [-Warray-bounds=]
  376 |                 PHYS_PFN(pgmap->ranges[pgmap->nr_range].start);
      |                          ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
include/linux/pfn.h:22:43: note: in definition of macro 'PHYS_PFN'
   22 | #define PHYS_PFN(x)     ((unsigned long)((x) >> PAGE_SHIFT))
      |                                           ^
In file included from include/linux/mm.h:31:
include/linux/memremap.h: In function '__populate_section_memmap':
include/linux/memremap.h:138:30: note: while referencing 'ranges'
  138 |                 struct range ranges[0];
      |                              ^~~~~~

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Alex Sierra <alex.sierra@amd.com>
Cc: Felix Kuehling <Felix.Kuehling@amd.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Shiyang Ruan <ruansy.fnst@fujitsu.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-mm@kvack.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 include/linux/memremap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/memremap.h b/include/linux/memremap.h
index 7fcaf3180a5b..1314d9c5f05b 100644
--- a/include/linux/memremap.h
+++ b/include/linux/memremap.h
@@ -135,7 +135,7 @@ struct dev_pagemap {
 	int nr_range;
 	union {
 		struct range range;
-		struct range ranges[0];
+		DECLARE_FLEX_ARRAY(struct range, ranges);
 	};
 };
 
-- 
2.34.1



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

* Re: [PATCH] memremap: Replace 0-length array with flexible array
  2023-01-05 22:01 [PATCH] memremap: Replace 0-length array with flexible array Kees Cook
@ 2023-01-05 22:14 ` Gustavo A. R. Silva
  2023-01-05 22:39   ` Kees Cook
  2023-01-05 22:41   ` Kees Cook
  2023-01-05 22:14 ` Dan Williams
  1 sibling, 2 replies; 8+ messages in thread
From: Gustavo A. R. Silva @ 2023-01-05 22:14 UTC (permalink / raw)
  To: Kees Cook
  Cc: Andrew Morton, Dan Williams, Alex Sierra, Felix Kuehling,
	Matthew Wilcox (Oracle),
	Shiyang Ruan, linux-mm, Alistair Popple, Joao Martins,
	Mike Rapoport, linux-kernel, linux-hardening

I think this is the same patch:

https://lore.kernel.org/linux-hardening/YxKO%2FjY1x0xTpl4r@work/

It's actually in linux-next.

--
Gustavo

On Thu, Jan 05, 2023 at 02:01:53PM -0800, Kees Cook wrote:
> Zero-length arrays are deprecated[1]. Replace struct ethtool_rxnfc's
> "rule_locs" 0-length array with a flexible array. Detected with GCC 13,
> using -fstrict-flex-arrays=3:
> 
> In file included from include/asm-generic/memory_model.h:5,
>                  from arch/x86/include/asm/page.h:86,
>                  from arch/x86/include/asm/thread_info.h:12,
>                  from include/linux/thread_info.h:60,
>                  from arch/x86/include/asm/preempt.h:9,
>                  from include/linux/preempt.h:78,
>                  from include/linux/spinlock.h:56,
>                  from include/linux/mmzone.h:8,
>                  from include/linux/gfp.h:7,
>                  from include/linux/mm.h:7,
>                  from mm/sparse-vmemmap.c:21:
> In function 'reuse_compound_section',
>     inlined from 'vmemmap_populate_compound_pages' at mm/sparse-vmemmap.c:407:6,
>     inlined from '__populate_section_memmap' at mm/sparse-vmemmap.c:463:7:
> mm/sparse-vmemmap.c:376:39: warning: array subscript <unknown> is outside array bounds of 'struct range[0]' [-Warray-bounds=]
>   376 |                 PHYS_PFN(pgmap->ranges[pgmap->nr_range].start);
>       |                          ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
> include/linux/pfn.h:22:43: note: in definition of macro 'PHYS_PFN'
>    22 | #define PHYS_PFN(x)     ((unsigned long)((x) >> PAGE_SHIFT))
>       |                                           ^
> In file included from include/linux/mm.h:31:
> include/linux/memremap.h: In function '__populate_section_memmap':
> include/linux/memremap.h:138:30: note: while referencing 'ranges'
>   138 |                 struct range ranges[0];
>       |                              ^~~~~~
> 
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
> 
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Alex Sierra <alex.sierra@amd.com>
> Cc: Felix Kuehling <Felix.Kuehling@amd.com>
> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
> Cc: Shiyang Ruan <ruansy.fnst@fujitsu.com>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: linux-mm@kvack.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  include/linux/memremap.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/memremap.h b/include/linux/memremap.h
> index 7fcaf3180a5b..1314d9c5f05b 100644
> --- a/include/linux/memremap.h
> +++ b/include/linux/memremap.h
> @@ -135,7 +135,7 @@ struct dev_pagemap {
>  	int nr_range;
>  	union {
>  		struct range range;
> -		struct range ranges[0];
> +		DECLARE_FLEX_ARRAY(struct range, ranges);
>  	};
>  };
>  
> -- 
> 2.34.1
> 


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

* RE: [PATCH] memremap: Replace 0-length array with flexible array
  2023-01-05 22:01 [PATCH] memremap: Replace 0-length array with flexible array Kees Cook
  2023-01-05 22:14 ` Gustavo A. R. Silva
@ 2023-01-05 22:14 ` Dan Williams
  1 sibling, 0 replies; 8+ messages in thread
From: Dan Williams @ 2023-01-05 22:14 UTC (permalink / raw)
  To: Kees Cook, Andrew Morton
  Cc: Kees Cook, Dan Williams, Alex Sierra, Felix Kuehling,
	Matthew Wilcox (Oracle),
	Shiyang Ruan, Gustavo A. R. Silva, linux-mm, Alistair Popple,
	Joao Martins, Mike Rapoport, linux-kernel, linux-hardening

Kees Cook wrote:
> Zero-length arrays are deprecated[1]. Replace struct ethtool_rxnfc's
> "rule_locs" 0-length array with a flexible array. Detected with GCC 13,
> using -fstrict-flex-arrays=3:
> 
> In file included from include/asm-generic/memory_model.h:5,
>                  from arch/x86/include/asm/page.h:86,
>                  from arch/x86/include/asm/thread_info.h:12,
>                  from include/linux/thread_info.h:60,
>                  from arch/x86/include/asm/preempt.h:9,
>                  from include/linux/preempt.h:78,
>                  from include/linux/spinlock.h:56,
>                  from include/linux/mmzone.h:8,
>                  from include/linux/gfp.h:7,
>                  from include/linux/mm.h:7,
>                  from mm/sparse-vmemmap.c:21:
> In function 'reuse_compound_section',
>     inlined from 'vmemmap_populate_compound_pages' at mm/sparse-vmemmap.c:407:6,
>     inlined from '__populate_section_memmap' at mm/sparse-vmemmap.c:463:7:
> mm/sparse-vmemmap.c:376:39: warning: array subscript <unknown> is outside array bounds of 'struct range[0]' [-Warray-bounds=]
>   376 |                 PHYS_PFN(pgmap->ranges[pgmap->nr_range].start);
>       |                          ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
> include/linux/pfn.h:22:43: note: in definition of macro 'PHYS_PFN'
>    22 | #define PHYS_PFN(x)     ((unsigned long)((x) >> PAGE_SHIFT))
>       |                                           ^
> In file included from include/linux/mm.h:31:
> include/linux/memremap.h: In function '__populate_section_memmap':
> include/linux/memremap.h:138:30: note: while referencing 'ranges'
>   138 |                 struct range ranges[0];
>       |                              ^~~~~~
> 
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
> 
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Alex Sierra <alex.sierra@amd.com>
> Cc: Felix Kuehling <Felix.Kuehling@amd.com>
> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
> Cc: Shiyang Ruan <ruansy.fnst@fujitsu.com>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: linux-mm@kvack.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Looks good to me:

Reviewed-by: Dan Williams <dan.j.williams@intel.com>

> ---
>  include/linux/memremap.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/memremap.h b/include/linux/memremap.h
> index 7fcaf3180a5b..1314d9c5f05b 100644
> --- a/include/linux/memremap.h
> +++ b/include/linux/memremap.h
> @@ -135,7 +135,7 @@ struct dev_pagemap {
>  	int nr_range;
>  	union {
>  		struct range range;
> -		struct range ranges[0];
> +		DECLARE_FLEX_ARRAY(struct range, ranges);
>  	};
>  };
>  
> -- 
> 2.34.1
> 




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

* Re: [PATCH] memremap: Replace 0-length array with flexible array
  2023-01-05 22:14 ` Gustavo A. R. Silva
@ 2023-01-05 22:39   ` Kees Cook
  2023-01-05 22:41   ` Kees Cook
  1 sibling, 0 replies; 8+ messages in thread
From: Kees Cook @ 2023-01-05 22:39 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Andrew Morton, Dan Williams, Alex Sierra, Felix Kuehling,
	Matthew Wilcox (Oracle),
	Shiyang Ruan, linux-mm, Alistair Popple, Joao Martins,
	Mike Rapoport, linux-kernel, linux-hardening

On Thu, Jan 05, 2023 at 04:14:05PM -0600, Gustavo A. R. Silva wrote:
> I think this is the same patch:
> 
> https://lore.kernel.org/linux-hardening/YxKO%2FjY1x0xTpl4r@work/
> 
> It's actually in linux-next.

Ah-ha! Thank you! I'll move to linux-next for build testing.

-- 
Kees Cook


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

* Re: [PATCH] memremap: Replace 0-length array with flexible array
  2023-01-05 22:14 ` Gustavo A. R. Silva
  2023-01-05 22:39   ` Kees Cook
@ 2023-01-05 22:41   ` Kees Cook
  2023-01-05 23:14     ` Gustavo A. R. Silva
  1 sibling, 1 reply; 8+ messages in thread
From: Kees Cook @ 2023-01-05 22:41 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Andrew Morton, Dan Williams, Alex Sierra, Felix Kuehling,
	Matthew Wilcox (Oracle),
	Shiyang Ruan, linux-mm, Alistair Popple, Joao Martins,
	Mike Rapoport, linux-kernel, linux-hardening

On Thu, Jan 05, 2023 at 04:14:05PM -0600, Gustavo A. R. Silva wrote:
> I think this is the same patch:
> 
> https://lore.kernel.org/linux-hardening/YxKO%2FjY1x0xTpl4r@work/
> 
> It's actually in linux-next.

Hm, it's been in -next since September? Is this in a tree of yours that
didn't get pulled for v6.2?

-- 
Kees Cook


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

* Re: [PATCH] memremap: Replace 0-length array with flexible array
  2023-01-05 22:41   ` Kees Cook
@ 2023-01-05 23:14     ` Gustavo A. R. Silva
  2023-01-05 23:37       ` Kees Cook
  0 siblings, 1 reply; 8+ messages in thread
From: Gustavo A. R. Silva @ 2023-01-05 23:14 UTC (permalink / raw)
  To: Kees Cook, Gustavo A. R. Silva
  Cc: Andrew Morton, Dan Williams, Alex Sierra, Felix Kuehling,
	Matthew Wilcox (Oracle),
	Shiyang Ruan, linux-mm, Alistair Popple, Joao Martins,
	Mike Rapoport, linux-kernel, linux-hardening



On 1/5/23 16:41, Kees Cook wrote:
> On Thu, Jan 05, 2023 at 04:14:05PM -0600, Gustavo A. R. Silva wrote:
>> I think this is the same patch:
>>
>> https://lore.kernel.org/linux-hardening/YxKO%2FjY1x0xTpl4r@work/
>>
>> It's actually in linux-next.
> 
> Hm, it's been in -next since September? Is this in a tree of yours that
> didn't get pulled for v6.2?

No. I didn't send it. It's just one of the two patches I have in my -next
tree. They didn't look like high priority at the time.

--
Gustavo


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

* Re: [PATCH] memremap: Replace 0-length array with flexible array
  2023-01-05 23:14     ` Gustavo A. R. Silva
@ 2023-01-05 23:37       ` Kees Cook
  2023-01-06  0:02         ` Gustavo A. R. Silva
  0 siblings, 1 reply; 8+ messages in thread
From: Kees Cook @ 2023-01-05 23:37 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Gustavo A. R. Silva, Andrew Morton, Dan Williams, Alex Sierra,
	Felix Kuehling, Matthew Wilcox (Oracle),
	Shiyang Ruan, linux-mm, Alistair Popple, Joao Martins,
	Mike Rapoport, linux-kernel, linux-hardening

On Thu, Jan 05, 2023 at 05:14:23PM -0600, Gustavo A. R. Silva wrote:
> 
> 
> On 1/5/23 16:41, Kees Cook wrote:
> > On Thu, Jan 05, 2023 at 04:14:05PM -0600, Gustavo A. R. Silva wrote:
> > > I think this is the same patch:
> > > 
> > > https://lore.kernel.org/linux-hardening/YxKO%2FjY1x0xTpl4r@work/
> > > 
> > > It's actually in linux-next.
> > 
> > Hm, it's been in -next since September? Is this in a tree of yours that
> > didn't get pulled for v6.2?
> 
> No. I didn't send it. It's just one of the two patches I have in my -next
> tree. They didn't look like high priority at the time.

Cool. I'd like to get -fstrict-flex-arrays=3 finished this devel cycle,
if possible. Can you add this one too?

https://lore.kernel.org/lkml/YzIc8z+QaHvqPjLX@work

I don't see it in patchwork which I find confusing too. :P

-- 
Kees Cook


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

* Re: [PATCH] memremap: Replace 0-length array with flexible array
  2023-01-05 23:37       ` Kees Cook
@ 2023-01-06  0:02         ` Gustavo A. R. Silva
  0 siblings, 0 replies; 8+ messages in thread
From: Gustavo A. R. Silva @ 2023-01-06  0:02 UTC (permalink / raw)
  To: Kees Cook
  Cc: Gustavo A. R. Silva, Andrew Morton, Dan Williams, Alex Sierra,
	Felix Kuehling, Matthew Wilcox (Oracle),
	Shiyang Ruan, linux-mm, Alistair Popple, Joao Martins,
	Mike Rapoport, linux-kernel, linux-hardening

On Thu, Jan 05, 2023 at 03:37:03PM -0800, Kees Cook wrote:
> On Thu, Jan 05, 2023 at 05:14:23PM -0600, Gustavo A. R. Silva wrote:
> > 
> > 
> > On 1/5/23 16:41, Kees Cook wrote:
> > > On Thu, Jan 05, 2023 at 04:14:05PM -0600, Gustavo A. R. Silva wrote:
> > > > I think this is the same patch:
> > > > 
> > > > https://lore.kernel.org/linux-hardening/YxKO%2FjY1x0xTpl4r@work/
> > > > 
> > > > It's actually in linux-next.
> > > 
> > > Hm, it's been in -next since September? Is this in a tree of yours that
> > > didn't get pulled for v6.2?
> > 
> > No. I didn't send it. It's just one of the two patches I have in my -next
> > tree. They didn't look like high priority at the time.
> 
> Cool. I'd like to get -fstrict-flex-arrays=3 finished this devel cycle,
> if possible. Can you add this one too?
> 
> https://lore.kernel.org/lkml/YzIc8z+QaHvqPjLX@work

Done!

https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git/log/?h=for-next/kspp

> 
> I don't see it in patchwork which I find confusing too. :P

mmh... and I don't remember updating it in patchwork before.
(thinkingface)

--
Gustavo


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

end of thread, other threads:[~2023-01-06  0:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-05 22:01 [PATCH] memremap: Replace 0-length array with flexible array Kees Cook
2023-01-05 22:14 ` Gustavo A. R. Silva
2023-01-05 22:39   ` Kees Cook
2023-01-05 22:41   ` Kees Cook
2023-01-05 23:14     ` Gustavo A. R. Silva
2023-01-05 23:37       ` Kees Cook
2023-01-06  0:02         ` Gustavo A. R. Silva
2023-01-05 22:14 ` Dan Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox