]>
Commit | Line | Data |
---|---|---|
335f7cc0 SL |
1 | From da560e97a94a217794269bf19731d6a2c9340d5b Mon Sep 17 00:00:00 2001 |
2 | From: Sasha Levin <sashal@kernel.org> | |
3 | Date: Thu, 15 Feb 2024 15:13:21 +0100 | |
4 | Subject: modpost: fix null pointer dereference | |
5 | ||
6 | From: Max Kellermann <max.kellermann@ionos.com> | |
7 | ||
8 | [ Upstream commit 23dfd914d2bfc4c9938b0084dffd7105de231d98 ] | |
9 | ||
10 | If the find_fromsym() call fails and returns NULL, the warn() call | |
11 | will dereference this NULL pointer and cause the program to crash. | |
12 | ||
13 | This happened when I tried to build with "test_user_copy" module. | |
14 | With 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 | ||
18 | masahiroy@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 | ||
22 | Signed-off-by: Max Kellermann <max.kellermann@ionos.com> | |
23 | Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> | |
24 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
25 | --- | |
26 | scripts/mod/modpost.c | 4 +++- | |
27 | 1 file changed, 3 insertions(+), 1 deletion(-) | |
28 | ||
29 | diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c | |
30 | index 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 | -- | |
45 | 2.43.0 | |
46 |