kernel: use struct group to wipe psb6970 volatile priv data
[openwrt/staging/hauke.git] / target / linux / generic / pending-5.15 / 130-binfmt_elf-dynamically-allocate-note.data-in-parse_e.patch
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
5 parse_elf_properties
6
7 Dynamically allocate note.data in parse_elf_properties to fix
8 compilation warning on some arch.
9
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=]
14 821 | }
15 | ^
16 cc1: all warnings being treated as errors
17
18 Fix this by dynamically allocating the array.
19
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+
23 ---
24 fs/binfmt_elf.c | 32 +++++++++++++++++++++++---------
25 1 file changed, 23 insertions(+), 9 deletions(-)
26
27 --- a/fs/binfmt_elf.c
28 +++ b/fs/binfmt_elf.c
29 @@ -768,7 +768,7 @@ static int parse_elf_properties(struct f
30 {
31 union {
32 struct elf_note nhdr;
33 - char data[NOTE_DATA_SZ];
34 + char *data;
35 } note;
36 loff_t pos;
37 ssize_t n;
38 @@ -788,26 +788,38 @@ static int parse_elf_properties(struct f
39 if (phdr->p_filesz > sizeof(note))
40 return -ENOEXEC;
41
42 + note.data = kcalloc(NOTE_DATA_SZ, sizeof(*note.data), GFP_KERNEL);
43 + if (!note.data)
44 + return -ENOMEM;
45 +
46 pos = phdr->p_offset;
47 n = kernel_read(f, &note, phdr->p_filesz, &pos);
48
49 BUILD_BUG_ON(sizeof(note) < sizeof(note.nhdr) + NOTE_NAME_SZ);
50 - if (n < 0 || n < sizeof(note.nhdr) + NOTE_NAME_SZ)
51 - return -EIO;
52 + if (n < 0 || n < sizeof(note.nhdr) + NOTE_NAME_SZ) {
53 + ret = -EIO;
54 + goto exit;
55 + }
56
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)))
61 - return -ENOEXEC;
62 + GNU_PROPERTY_TYPE_0_NAME, n - sizeof(note.nhdr))) {
63 + ret = -ENOEXEC;
64 + goto exit;
65 + }
66
67 off = round_up(sizeof(note.nhdr) + NOTE_NAME_SZ,
68 ELF_GNU_PROPERTY_ALIGN);
69 - if (off > n)
70 - return -ENOEXEC;
71 -
72 - if (note.nhdr.n_descsz > n - off)
73 - return -ENOEXEC;
74 + if (off > n) {
75 + ret = -ENOEXEC;
76 + goto exit;
77 + }
78 +
79 + if (note.nhdr.n_descsz > n - off) {
80 + ret = -ENOEXEC;
81 + goto exit;
82 + }
83 datasz = off + note.nhdr.n_descsz;
84
85 have_prev_type = false;
86 @@ -817,6 +829,8 @@ static int parse_elf_properties(struct f
87 have_prev_type = true;
88 } while (!ret);
89
90 +exit:
91 + kfree(note.data);
92 return ret == -ENOENT ? 0 : ret;
93 }
94