]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rcu: Return early if callback is not specified
authorUladzislau Rezki (Sony) <urezki@gmail.com>
Tue, 10 Jun 2025 17:34:48 +0000 (19:34 +0200)
committerJoel Fernandes <joelagnelf@nvidia.com>
Fri, 20 Jun 2025 19:31:48 +0000 (15:31 -0400)
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>
kernel/rcu/tree.c

index e8a4b720d7d283a3771d069805349fa16f27eada..14d4499c6fc31615325452f0bf49d71bba8601b9 100644 (file)
@@ -3072,6 +3072,10 @@ __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy_in)
        /* Misaligned rcu_head! */
        WARN_ON_ONCE((unsigned long)head & (sizeof(void *) - 1));
 
+       /* Avoid NULL dereference if callback is NULL. */
+       if (WARN_ON_ONCE(!func))
+               return;
+
        if (debug_rcu_head_queue(head)) {
                /*
                 * Probable double call_rcu(), so leak the callback.