]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.6/modpost-do-not-make-find_tosym-return-null.patch
0ae3796c8ea6ae1c82613dbfe99a16e4c9d44057
[thirdparty/kernel/stable-queue.git] / queue-6.6 / modpost-do-not-make-find_tosym-return-null.patch
1 From 7a195340722526f1bf5f2278d5357bf3154e3b98 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Sat, 23 Mar 2024 20:45:11 +0900
4 Subject: modpost: do not make find_tosym() return NULL
5
6 From: Masahiro Yamada <masahiroy@kernel.org>
7
8 [ Upstream commit 1102f9f85bf66b1a7bd6a40afb40efbbe05dfc05 ]
9
10 As mentioned in commit 397586506c3d ("modpost: Add '.ltext' and
11 '.ltext.*' to TEXT_SECTIONS"), modpost can result in a segmentation
12 fault due to a NULL pointer dereference in default_mismatch_handler().
13
14 find_tosym() can return the original symbol pointer instead of NULL
15 if a better one is not found.
16
17 This fixes the reported segmentation fault.
18
19 Fixes: a23e7584ecf3 ("modpost: unify 'sym' and 'to' in default_mismatch_handler()")
20 Reported-by: Nathan Chancellor <nathan@kernel.org>
21 Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
22 Signed-off-by: Sasha Levin <sashal@kernel.org>
23 ---
24 scripts/mod/modpost.c | 7 +++++--
25 1 file changed, 5 insertions(+), 2 deletions(-)
26
27 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
28 index 66589fb4e9aef..7d53942445d75 100644
29 --- a/scripts/mod/modpost.c
30 +++ b/scripts/mod/modpost.c
31 @@ -1052,6 +1052,8 @@ static Elf_Sym *find_fromsym(struct elf_info *elf, Elf_Addr addr,
32
33 static Elf_Sym *find_tosym(struct elf_info *elf, Elf_Addr addr, Elf_Sym *sym)
34 {
35 + Elf_Sym *new_sym;
36 +
37 /* If the supplied symbol has a valid name, return it */
38 if (is_valid_name(elf, sym))
39 return sym;
40 @@ -1060,8 +1062,9 @@ static Elf_Sym *find_tosym(struct elf_info *elf, Elf_Addr addr, Elf_Sym *sym)
41 * Strive to find a better symbol name, but the resulting name may not
42 * match the symbol referenced in the original code.
43 */
44 - return symsearch_find_nearest(elf, addr, get_secindex(elf, sym),
45 - true, 20);
46 + new_sym = symsearch_find_nearest(elf, addr, get_secindex(elf, sym),
47 + true, 20);
48 + return new_sym ? new_sym : sym;
49 }
50
51 static bool is_executable_section(struct elf_info *elf, unsigned int secndx)
52 --
53 2.43.0
54