1 From ca71e00839fcdd26f122fb6d9e97903c9fe198f7 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Sat, 6 May 2023 08:08:35 +0200
4 Subject: [PATCH] binfmt_elf: dynamically allocate note.data in
7 Dynamically allocate note.data in parse_elf_properties to fix
8 compilation warning on some arch.
10 On some arch note.data exceet the stack limit for a single function and
11 this cause the following compilation warning:
12 fs/binfmt_elf.c: In function 'parse_elf_properties.isra':
13 fs/binfmt_elf.c:821:1: error: the frame size of 1040 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
16 cc1: all warnings being treated as errors
18 Fix this by dynamically allocating the array.
20 Fixes: 00e19ceec80b ("ELF: Add ELF program property parsing support")
21 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
22 Cc: stable@vger.kernel.org # v5.8+
24 fs/binfmt_elf.c | 32 +++++++++++++++++++++++---------
25 1 file changed, 23 insertions(+), 9 deletions(-)
29 @@ -769,7 +769,7 @@ static int parse_elf_properties(struct f
33 - char data[NOTE_DATA_SZ];
38 @@ -789,26 +789,38 @@ static int parse_elf_properties(struct f
39 if (phdr->p_filesz > sizeof(note))
42 + note.data = kcalloc(NOTE_DATA_SZ, sizeof(*note.data), GFP_KERNEL);
47 n = kernel_read(f, ¬e, phdr->p_filesz, &pos);
49 BUILD_BUG_ON(sizeof(note) < sizeof(note.nhdr) + NOTE_NAME_SZ);
50 - if (n < 0 || n < sizeof(note.nhdr) + NOTE_NAME_SZ)
52 + if (n < 0 || n < sizeof(note.nhdr) + NOTE_NAME_SZ) {
57 if (note.nhdr.n_type != NT_GNU_PROPERTY_TYPE_0 ||
58 note.nhdr.n_namesz != NOTE_NAME_SZ ||
59 strncmp(note.data + sizeof(note.nhdr),
60 - GNU_PROPERTY_TYPE_0_NAME, n - sizeof(note.nhdr)))
62 + GNU_PROPERTY_TYPE_0_NAME, n - sizeof(note.nhdr))) {
67 off = round_up(sizeof(note.nhdr) + NOTE_NAME_SZ,
68 ELF_GNU_PROPERTY_ALIGN);
72 - if (note.nhdr.n_descsz > n - off)
79 + if (note.nhdr.n_descsz > n - off) {
83 datasz = off + note.nhdr.n_descsz;
85 have_prev_type = false;
86 @@ -818,6 +830,8 @@ static int parse_elf_properties(struct f
87 have_prev_type = true;
92 return ret == -ENOENT ? 0 : ret;