Skip to content

Commit 33b6a1f

Browse files
urezkiJoel Fernandes
authored andcommitted
rcu: Return early if callback is not specified
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]>
1 parent 11313e2 commit 33b6a1f

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
@@ -3072,6 +3072,10 @@ __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy_in)
30723072
/* Misaligned rcu_head! */
30733073
WARN_ON_ONCE((unsigned long)head & (sizeof(void *) - 1));
30743074

3075+
/* Avoid NULL dereference if callback is NULL. */
3076+
if (WARN_ON_ONCE(!func))
3077+
return;
3078+
30753079
if (debug_rcu_head_queue(head)) {
30763080
/*
30773081
* Probable double call_rcu(), so leak the callback.

0 commit comments

Comments
 (0)