[PATCH v2] irq_work: Fix use-after-free in irq_work_run_cpu() on PREEMPT_RT

From: Andrea Parri

Date: Tue Dec 01 2026 - 08:25:40 EST


On PREEMPT_RT, irq_work_sync() relies on synchronize_rcu() for
!IRQ_WORK_HARD_IRQ items, because irq_work_single() still touches @work
after clearing IRQ_WORK_BUSY. run_irq_workd() holds the RCU read lock
for that, but irq_work_run_cpu(), which runs a dead CPU's lazy items in
preemptible task context, does not. If it is preempted right after
clearing IRQ_WORK_BUSY, irq_work_sync() can return and the caller can
free @work while irq_work_single() still uses it.

Hold the RCU read lock in irq_work_run_cpu(), as run_irq_workd() does.

The fix, the changelog and the test were written with the help of an
LLM.

Fixes: 40dcc9bdbef3 ("irq_work: Flush lazy work CPU down on PREEMPT_RT")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://sashiko.dev/#/patchset/20260911143815.997254-1-bigeasy@xxxxxxxxxxxxx?part=2
Signed-off-by: Andrea Parri <parri.andrea@xxxxxxxxx>
---
Changes in v2:
- Shorten the changelog (Sebastian).

v1: https://lore.kernel.org/all/20261130093411.5582-1-parri.andrea@xxxxxxxxx/

kernel/irq_work.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/kernel/irq_work.c b/kernel/irq_work.c
index 73eabcbdcd50c..121f604569d17 100644
--- a/kernel/irq_work.c
+++ b/kernel/irq_work.c
@@ -271,6 +271,7 @@ void irq_work_run_cpu(unsigned int cpu)
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
return;

+ guard(rcu)();
irq_work_run_list(per_cpu_ptr(&lazy_list, cpu));
}

--
2.53.0