mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: Jan Kiszka <jan.kiszka@siemens.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Harry Yoo <harry@kernel.org>
Cc: Jiayuan Chen <jiayuan.chen@linux.dev>,
	linux-rt-devel@lists.linux.dev,
	Steven Rostedt <rostedt@goodmis.org>,
	Clark Williams <clrkwllms@kernel.org>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	linux-kernel@vger.kernel.org,
	Florian Bezdeka <florian.bezdeka@siemens.com>
Subject: Re: [PATCH v2] irq_work: Fix use-after-free in irq_work_single on PREEMPT_RT
Date: Fri, 27 Nov 2026 21:44:52 +0100	[thread overview]
Message-ID: <5c553fca-3a7a-4bd6-b41a-00594f854440@kernel.org> (raw)
In-Reply-To: <60887e69-ae28-495c-a6d7-7d0a94fd1aa8@siemens.com>

On 8/19/26 13:46, Jan Kiszka wrote:
> On 19.08.26 12:52, Sebastian Andrzej Siewior wrote:
>> On 2026-08-19 12:44:57 [+0200], Jan Kiszka wrote:
>>> With this patch, arm 32-bit, and a single-core SoC, I got a noticeable
>>> slowdown of irq_work_sync. Reverting the patch resolves this. So I dug
>>> deeper, found out that things were even worse before [1], but even with
>>> that, I could still see up to 2 ticks delay per call. If you combine
>>> that with an unfortunate loop of irq_work_sync calls (mine is
>>> out-of-tree, but I see something even "worse" in bpf_mem_alloc_destroy),
>>> there is this impact.
>>>
>>> While this patch is motivated by PREEMPT_RT, the condition to enter the
>>> modified branch are not limited to it:
>> 
>> It is not motivated by PREEMPT_RT. All the lazy-work has "this" problem.
>> It is just on RT most of the work is stuffed into the lazy queue.
> 
> I was suspecting that already, but the patch description still reads
> rt-only.
> 
>> 
>>> ... || !arch_irq_work_has_interrupt()
>>>
>>> arch_irq_work_has_interrupt() is false on some archs, either always
>>> (very rare) or under certain conditions. On arm, it's false when
>>> is_smp() is false.
>>>
>>> If we "only" need the synchronize_rcu() for PREEMPT_RT, should we limit
>>> it to that configuration? Or do we actually need otherwise as well?
>>>
>>> And what could be done to accelerate irq_work_sync loops? Practically, a
>>> single synchronize_rcu() at the end could be enough, no?
>> 
>> Let me look into this again…
>> 
> 
> Thanks!
> 
> I was meanwhile considering to backport the synchronize_rcu accelerator
> commit. Seems to be straightforward for 6.12, but older kernels need more...
> 
> Jan
 
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.

----8<----
From: Chris Mason <mason@kernel.org>

On PREEMPT_RT, or on an architecture without an irq_work interrupt,
destroying a slab cache stalls for two RCU grace periods per possible
CPU. kvfree_rcu_barrier() stalls for one grace period per possible CPU.
Tasks that do either at the same time also wait for each other.

deferred_work_barrier() calls irq_work_sync() on the deferred work of
each possible CPU. kmem_cache_destroy() calls the barrier twice, and
kvfree_rcu_barrier() calls it once.

Commit 91840be8f710 ("irq_work: Fix use-after-free in
irq_work_single() on PREEMPT_RT") added a synchronize_rcu() at the end
of irq_work_sync(), so that the caller can free the work afterwards.
Only the kernels named above have it, since irq_work_sync() sleeps on
them instead of spinning. Before that commit irq_work_sync() returned at
once for an idle work. Now it waits for a grace period for an idle work
too.

But the deferred works are static per-CPU data that nobody frees, so the
use-after-free that the grace period prevents cannot happen here. The
barrier also runs its whole loop under a global mutex, added by
"mm/slab: serialize deferred_work_barrier()".

The fix used here is to call irq_work_sync() only for a work that is
busy.

Fixes: 91840be8f710 ("irq_work: Fix use-after-free in irq_work_single() on PREEMPT_RT")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
 mm/slub.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 3b8ac5310d07f..3318e94350947 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -6624,8 +6624,17 @@ void deferred_work_barrier(void)
 	/* irq_work_sync() may use rcuwait that requires serialization */
 	guard(mutex)(&barrier_mutex);
 
-	for_each_possible_cpu(cpu)
-		irq_work_sync(&per_cpu_ptr(&deferred_percpu_work, cpu)->work);
+	for_each_possible_cpu(cpu) {
+		struct irq_work *work;
+
+		work = &per_cpu_ptr(&deferred_percpu_work, cpu)->work;
+		/*
+		 * irq_work_sync() may end in synchronize_rcu(), for callers
+		 * that free the work. Ours is static, so skip it while idle.
+		 */
+		if (irq_work_is_busy(work))
+			irq_work_sync(work);
+	}
 }
 
 static __fastpath_inline
-- 
2.56.1



      reply	other threads:[~2026-11-27 20:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-30  7:32 Jiayuan Chen
2026-04-02  6:50 ` Sebastian Andrzej Siewior
2026-06-05 10:31   ` Xi Ruoyao
2026-06-05 10:45     ` Sebastian Andrzej Siewior
2026-06-05 17:26       ` Xi Ruoyao
2026-05-11 14:31 ` [tip: irq/urgent] irq_work: Fix use-after-free in irq_work_single() " tip-bot2 for Jiayuan Chen
2026-08-19 10:44 ` [PATCH v2] irq_work: Fix use-after-free in irq_work_single " Jan Kiszka
2026-08-19 10:52   ` Sebastian Andrzej Siewior
2026-08-19 11:46     ` Jan Kiszka
2026-11-27 20:44       ` Vlastimil Babka (SUSE) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5c553fca-3a7a-4bd6-b41a-00594f854440@kernel.org \
    --to=vbabka@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=clrkwllms@kernel.org \
    --cc=florian.bezdeka@siemens.com \
    --cc=harry@kernel.org \
    --cc=jan.kiszka@siemens.com \
    --cc=jiayuan.chen@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®