rcu: Improve callback diagnostics and validation
Subsystems (2)
v2 cover rcu: Improve callback diagnostics and validation
Hi,
This series improves callback diagnostics and validation across RCU, SRCU, and RCU Tasks.
Patches 1-3 record callback registration stacks for KASAN in Tree SRCU, Tiny SRCU, and Tiny RCU. KASAN prints the recorded auxiliary stack when reporting a use-after-free.
Patches 4-6 add rcu_head alignment and NULL callback-function checks.
Patches 7-10 detect duplicate callback enqueue attempts before queueing, using the RCU head debug-object mechanism. A duplicate registration is rejected at entry and __ratelimit() controls the diagnostic output group (pr_err, mem_dump_obj, dump_stack). Detection requires CONFIG_DEBUG_OBJECTS_RCU_HEAD.
Changes since v1:
- Patches 7-9: __ratelimit() + dump_stack() instead of hard-coded limit
- Patch 10 (new): same change for Tree RCU's rcu_do_enqueue()
- Patch 9: fixed log format to avoid pseudo-function names
- Tags: Reviewed-by (4-6), Suggested-by (7-10)
- v1: https://lore.kernel.org/all/[email protected]/
Testing:
rcutorture with KASAN (SRCU-N, SRCU-P, SRCU-T, SRCU-U, TINY01, TINY02, TREE03, 3min each): all exitcode 0.
KASAN aux stack (QEMU, CONFIG_KASAN_GENERIC=y):
Last potentially related work creation:
kasan_save_stack+0x33/0x60
kasan_record_aux_stack+0x8c/0xa0
call_srcu+0xb2/0x390 Duplicate enqueue (QEMU, CONFIG_DEBUG_OBJECTS_RCU_HEAD=y):
call_srcu(): Duplicate call_srcu() CB ... ->cb
dump_stack_lvl+0x47/0x60
call_rcu_tasks_generic(): Duplicate CB for RCU Tasks, ... ->cb
dump_stack_lvl+0x47/0x60
rcu_do_enqueue(): Double-freed CB ... ->cb slab kmalloc-16 ...Kunwu Chan (10):
srcu: Record callback registration stack for KASAN
srcutiny: Record callback registration stack for KASAN
rcu: Record callback registration stack for Tiny RCU
srcu: Validate callback arguments
rcu: Validate callback arguments in Tiny RCU
rcu-tasks: Validate callback arguments
srcu: Detect duplicate callback enqueue at registration
srcutiny: Detect duplicate callback enqueue
rcu-tasks: Detect duplicate callback enqueue
rcu: Improve duplicate callback diagnostics
kernel/rcu/srcutiny.c | 34 ++++++++++++++++++++++++++++++++++ kernel/rcu/srcutree.c | 36 ++++++++++++++++++++++++++++++------ kernel/rcu/tasks.h | 27 +++++++++++++++++++++++++++ kernel/rcu/tiny.c | 11 +++++++++++ kernel/rcu/tree.c | 9 +++++++-- 5 files changed, 109 insertions(+), 8 deletions(-)
base-commit: 940793b926aa94bf65ec404043050888e3053188
Signature · 1 line
2.43.0
PATCH v2 1/10 srcu: Record callback registration stack for KASAN
Record the callback registration stack in __call_srcu() for KASAN diagnostics involving SRCU callbacks.
--- kernel/rcu/srcutree.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/rcu/srcutree.c +5 -0
@@ -20,6 +20,7 @@#include <linux/percpu.h> #include <linux/preempt.h> #include <linux/irq_work.h> +#include <linux/kasan.h> #include <linux/llist.h> #include <linux/rcupdate_wait.h> #include <linux/sched.h>
@@ -1530,6 +1531,10 @@ static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp, {if (WARN_ON_ONCE (ssp->srcu_reader_flavor ==SRCU_READ_FLAVOR_ATOMIC ))return ;// Leak the callback rather than corrupt SRCU state. + +/* Record the caller: the irq_work's stack says nothing about it. */ +kasan_record_aux_stack (rhp); +if (should_rcu_defer ()) {struct srcu_defer *sndp =this_cpu_ptr (&srcu_defer);struct srcu_data *sdp;
Signature · 1 line
2.43.0
PATCH v2 2/10 srcutiny: Record callback registration stack for KASAN
In reply to Kunwu ChanRecord the callback registration stack in call_srcu() for KASAN diagnostics involving Tiny SRCU callbacks.
--- kernel/rcu/srcutiny.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/rcu/srcutiny.c +4 -0
@@ -10,6 +10,7 @@#include <linux/export.h> #include <linux/irq_work.h> +#include <linux/kasan.h> #include <linux/llist.h> #include <linux/mutex.h> #include <linux/preempt.h>
@@ -290,6 +291,9 @@ EXPORT_SYMBOL_GPL(srcu_defer_drain);void call_srcu (struct srcu_struct *ssp,struct rcu_head *rhp,rcu_callback_t func) { +/* Record the caller: the irq_work's stack says nothing about it. */ +kasan_record_aux_stack (rhp); +if (should_rcu_defer ()) {/* A re-entrant call_srcu() during the drain would livelock it. */ if (READ_ONCE (srcu_defer_draining) && !in_nmi ()) {
Signature · 1 line
2.43.0
PATCH v2 3/10 rcu: Record callback registration stack for Tiny RCU
In reply to Kunwu ChanRecord the callback registration stack in call_rcu() for KASAN diagnostics involving Tiny RCU callbacks.
--- kernel/rcu/tiny.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/rcu/tiny.c +4 -0
@@ -12,6 +12,7 @@#include <linux/completion.h> #include <linux/interrupt.h> #include <linux/irq_work.h> +#include <linux/kasan.h> #include <linux/llist.h> #include <linux/notifier.h> #include <linux/rcupdate_wait.h>
@@ -251,6 +252,9 @@ EXPORT_SYMBOL_GPL(synchronize_rcu);*/ void call_rcu (struct rcu_head *head,rcu_callback_t func) { +/* Record the caller: the irq_work's stack says nothing about it. */ +kasan_record_aux_stack (head); +if (should_rcu_defer ()) {call_rcu_defer (head, func);return ;
Signature · 1 line
2.43.0
PATCH v2 4/10 srcu: Validate callback arguments
In reply to Kunwu ChanCheck callback-head alignment and reject NULL callback functions in the SRCU callback registration paths.
--- kernel/rcu/srcutiny.c | 7 +++++++ kernel/rcu/srcutree.c | 7 +++++++ 2 files changed, 14 insertions(+)
kernel/rcu/srcutiny.c +7 -0
@@ -291,6 +291,13 @@ EXPORT_SYMBOL_GPL(srcu_defer_drain);void call_srcu (struct srcu_struct *ssp,struct rcu_head *rhp,rcu_callback_t func) { +/* Misaligned rcu_head! */ +WARN_ON_ONCE ((unsigned long )rhp & (sizeof (void *) -1 )); + +/* Avoid NULL dereference if callback is NULL. */ +if (WARN_ON_ONCE (!func)) +return ; +/* Record the caller: the irq_work's stack says nothing about it. */ kasan_record_aux_stack (rhp);
kernel/rcu/srcutree.c +7 -0
@@ -1529,6 +1529,13 @@ static void srcu_do_enqueue(struct srcu_struct *ssp, struct rcu_head *rhp,static void __call_srcu (struct srcu_struct *ssp,struct rcu_head *rhp,rcu_callback_t func,bool do_norm) { +/* Misaligned rcu_head! */ +WARN_ON_ONCE ((unsigned long )rhp & (sizeof (void *) -1 )); + +/* Avoid NULL dereference if callback is NULL. */ +if (WARN_ON_ONCE (!func)) +return ; +if (WARN_ON_ONCE (ssp->srcu_reader_flavor ==SRCU_READ_FLAVOR_ATOMIC ))return ;// Leak the callback rather than corrupt SRCU state.
Signature · 1 line
2.43.0
PATCH v2 5/10 rcu: Validate callback arguments in Tiny RCU
In reply to Kunwu ChanCheck callback-head alignment and reject NULL callback functions in Tiny RCU's call_rcu() path.
--- kernel/rcu/tiny.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/rcu/tiny.c +7 -0
@@ -252,6 +252,13 @@ EXPORT_SYMBOL_GPL(synchronize_rcu);*/ void call_rcu (struct rcu_head *head,rcu_callback_t func) { +/* 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 ; +/* Record the caller: the irq_work's stack says nothing about it. */ kasan_record_aux_stack (head);
Signature · 1 line
2.43.0
PATCH v2 6/10 rcu-tasks: Validate callback arguments
In reply to Kunwu ChanCheck callback-head alignment and reject NULL callback functions in the generic RCU Tasks callback registration path.
--- kernel/rcu/tasks.h | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/rcu/tasks.h +7 -0
@@ -351,6 +351,13 @@ static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func,bool needwake;struct rcu_tasks_percpu *rtpcp; +/* Misaligned rcu_head! */ +WARN_ON_ONCE ((unsigned long )rhp & (sizeof (void *) -1 )); + +/* Avoid NULL dereference if callback is NULL. */ +if (WARN_ON_ONCE (!func)) +return ; + rhp->next =NULL ; rhp->func = func;local_irq_save (flags);
Signature · 1 line
2.43.0
PATCH v2 7/10 srcu: Detect duplicate callback enqueue at registration
In reply to Kunwu ChanMove the duplicate-callback check from srcu_do_enqueue() to __call_srcu() entry so that detected duplicate registrations are rejected before they reach the deferred-list enqueue path. Use __ratelimit() to limit the diagnostic output (error message, object dump, and stack trace) as a group.
--- kernel/rcu/srcutree.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
kernel/rcu/srcutree.c +18 -6
@@ -23,10 +23,12 @@#include <linux/kasan.h> #include <linux/llist.h> #include <linux/rcupdate_wait.h> +#include <linux/ratelimit.h> #include <linux/sched.h> #include <linux/smp.h> #include <linux/delay.h> #include <linux/module.h> +#include <linux/mm.h> #include <linux/slab.h> #include <linux/srcu.h>
@@ -1511,12 +1513,6 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,static void srcu_do_enqueue (struct srcu_struct *ssp,struct rcu_head *rhp,rcu_callback_t func,bool do_norm) { -if (debug_rcu_head_queue (rhp)) { -/* Probable double call_srcu(), so leak the callback. */ -WRITE_ONCE (rhp->func, srcu_leak_callback); -WARN_ONCE (1 ,"call_srcu(): Leaked duplicate callback\n" ); -return ; - } rhp->func = func; (void )srcu_gp_start_if_needed (ssp, rhp, do_norm); }
@@ -1526,6 +1522,10 @@ static void srcu_do_enqueue(struct srcu_struct *ssp, struct rcu_head *rhp,* disabled, so defer when interrupts are already off rather than enqueue into * an operation that may be in flight on this CPU. */ +static DEFINE_RATELIMIT_STATE(rcu_srcu_dup_rs, + DEFAULT_RATELIMIT_INTERVAL, + DEFAULT_RATELIMIT_BURST); +static void __call_srcu (struct srcu_struct *ssp,struct rcu_head *rhp,rcu_callback_t func,bool do_norm) {
@@ -1539,6 +1539,17 @@ static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,if (WARN_ON_ONCE (ssp->srcu_reader_flavor ==SRCU_READ_FLAVOR_ATOMIC ))return ;// Leak the callback rather than corrupt SRCU state. +if (debug_rcu_head_queue (rhp)) { +if (__ratelimit (&rcu_srcu_dup_rs)) { +pr_err ("%s(): Duplicate call_srcu() CB %p->%pS()\n" , + __func__, rhp, rhp->func); +mem_dump_obj (rhp); +dump_stack (); + } +WRITE_ONCE (rhp->func, srcu_leak_callback); +return ; + } +/* Record the caller: the irq_work's stack says nothing about it. */ kasan_record_aux_stack (rhp);
@@ -1554,6 +1565,7 @@ static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,if (READ_ONCE (sndp->draining) && !in_nmi ()) {WARN_ONCE (IS_ENABLED (CONFIG_PROVE_RCU ),"call_srcu() re-entered during callback drain; leaking callback\n" ); +debug_rcu_head_unqueue (rhp);return ; } sdp =this_cpu_ptr (ssp->sda);
Signature · 1 line
2.43.0
PATCH v2 8/10 srcutiny: Detect duplicate callback enqueue
In reply to Kunwu ChanDetect duplicate callback enqueue attempts at call_srcu() entry, before the deferred list can be corrupted. Use __ratelimit() for the diagnostic output group.
--- kernel/rcu/srcutiny.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
kernel/rcu/srcutiny.c +23 -0
@@ -12,9 +12,11 @@#include <linux/irq_work.h> #include <linux/kasan.h> #include <linux/llist.h> +#include <linux/mm.h> #include <linux/mutex.h> #include <linux/preempt.h> #include <linux/rcupdate_wait.h> +#include <linux/ratelimit.h> #include <linux/sched.h> #include <linux/delay.h> #include <linux/srcu.h>
@@ -178,6 +180,7 @@ void srcu_drive_gp(struct work_struct *wp)while (lh) { rhp = lh; lh = lh->next; +debug_rcu_head_unqueue (rhp);debug_rcu_head_callback (rhp);local_bh_disable (); rhp->func (rhp);
@@ -235,6 +238,8 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)* Also called by __srcu_defer_drain() to re-issue a deferred callback, so it * must not re-check the deferral condition. */ +static void srcu_leak_callback (struct rcu_head *rhp) { } +static void srcu_do_enqueue (struct srcu_struct *ssp,struct rcu_head *rhp,rcu_callback_t func) {
@@ -272,6 +277,8 @@ static void __srcu_defer_drain(struct srcu_struct *ssp)llist_for_each_safe (node, next,llist_del_all (&ssp->defer_cbs)) {struct rcu_head *rhp = (struct rcu_head *)node; +/* Bounds a node self-linked by a double call_srcu(). */ + rhp->next =NULL ;srcu_do_enqueue (ssp, rhp, rhp->func); }local_irq_restore (flags);
@@ -288,6 +295,10 @@ void srcu_defer_drain(struct irq_work *iw) }EXPORT_SYMBOL_GPL (srcu_defer_drain); +static DEFINE_RATELIMIT_STATE(rcu_srcutiny_dup_rs, + DEFAULT_RATELIMIT_INTERVAL, + DEFAULT_RATELIMIT_BURST); +void call_srcu (struct srcu_struct *ssp,struct rcu_head *rhp,rcu_callback_t func) {
@@ -298,6 +309,17 @@ void call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,if (WARN_ON_ONCE (!func))return ; +if (debug_rcu_head_queue (rhp)) { +if (__ratelimit (&rcu_srcutiny_dup_rs)) { +pr_err ("%s(): Duplicate call_srcu() CB %p->%pS()\n" , + __func__, rhp, rhp->func); +mem_dump_obj (rhp); +dump_stack (); + } +WRITE_ONCE (rhp->func, srcu_leak_callback); +return ; + } +/* Record the caller: the irq_work's stack says nothing about it. */ kasan_record_aux_stack (rhp);
@@ -306,6 +328,7 @@ void call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,if (READ_ONCE (srcu_defer_draining) && !in_nmi ()) {WARN_ONCE (IS_ENABLED (CONFIG_PROVE_RCU ),"call_srcu() re-entered during callback drain; leaking callback\n" ); +debug_rcu_head_unqueue (rhp);return ; } rhp->func = func;
Signature · 1 line
2.43.0
PATCH v2 9/10 rcu-tasks: Detect duplicate callback enqueue
In reply to Kunwu ChanDetect duplicate callback enqueue attempts in the generic RCU Tasks callback registration path. Use __ratelimit() for the diagnostic output group.
--- kernel/rcu/tasks.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
kernel/rcu/tasks.h +20 -0
@@ -6,6 +6,8 @@*/ #ifdef CONFIG_TASKS_RCU_GENERIC +#include <linux/mm.h> +#include <linux/ratelimit.h> #include "rcu_segcblist.h" ////////////////////////////////////////////////////////////////////////
@@ -339,6 +341,12 @@ static void call_rcu_tasks_iw_wakeup(struct irq_work *iwp) }// Enqueue a callback for the specified flavor of Tasks RCU. +static void rcu_tasks_leak_callback (struct rcu_head *rhp) { } + +static DEFINE_RATELIMIT_STATE(rcu_tasks_dup_rs, + DEFAULT_RATELIMIT_INTERVAL, + DEFAULT_RATELIMIT_BURST); +static void call_rcu_tasks_generic (struct rcu_head *rhp,rcu_callback_t func,struct rcu_tasks *rtp) {
@@ -358,6 +366,17 @@ static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func,if (WARN_ON_ONCE (!func))return ; +if (debug_rcu_head_queue (rhp)) { +if (__ratelimit (&rcu_tasks_dup_rs)) { +pr_err ("%s(): Duplicate CB for %s, %p->%pS()\n" , + __func__, rtp->name, rhp, rhp->func); +mem_dump_obj (rhp); +dump_stack (); + } +WRITE_ONCE (rhp->func, rcu_tasks_leak_callback); +return ; + } + rhp->next =NULL ; rhp->func = func;local_irq_save (flags);
@@ -586,6 +605,7 @@ static void rcu_tasks_invoke_cbs(struct rcu_tasks *rtp, struct rcu_tasks_percpuraw_spin_unlock_irqrestore_rcu_node (rtpcp, flags); len = rcl.len;for (rhp =rcu_cblist_dequeue (&rcl); rhp; rhp =rcu_cblist_dequeue (&rcl)) { +debug_rcu_head_unqueue (rhp);debug_rcu_head_callback (rhp);local_bh_disable (); rhp->func (rhp);
Signature · 1 line
2.43.0
PATCH v2 10/10 rcu: Improve duplicate callback diagnostics
In reply to Kunwu ChanUse ratelimited diagnostics with dump_stack() for duplicate callback detection in rcu_do_enqueue().
--- kernel/rcu/tree.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/rcu/tree.c +7 -2
@@ -25,6 +25,7 @@#include <linux/rcupdate_wait.h> #include <linux/interrupt.h> #include <linux/llist.h> +#include <linux/ratelimit.h> #include <linux/sched.h> #include <linux/sched/debug.h> #include <linux/nmi.h>
@@ -3154,9 +3155,12 @@ static void check_cb_ovld(struct rcu_data *rdp)* already disabled, and a drain of a remote CPU re-issues onto the draining * CPU. */ +static DEFINE_RATELIMIT_STATE(rcu_dup_rs, + DEFAULT_RATELIMIT_INTERVAL, + DEFAULT_RATELIMIT_BURST); +static void rcu_do_enqueue (struct rcu_head *head,rcu_callback_t func,bool lazy_in) { -static atomic_t doublefrees;unsigned long flags;bool lazy;struct rcu_data *rdp;
@@ -3167,9 +3171,10 @@ static void rcu_do_enqueue(struct rcu_head *head, rcu_callback_t func, bool lazy* Use rcu:rcu_callback trace event to find the previous * time callback was passed to call_rcu(). */ -if (atomic_inc_return (&doublefrees) <4 ) { +if (__ratelimit (&rcu_dup_rs)) {pr_err ("%s(): Double-freed CB %p->%pS()!!! " , __func__, head, head->func);mem_dump_obj (head); +dump_stack (); }WRITE_ONCE (head->func, rcu_leak_callback);return ;
Signature · 1 line
2.43.0
Quoted 43 lines · Kunwu Chan
Hi,
This series improves callback diagnostics and validation across RCU, SRCU, and RCU Tasks.
Patches 1-3 record callback registration stacks for KASAN in Tree SRCU, Tiny SRCU, and Tiny RCU. KASAN prints the recorded auxiliary stack when reporting a use-after-free.
Patches 4-6 add
rcu_headalignment and NULL callback-function checks.Patches 7-10 detect duplicate callback enqueue attempts before queueing, using the RCU head debug-object mechanism. A duplicate registration is rejected at entry and
__ratelimit()controls the diagnostic output group (pr_err,mem_dump_obj,dump_stack). Detection requiresCONFIG_DEBUG_OBJECTS_RCU_HEAD.Changes since v1:
- Patches 7-9:__ratelimit()+dump_stack()instead of hard-coded limit
- Patch 10 (new): same change for Tree RCU'srcu_do_enqueue()
- Patch 9: fixed log format to avoid pseudo-function names
- Tags: Reviewed-by (4-6), Suggested-by (7-10)
- v1: https://lore.kernel.org/all/[email protected]/Testing:
rcutorture with KASAN (SRCU-N, SRCU-P, SRCU-T, SRCU-U, TINY01, TINY02, TREE03, 3min each): all exitcode 0.KASAN aux stack (QEMU,
CONFIG_KASAN_GENERIC=y):Last potentially related work creation: kasan_save_stack+0x33/0x60 kasan_record_aux_stack+0x8c/0xa0 call_srcu+0xb2/0x390Duplicate enqueue (QEMU,
CONFIG_DEBUG_OBJECTS_RCU_HEAD=y):call_srcu(): Duplicate call_srcu() CB ... ->cb dump_stack_lvl+0x47/0x60 call_rcu_tasks_generic(): Duplicate CB for RCU Tasks, ... ->cb dump_stack_lvl+0x47/0x60 rcu_do_enqueue(): Double-freed CB ... ->cb slab kmalloc-16 ...
Quoted 11 lines
Kunwu Chan (10):
srcu: Record callback registration stack for KASAN
srcutiny: Record callback registration stack for KASAN
rcu: Record callback registration stack for Tiny RCU
srcu: Validate callback arguments
rcu: Validate callback arguments in Tiny RCU
rcu-tasks: Validate callback arguments
srcu: Detect duplicate callback enqueue at registration
srcutiny: Detect duplicate callback enqueue
rcu-tasks: Detect duplicate callback enqueue
rcu: Improve duplicate callback diagnostics
All look good to me, applying for further testing and review for 7.5. Did you also test double-call-srcu and confirm intended behavior? Thanks!
thanks,
Joel Fernandes
Quoted 13 lines
kernel/rcu/srcutiny.c | 34 ++++++++++++++++++++++++++++++++++ kernel/rcu/srcutree.c | 36 ++++++++++++++++++++++++++++++------ kernel/rcu/tasks.h | 27 +++++++++++++++++++++++++++ kernel/rcu/tiny.c | 11 +++++++++++ kernel/rcu/tree.c | 9 +++++++-- 5 files changed, 109 insertions(+), 8 deletions(-)base-commit:
940793b926aa94bf65ec404043050888e3053188Signature · 1 line
2.43.0
Quoted 58 lines · Joel Fernandes
Quoted 43 lines · Kunwu Chan
Hi,
This series improves callback diagnostics and validation across RCU, SRCU, and RCU Tasks.
Patches 1-3 record callback registration stacks for KASAN in Tree SRCU, Tiny SRCU, and Tiny RCU. KASAN prints the recorded auxiliary stack when reporting a use-after-free.
Patches 4-6 add
rcu_headalignment and NULL callback-function checks.Patches 7-10 detect duplicate callback enqueue attempts before queueing, using the RCU head debug-object mechanism. A duplicate registration is rejected at entry and
__ratelimit()controls the diagnostic output group (pr_err,mem_dump_obj,dump_stack). Detection requiresCONFIG_DEBUG_OBJECTS_RCU_HEAD.Changes since v1:
- Patches 7-9:__ratelimit()+dump_stack()instead of hard-coded limit
- Patch 10 (new): same change for Tree RCU'srcu_do_enqueue()
- Patch 9: fixed log format to avoid pseudo-function names
- Tags: Reviewed-by (4-6), Suggested-by (7-10)
- v1: https://lore.kernel.org/all/[email protected]/Testing:
rcutorture with KASAN (SRCU-N, SRCU-P, SRCU-T, SRCU-U, TINY01, TINY02, TREE03, 3min each): all exitcode 0.KASAN aux stack (QEMU,
CONFIG_KASAN_GENERIC=y):Last potentially related work creation: kasan_save_stack+0x33/0x60 kasan_record_aux_stack+0x8c/0xa0 call_srcu+0xb2/0x390Duplicate enqueue (QEMU,
CONFIG_DEBUG_OBJECTS_RCU_HEAD=y):call_srcu(): Duplicate call_srcu() CB ... ->cb dump_stack_lvl+0x47/0x60 call_rcu_tasks_generic(): Duplicate CB for RCU Tasks, ... ->cb dump_stack_lvl+0x47/0x60 rcu_do_enqueue(): Double-freed CB ... ->cb slab kmalloc-16 ...Quoted 11 lines
Kunwu Chan (10):
srcu: Record callback registration stack for KASAN
srcutiny: Record callback registration stack for KASAN
rcu: Record callback registration stack for Tiny RCU
srcu: Validate callback arguments
rcu: Validate callback arguments in Tiny RCU
rcu-tasks: Validate callback arguments
srcu: Detect duplicate callback enqueue at registration
srcutiny: Detect duplicate callback enqueue
rcu-tasks: Detect duplicate callback enqueue
rcu: Improve duplicate callback diagnostics
Quoted 1 line
Reviewed-by Joel Fernandes <[email protected]>
Thanks, Joel.
Quoted 4 lines
All look good to me, applying for further testing and review for 7.5. Did you also test double-call-srcu and confirm intended behavior? Thanks!
Yes, I tested double call_srcu() under QEMU with CONFIG_DEBUG_OBJECTS_RCU_HEAD=y.
Both Tree SRCU (direct and deferred paths) and Tiny SRCU triggered the expected duplicate-enqueue diagnostic with the callback symbol and dump_stack() output.
BTW, I'm working on follow-up rcutorture support for duplicate-callback testing and
KASAN aux-stack verification.
Thanks for review.
Kunwu
Quoted 18 lines
thanks,
Joel Fernandes
Quoted 13 lines
kernel/rcu/srcutiny.c | 34 ++++++++++++++++++++++++++++++++++ kernel/rcu/srcutree.c | 36 ++++++++++++++++++++++++++++++------ kernel/rcu/tasks.h | 27 +++++++++++++++++++++++++++ kernel/rcu/tiny.c | 11 +++++++++++ kernel/rcu/tree.c | 9 +++++++-- 5 files changed, 109 insertions(+), 8 deletions(-)base-commit:
940793b926aa94bf65ec404043050888e3053188--
2.43.0
Joel Fernandes
maintainerQuoted 64 lines · KunWu Chan
Quoted 58 lines · Joel Fernandes
Quoted 43 lines · Kunwu Chan
Hi,
This series improves callback diagnostics and validation across RCU, SRCU, and RCU Tasks.
Patches 1-3 record callback registration stacks for KASAN in Tree SRCU, Tiny SRCU, and Tiny RCU. KASAN prints the recorded auxiliary stack when reporting a use-after-free.
Patches 4-6 add
rcu_headalignment and NULL callback-function checks.Patches 7-10 detect duplicate callback enqueue attempts before queueing, using the RCU head debug-object mechanism. A duplicate registration is rejected at entry and
__ratelimit()controls the diagnostic output group (pr_err,mem_dump_obj,dump_stack). Detection requiresCONFIG_DEBUG_OBJECTS_RCU_HEAD.Changes since v1:
- Patches 7-9:__ratelimit()+dump_stack()instead of hard-coded limit
- Patch 10 (new): same change for Tree RCU'srcu_do_enqueue()
- Patch 9: fixed log format to avoid pseudo-function names
- Tags: Reviewed-by (4-6), Suggested-by (7-10)
- v1: https://lore.kernel.org/all/[email protected]/Testing:
rcutorture with KASAN (SRCU-N, SRCU-P, SRCU-T, SRCU-U, TINY01, TINY02, TREE03, 3min each): all exitcode 0.KASAN aux stack (QEMU,
CONFIG_KASAN_GENERIC=y):Last potentially related work creation: kasan_save_stack+0x33/0x60 kasan_record_aux_stack+0x8c/0xa0 call_srcu+0xb2/0x390Duplicate enqueue (QEMU,
CONFIG_DEBUG_OBJECTS_RCU_HEAD=y):call_srcu(): Duplicate call_srcu() CB ... ->cb dump_stack_lvl+0x47/0x60 call_rcu_tasks_generic(): Duplicate CB for RCU Tasks, ... ->cb dump_stack_lvl+0x47/0x60 rcu_do_enqueue(): Double-freed CB ... ->cb slab kmalloc-16 ...Quoted 11 lines
Kunwu Chan (10):
srcu: Record callback registration stack for KASAN
srcutiny: Record callback registration stack for KASAN
rcu: Record callback registration stack for Tiny RCU
srcu: Validate callback arguments
rcu: Validate callback arguments in Tiny RCU
rcu-tasks: Validate callback arguments
srcu: Detect duplicate callback enqueue at registration
srcutiny: Detect duplicate callback enqueue
rcu-tasks: Detect duplicate callback enqueue
rcu: Improve duplicate callback diagnosticsQuoted 1 line
Reviewed-by Joel Fernandes <[email protected]>Thanks, Joel.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
All look good to me, applying for further testing and review for 7.5. Did you also test double-call-srcu and confirm intended behavior? Thanks!
Yes, I tested double
call_srcu()under QEMU withCONFIG_DEBUG_OBJECTS_RCU_HEAD=y.
Both Tree SRCU (direct and deferred paths) and Tiny SRCU triggered the expected duplicate-enqueue diagnostic with the callback symbol anddump_stack()output.
Great!
Quoted 4 lines
BTW, I'm working on follow-up rcutorture support for duplicate-callback testing and
KASAN aux-stack verification.
Nice! How is that coming along?
thanks,
Joel Fernandes
Quoted 22 lines
Thanks for review.
KunwuQuoted 18 lines
thanks,
Joel Fernandes
Quoted 13 lines
kernel/rcu/srcutiny.c | 34 ++++++++++++++++++++++++++++++++++ kernel/rcu/srcutree.c | 36 ++++++++++++++++++++++++++++++------ kernel/rcu/tasks.h | 27 +++++++++++++++++++++++++++ kernel/rcu/tiny.c | 11 +++++++++++ kernel/rcu/tree.c | 9 +++++++-- 5 files changed, 109 insertions(+), 8 deletions(-)base-commit:
940793b926aa94bf65ec404043050888e3053188--
2.43.0
Quoted 75 lines · Joel Fernandes
Quoted 64 lines · KunWu Chan
Quoted 58 lines · Joel Fernandes
Quoted 43 lines · Kunwu Chan
Hi,
This series improves callback diagnostics and validation across RCU, SRCU, and RCU Tasks.
Patches 1-3 record callback registration stacks for KASAN in Tree SRCU, Tiny SRCU, and Tiny RCU. KASAN prints the recorded auxiliary stack when reporting a use-after-free.
Patches 4-6 add
rcu_headalignment and NULL callback-function checks.Patches 7-10 detect duplicate callback enqueue attempts before queueing, using the RCU head debug-object mechanism. A duplicate registration is rejected at entry and
__ratelimit()controls the diagnostic output group (pr_err,mem_dump_obj,dump_stack). Detection requiresCONFIG_DEBUG_OBJECTS_RCU_HEAD.Changes since v1:
- Patches 7-9:__ratelimit()+dump_stack()instead of hard-coded limit
- Patch 10 (new): same change for Tree RCU'srcu_do_enqueue()
- Patch 9: fixed log format to avoid pseudo-function names
- Tags: Reviewed-by (4-6), Suggested-by (7-10)
- v1: https://lore.kernel.org/all/[email protected]/Testing:
rcutorture with KASAN (SRCU-N, SRCU-P, SRCU-T, SRCU-U, TINY01, TINY02, TREE03, 3min each): all exitcode 0.KASAN aux stack (QEMU,
CONFIG_KASAN_GENERIC=y):Last potentially related work creation: kasan_save_stack+0x33/0x60 kasan_record_aux_stack+0x8c/0xa0 call_srcu+0xb2/0x390Duplicate enqueue (QEMU,
CONFIG_DEBUG_OBJECTS_RCU_HEAD=y):call_srcu(): Duplicate call_srcu() CB ... ->cb dump_stack_lvl+0x47/0x60 call_rcu_tasks_generic(): Duplicate CB for RCU Tasks, ... ->cb dump_stack_lvl+0x47/0x60 rcu_do_enqueue(): Double-freed CB ... ->cb slab kmalloc-16 ...Quoted 11 lines
Kunwu Chan (10):
srcu: Record callback registration stack for KASAN
srcutiny: Record callback registration stack for KASAN
rcu: Record callback registration stack for Tiny RCU
srcu: Validate callback arguments
rcu: Validate callback arguments in Tiny RCU
rcu-tasks: Validate callback arguments
srcu: Detect duplicate callback enqueue at registration
srcutiny: Detect duplicate callback enqueue
rcu-tasks: Detect duplicate callback enqueue
rcu: Improve duplicate callback diagnosticsQuoted 1 line
Reviewed-by Joel Fernandes <[email protected]>Thanks, Joel.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
All look good to me, applying for further testing and review for 7.5. Did you also test double-call-srcu and confirm intended behavior? Thanks!
Yes, I tested double
call_srcu()under QEMU withCONFIG_DEBUG_OBJECTS_RCU_HEAD=y.
Both Tree SRCU (direct and deferred paths) and Tiny SRCU triggered the expected duplicate-enqueue diagnostic with the callback symbol anddump_stack()output.
Quoted 9 lines
Great!
Quoted 4 lines
BTW, I'm working on follow-up rcutorture support for duplicate-callback testing and
KASAN aux-stack verification.Nice! How is that coming along?
It's currently in testing. I expect to send it out later this week!
Thanks,
Kunwu
Quoted 27 lines
thanks,
Joel Fernandes
Quoted 22 lines
Thanks for review.
KunwuQuoted 18 lines
thanks,
Joel Fernandes
Quoted 13 lines
kernel/rcu/srcutiny.c | 34 ++++++++++++++++++++++++++++++++++ kernel/rcu/srcutree.c | 36 ++++++++++++++++++++++++++++++------ kernel/rcu/tasks.h | 27 +++++++++++++++++++++++++++ kernel/rcu/tiny.c | 11 +++++++++++ kernel/rcu/tree.c | 9 +++++++-- 5 files changed, 109 insertions(+), 8 deletions(-)base-commit:
940793b926aa94bf65ec404043050888e3053188--
2.43.0