]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/6.8.6/modpost-fix-null-pointer-dereference.patch
Linux 6.8.6
[thirdparty/kernel/stable-queue.git] / releases / 6.8.6 / modpost-fix-null-pointer-dereference.patch
CommitLineData
335f7cc0
SL
1From da560e97a94a217794269bf19731d6a2c9340d5b Mon Sep 17 00:00:00 2001
2From: Sasha Levin <sashal@kernel.org>
3Date: Thu, 15 Feb 2024 15:13:21 +0100
4Subject: modpost: fix null pointer dereference
5
6From: Max Kellermann <max.kellermann@ionos.com>
7
8[ Upstream commit 23dfd914d2bfc4c9938b0084dffd7105de231d98 ]
9
10If the find_fromsym() call fails and returns NULL, the warn() call
11will dereference this NULL pointer and cause the program to crash.
12
13This happened when I tried to build with "test_user_copy" module.
14With this fix, it prints lots of warnings like this:
15
16 WARNING: modpost: lib/test_user_copy: section mismatch in reference: (unknown)+0x4 (section: .text.fixup) -> (unknown) (section: .init.text)
17
18masahiroy@kernel.org:
19 The issue is reproduced with ARCH=arm allnoconfig + CONFIG_MODULES=y +
20 CONFIG_RUNTIME_TESTING_MENU=y + CONFIG_TEST_USER_COPY=m
21
22Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
23Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
24Signed-off-by: Sasha Levin <sashal@kernel.org>
25---
26 scripts/mod/modpost.c | 4 +++-
27 1 file changed, 3 insertions(+), 1 deletion(-)
28
29diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
30index 6568f8177e392..ce686ebf5591f 100644
31--- a/scripts/mod/modpost.c
32+++ b/scripts/mod/modpost.c
33@@ -1053,7 +1053,9 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
34 sec_mismatch_count++;
35
36 warn("%s: section mismatch in reference: %s+0x%x (section: %s) -> %s (section: %s)\n",
37- modname, fromsym, (unsigned int)(faddr - from->st_value), fromsec, tosym, tosec);
38+ modname, fromsym,
39+ (unsigned int)(faddr - (from ? from->st_value : 0)),
40+ fromsec, tosym, tosec);
41
42 if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) {
43 if (match(tosec, mismatch->bad_tosec))
44--
452.43.0
46