Re: [PATCH v2] irq_work: Fix use-after-free in irq_work_single on PREEMPT_RT
From: Sebastian Andrzej Siewior
Date: Tue Dec 01 2026 - 03:41:48 EST
On 2026-12-01 08:41:02 [+0100], To Vlastimil Babka (SUSE) wrote:
> On 2026-11-27 21:44:52 [+0100], Vlastimil Babka (SUSE) wrote:
> > Hi,
> >
> > for slab we recently got proposed the AI fix below. While it seems correct
> > to me, it feels wrong to do such an ad-hoc workaround. I'd expect there
> > would be other cases where the work is static and no UAF can exist. Can we
> > accomodate them in a generic way? Thanks.
>
> Something like the below with the move of static_obj() to somewhere in
> mm/?
>
> diff --git a/kernel/irq_work.c b/kernel/irq_work.c
> index 73eabcbdcd50c..4e26a4ecdad8c 100644
> --- a/kernel/irq_work.c
> +++ b/kernel/irq_work.c
> @@ -305,7 +305,8 @@ void irq_work_sync(struct irq_work *work)
> * after removing IRQ_WORK_BUSY. It is always
> * accessed within a RCU-read section.
> */
> - synchronize_rcu();
> + if (!static_obj(&work->irqwait))
> + synchronize_rcu();
> return;
> }
I had this in quick testing and it almost hit nothing (as in avoided a
synchronize_rcu()). I got deferred_work_barrier() a few times after a
rmmod btrfs. I got sched_mm_cid_exit() which is non-static way more
often.
Initially I suggested this synchronize_rcu() and a RCU section because
almost everything was in place and cancel+ irq_work_sync() should not
happen *that* often. But it is more often than I expected.
There I am thinking to revive Jiayuan's original patch and solve this
issue without synchronize_rcu() and the need for a RCU read section.
This would avoid both issues.
Sebastian