]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
modpost: do not make find_tosym() return NULL
authorMasahiro Yamada <masahiroy@kernel.org>
Sat, 23 Mar 2024 11:45:11 +0000 (20:45 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Apr 2024 14:35:47 +0000 (16:35 +0200)
[ Upstream commit 1102f9f85bf66b1a7bd6a40afb40efbbe05dfc05 ]

As mentioned in commit 397586506c3d ("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: a23e7584ecf3 ("modpost: unify 'sym' and 'to' in default_mismatch_handler()")
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
scripts/mod/modpost.c

index 66589fb4e9aef54d7fc8f3ab397a78b8e9d4e451..7d53942445d75f602a2d6d80afe226c57d3c72de 100644 (file)
@@ -1052,6 +1052,8 @@ static Elf_Sym *find_fromsym(struct elf_info *elf, Elf_Addr addr,
 
 static Elf_Sym *find_tosym(struct elf_info *elf, Elf_Addr addr, Elf_Sym *sym)
 {
+       Elf_Sym *new_sym;
+
        /* If the supplied symbol has a valid name, return it */
        if (is_valid_name(elf, sym))
                return sym;
@@ -1060,8 +1062,9 @@ static Elf_Sym *find_tosym(struct elf_info *elf, Elf_Addr addr, Elf_Sym *sym)
         * Strive to find a better symbol name, but the resulting name may not
         * match the symbol referenced in the original code.
         */
-       return symsearch_find_nearest(elf, addr, get_secindex(elf, sym),
-                                     true, 20);
+       new_sym = symsearch_find_nearest(elf, addr, get_secindex(elf, sym),
+                                        true, 20);
+       return new_sym ? new_sym : sym;
 }
 
 static bool is_executable_section(struct elf_info *elf, unsigned int secndx)