linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hugetlb/cgroup: Fix copy/paste array assignment
@ 2021-12-03  6:56 Kees Cook
  2021-12-03  7:43 ` Muchun Song
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Kees Cook @ 2021-12-03  6:56 UTC (permalink / raw)
  To: Mina Almasry
  Cc: Kees Cook, Andrew Morton, Shakeel Butt, Muchun Song,
	Mike Kravetz, linux-kernel, linux-mm, linux-hardening

Fix mismatched array assignment, reported by an -Warray-bounds build:

mm/hugetlb_cgroup.c: In function '__hugetlb_cgroup_file_legacy_init':
mm/hugetlb_cgroup.c:850:35: error: array subscript 8 is above array bounds of 'struct cftype[8]' [-Werror=array-bounds ]
  850 |         cft = &h->cgroup_files_dfl[8];
      |                ~~~~~~~~~~~~~~~~~~~^~~
In file included from mm/hugetlb_cgroup.c:23:
./include/linux/hugetlb.h:625:23: note: while referencing 'cgroup_files_dfl'
  625 |         struct cftype cgroup_files_dfl[8];
      |                       ^~~~~~~~~~~~~~~~

Fixes: e45f4726bcad ("hugetlb: add hugetlb.*.numa_stat file")
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 mm/hugetlb_cgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
index 9eebe8df3c39..f9942841df18 100644
--- a/mm/hugetlb_cgroup.c
+++ b/mm/hugetlb_cgroup.c
@@ -847,7 +847,7 @@ static void __init __hugetlb_cgroup_file_legacy_init(int idx)
 	cft->read_u64 = hugetlb_cgroup_read_u64;
 
 	/* Add the numa stat file */
-	cft = &h->cgroup_files_dfl[8];
+	cft = &h->cgroup_files_legacy[8];
 	snprintf(cft->name, MAX_CFTYPE_NAME, "%s.numa_stat", buf);
 	cft->private = MEMFILE_PRIVATE(idx, 1);
 	cft->seq_show = hugetlb_cgroup_read_numa_stat;
-- 
2.30.2



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

* Re: [PATCH] hugetlb/cgroup: Fix copy/paste array assignment
  2021-12-03  6:56 [PATCH] hugetlb/cgroup: Fix copy/paste array assignment Kees Cook
@ 2021-12-03  7:43 ` Muchun Song
  2021-12-03 19:15 ` Mike Kravetz
  2021-12-07  1:54 ` Mina Almasry
  2 siblings, 0 replies; 4+ messages in thread
From: Muchun Song @ 2021-12-03  7:43 UTC (permalink / raw)
  To: Kees Cook
  Cc: Mina Almasry, Andrew Morton, Shakeel Butt, Mike Kravetz, LKML,
	Linux Memory Management List, linux-hardening

On Fri, Dec 3, 2021 at 2:56 PM Kees Cook <keescook@chromium.org> wrote:
>
> Fix mismatched array assignment, reported by an -Warray-bounds build:
>
> mm/hugetlb_cgroup.c: In function '__hugetlb_cgroup_file_legacy_init':
> mm/hugetlb_cgroup.c:850:35: error: array subscript 8 is above array bounds of 'struct cftype[8]' [-Werror=array-bounds ]
>   850 |         cft = &h->cgroup_files_dfl[8];
>       |                ~~~~~~~~~~~~~~~~~~~^~~
> In file included from mm/hugetlb_cgroup.c:23:
> ./include/linux/hugetlb.h:625:23: note: while referencing 'cgroup_files_dfl'
>   625 |         struct cftype cgroup_files_dfl[8];
>       |                       ^~~~~~~~~~~~~~~~
>
> Fixes: e45f4726bcad ("hugetlb: add hugetlb.*.numa_stat file")
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Muchun Song <songmuchun@bytedance.com>

Thanks.


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

