Skip to content

Commit 100040b

Browse files
urezkigregkh
authored andcommitted
rcu: Return early if callback is not specified
[ 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) <[email protected]> Reviewed-by: Joel Fernandes <[email protected]> Signed-off-by: Joel Fernandes <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent f994086 commit 100040b

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
@@ -2827,6 +2827,10 @@ void call_rcu(struct rcu_head *head, rcu_callback_t func)
28272827
/* Misaligned rcu_head! */
28282828
WARN_ON_ONCE((unsigned long)head & (sizeof(void *) - 1));
28292829

2830+
/* Avoid NULL dereference if callback is NULL. */
2831+
if (WARN_ON_ONCE(!func))
2832+
return;
2833+
28302834
if (debug_rcu_head_queue(head)) {
28312835
/*
28322836
* Probable double call_rcu(), so leak the callback.

0 commit comments

Comments
 (0)