Skip to content

Commit 3489d92

Browse files
urezkismb49
authored andcommitted
rcu: Return early if callback is not specified
BugLink: https://bugs.launchpad.net/bugs/2122072 [ Upstream commit 33b6a1f155d627f5bd80c7485c598ce45428f74f ] Currently the call_rcu() API does not check whether a callback pointer is NULL. If NULL is passed, rcu_core() will try to invoke it, resulting in NULL pointer dereference and a kernel crash. To prevent this and improve debuggability, this patch adds a check for NULL and emits a kernel stack trace to help identify a faulty caller. Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com> Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com> Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Noah Wager <noah.wager@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent 8f15ed6 commit 3489d92

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

kernel/rcu/tree.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,6 +3055,10 @@ __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy_in)
30553055
/* Misaligned rcu_head! */
30563056
WARN_ON_ONCE((unsigned long)head & (sizeof(void *) - 1));
30573057

3058+
/* Avoid NULL dereference if callback is NULL. */
3059+
if (WARN_ON_ONCE(!func))
3060+
return;
3061+
30583062
if (debug_rcu_head_queue(head)) {
30593063
/*
30603064
* Probable double call_rcu(), so leak the callback.

0 commit comments

Comments
 (0)