Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 1102f9f

Browse files
committed
modpost: do not make find_tosym() return NULL
As mentioned in commit 3975865 ("modpost: Add '.ltext' and '.ltext.*' to TEXT_SECTIONS"), modpost can result in a segmentation fault due to a NULL pointer dereference in default_mismatch_handler(). find_tosym() can return the original symbol pointer instead of NULL if a better one is not found. This fixes the reported segmentation fault. Fixes: a23e758 ("modpost: unify 'sym' and 'to' in default_mismatch_handler()") Reported-by: Nathan Chancellor <nathan@kernel.org> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent 0316e4b commit 1102f9f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

scripts/mod/modpost.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,8 @@ static Elf_Sym *find_fromsym(struct elf_info *elf, Elf_Addr addr,
10071007

10081008
static Elf_Sym *find_tosym(struct elf_info *elf, Elf_Addr addr, Elf_Sym *sym)
10091009
{
1010+
Elf_Sym *new_sym;
1011+
10101012
/* If the supplied symbol has a valid name, return it */
10111013
if (is_valid_name(elf, sym))
10121014
return sym;
@@ -1015,8 +1017,9 @@ static Elf_Sym *find_tosym(struct elf_info *elf, Elf_Addr addr, Elf_Sym *sym)
10151017
* Strive to find a better symbol name, but the resulting name may not
10161018
* match the symbol referenced in the original code.
10171019
*/
1018-
return symsearch_find_nearest(elf, addr, get_secindex(elf, sym),
1019-
true, 20);
1020+
new_sym = symsearch_find_nearest(elf, addr, get_secindex(elf, sym),
1021+
true, 20);
1022+
return new_sym ? new_sym : sym;
10201023
}
10211024

10221025
static bool is_executable_section(struct elf_info *elf, unsigned int secndx)

0 commit comments

Comments
 (0)