From: Wang Hai <wanghai38@huawei.com>
To: <peterz@infradead.org>, <jpoimboe@redhat.com>,
<jbaron@akamai.com>, <rostedt@goodmis.org>, <ardb@kernel.org>,
<mingo@kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: [PATCH] static_call: fix null-ptr-deref in static_call_del_module
Date: Sat, 9 Oct 2021 15:44:28 +0800 [thread overview]
Message-ID: <20211009074428.1668662-1-wanghai38@huawei.com> (raw)
I got a NULL pointer dereference report when doing fault injection test:
BUG: kernel NULL pointer dereference, address: 0000000000000009
...
RIP: 0010:static_call_del_module+0x7a/0x100
...
Call Trace:
static_call_module_notify+0x1e1/0x200
notifier_call_chain_robust+0x6f/0xe0
blocking_notifier_call_chain_robust+0x4e/0x70
load_module+0x21f7/0x2b60
__do_sys_finit_module+0xb0/0xf0
? __do_sys_finit_module+0xb0/0xf0
__x64_sys_finit_module+0x1a/0x20
do_syscall_64+0x34/0xb0
entry_SYSCALL_64_after_hwframe+0x44/0xae
When loading a module, if it fails to allocate memory for static
calls, it will delete the non-existent mods (mods == 1) in the
static_call_module_notify()'s error path.
static_call_module_notify
static_call_add_module
__static_call_init
site_mod = kzalloc() // fault injection
static_call_del_module // access non-existent mods
This patch fixes the bug by skipping the operation when the key
has no mods.
Fixes: a945c8345ec0 ("static_call: Allow early init")
Signed-off-by: Wang Hai <wanghai38@huawei.com>
---
kernel/static_call.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/static_call.c b/kernel/static_call.c
index 43ba0b1e0edb..c3f8ffc5a52f 100644
--- a/kernel/static_call.c
+++ b/kernel/static_call.c
@@ -400,7 +400,7 @@ static void static_call_del_module(struct module *mod)
for (site = start; site < stop; site++) {
key = static_call_key(site);
- if (key == prev_key)
+ if (key == prev_key || !static_call_key_has_mods(key))
continue;
prev_key = key;
--
2.17.1
next reply other threads:[~2021-10-09 7:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-09 7:44 Wang Hai [this message]
2021-10-09 10:00 ` Peter Zijlstra
2021-10-11 3:18 ` wanghai (M)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211009074428.1668662-1-wanghai38@huawei.com \
--to=wanghai38@huawei.com \
--cc=ardb@kernel.org \
--cc=jbaron@akamai.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®