Skip to content

Commit 23dfd91

Browse files
MaxKellermannmasahir0y
authored andcommitted
modpost: fix null pointer dereference
If the find_fromsym() call fails and returns NULL, the warn() call will dereference this NULL pointer and cause the program to crash. This happened when I tried to build with "test_user_copy" module. With this fix, it prints lots of warnings like this: WARNING: modpost: lib/test_user_copy: section mismatch in reference: (unknown)+0x4 (section: .text.fixup) -> (unknown) (section: .init.text) masahiroy@kernel.org: The issue is reproduced with ARCH=arm allnoconfig + CONFIG_MODULES=y + CONFIG_RUNTIME_TESTING_MENU=y + CONFIG_TEST_USER_COPY=m Signed-off-by: Max Kellermann <max.kellermann@ionos.com> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent 44929bf commit 23dfd91

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

scripts/mod/modpost.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,9 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
10501050
sec_mismatch_count++;
10511051

10521052
warn("%s: section mismatch in reference: %s+0x%x (section: %s) -> %s (section: %s)\n",
1053-
modname, fromsym, (unsigned int)(faddr - from->st_value), fromsec, tosym, tosec);
1053+
modname, fromsym,
1054+
(unsigned int)(faddr - (from ? from->st_value : 0)),
1055+
fromsec, tosym, tosec);
10541056

10551057
if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) {
10561058
if (match(tosec, mismatch->bad_tosec))

0 commit comments

Comments
 (0)