* Re: [PATCH] hugetlb/cgroup: Fix copy/paste array assignment
  2021-12-03  6:56 [PATCH] hugetlb/cgroup: Fix copy/paste array assignment Kees Cook
  2021-12-03  7:43 ` Muchun Song
@ 2021-12-03 19:15 ` Mike Kravetz
  2021-12-07  1:54 ` Mina Almasry
  2 siblings, 0 replies; 4+ messages in thread
From: Mike Kravetz @ 2021-12-03 19:15 UTC (permalink / raw)
  To: Kees Cook, Mina Almasry
  Cc: Andrew Morton, Shakeel Butt, Muchun Song, linux-kernel, linux-mm,
	linux-hardening

On 12/2/21 22:56, Kees Cook wrote:
> Fix mismatched array assignment, reported by an -Warray-bounds build:
> 
> mm/hugetlb_cgroup.c: In function '__hugetlb_cgroup_file_legacy_init':
> mm/hugetlb_cgroup.c:850:35: error: array subscript 8 is above array bounds of 'struct cftype[8]' [-Werror=array-bounds ]
>   850 |         cft = &h->cgroup_files_dfl[8];
>       |                ~~~~~~~~~~~~~~~~~~~^~~
> In file included from mm/hugetlb_cgroup.c:23:
> ./include/linux/hugetlb.h:625:23: note: while referencing 'cgroup_files_dfl'
>   625 |         struct cftype cgroup_files_dfl[8];
>       |                       ^~~~~~~~~~~~~~~~
> 
> Fixes: e45f4726bcad ("hugetlb: add hugetlb.*.numa_stat file")
> Signed-off-by: Kees Cook <keescook@chromium.org>

Thank you Kees (and Muchun)!

I believe this is just in Andrew's tree and as a result linux-next right now.
Perhaps Andrew can just squash this and ("hugetlb: Fix spelling mistake
"hierarichal" -> "hierarchical"") with the original?

The Fixes hash will change.
-- 
Mike Kravetz


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

* Re: [PATCH] hugetlb/cgroup: Fix copy/paste array assignment
  2021-12-03  6:56 [PATCH] hugetlb/cgroup: Fix copy/paste array assignment Kees Cook
  2021-12-03  7:43 ` Muchun Song
  2021-12-03 19:15 ` Mike Kravetz
@ 2021-12-07  1:54 ` Mina Almasry
  2 siblings, 0 replies; 4+ messages in thread
From: Mina Almasry @ 2021-12-07  1:54 UTC (permalink / raw)
  To: Kees Cook
  Cc: Andrew Morton, Shakeel Butt, Muchun Song, Mike Kravetz,
	linux-kernel, linux-mm, linux-hardening

On Thu, Dec 2, 2021 at 10:56 PM Kees Cook <keescook@chromium.org> wrote:
>
> Fix mismatched array assignment, reported by an -Warray-bounds build:
>
> mm/hugetlb_cgroup.c: In function '__hugetlb_cgroup_file_legacy_init':
> mm/hugetlb_cgroup.c:850:35: error: array subscript 8 is above array bounds of 'struct cftype[8]' [-Werror=array-bounds ]
>   850 |         cft = &h->cgroup_files_dfl[8];
>       |                ~~~~~~~~~~~~~~~~~~~^~~
> In file included from mm/hugetlb_cgroup.c:23:
> ./include/linux/hugetlb.h:625:23: note: while referencing 'cgroup_files_dfl'
>   625 |         struct cftype cgroup_files_dfl[8];
>       |                       ^~~~~~~~~~~~~~~~
>
> Fixes: e45f4726bcad ("hugetlb: add hugetlb.*.numa_stat file")
> Signed-off-by: Kees Cook <keescook@chromium.org>

Sorry about that and thanks for the fix!

Reviewed-by: Mina Almasry <almasrymina@google.com>

> ---
>  mm/hugetlb_cgroup.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
> index 9eebe8df3c39..f9942841df18 100644
> --- a/mm/hugetlb_cgroup.c
> +++ b/mm/hugetlb_cgroup.c
> @@ -847,7 +847,7 @@ static void __init __hugetlb_cgroup_file_legacy_init(int idx)
>         cft->read_u64 = hugetlb_cgroup_read_u64;
>
>         /* Add the numa stat file */
> -       cft = &h->cgroup_files_dfl[8];
> +       cft = &h->cgroup_files_legacy[8];
>         snprintf(cft->name, MAX_CFTYPE_NAME, "%s.numa_stat", buf);
>         cft->private = MEMFILE_PRIVATE(idx, 1);
>         cft->seq_show = hugetlb_cgroup_read_numa_stat;
> --
> 2.30.2
>


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

end of thread, other threads:[~2021-12-07  1:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-03  6:56 [PATCH] hugetlb/cgroup: Fix copy/paste array assignment Kees Cook
2021-12-03  7:43 ` Muchun Song
2021-12-03 19:15 ` Mike Kravetz
2021-12-07  1:54 ` Mina Almasry

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