summaryrefslogtreecommitdiff
path: root/scripts/mod/modpost.c
diff options
context:
space:
mode:
authorMax Kellermann <max.kellermann@ionos.com>2024-02-15 17:13:21 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-04-13 14:10:10 +0300
commitb741f93b6eb4c1e701be586803ca283a56d11191 (patch)
treecbe77b64ae522496ebd97eeec4b959cdd0f923d1 /scripts/mod/modpost.c
parentcb1cd176e0b431644653a7fa8691a1aaf7be98da (diff)
downloadlinux-b741f93b6eb4c1e701be586803ca283a56d11191.tar.xz
modpost: fix null pointer dereference
[ Upstream commit 23dfd914d2bfc4c9938b0084dffd7105de231d98 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'scripts/mod/modpost.c')
-rw-r--r--scripts/mod/modpost.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 6568f8177e39..ce686ebf5591 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1053,7 +1053,9 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
sec_mismatch_count++;
warn("%s: section mismatch in reference: %s+0x%x (section: %s) -> %s (section: %s)\n",
- modname, fromsym, (unsigned int)(faddr - from->st_value), fromsec, tosym, tosec);
+ modname, fromsym,
+ (unsigned int)(faddr - (from ? from->st_value : 0)),
+ fromsec, tosym, tosec);
if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) {
if (match(tosec, mismatch->bad_tosec))