From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0FB32FD7C3; Thu, 28 May 2026 20:24:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779999887; cv=none; b=VnNxvLgzOpF7o/+Njlt/ynx7VjwKNZtiTlb6hGQSG9mfYiyEanqg1t01Nt4F/PFDoP1UuZhql2fdDsQy1/jXqxC1N6m3dLvrK/7qNGa73NFHwTtvGTAh/i9mNCg4ZTtlLo4bksRkDjdagfnOcBeLVX7I8nsQnyLEQj43bgcuk2U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779999887; c=relaxed/simple; bh=m/Uk/DJlaoAt7MtKwPDu4IGHpp8MIkF4PgVummuZpas=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kLpVEh/wryh7MMhJcN7+7TVKL48TAgxi2904wGMVlpt3RJR06oxncd0oMs3XzC4lJEMqkZvvCL5qPanB256FAYIanytdKVgzaY/btfy9jHg7m2EncSxdkyKssJvWtdx42owvYdMfME+fYn0dNJna3MXDPoSnw+8hJq9GKe9XHrg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JnYpckib; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="JnYpckib" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFAF91F000E9; Thu, 28 May 2026 20:24:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1779999886; bh=MOS/FMVOjUyWQUwK5zCrR66sOV412kc9OmbFN6HkJuk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JnYpckibo7eRTx73nt5lBJo3H94GaOhlTHdhoUxig6XvoI4/sObhLIcmRol7urwWS 17zkPN4nav/uRW8kAW1gogbxH0piZxHHhlnYMqgNrY2Lx1XrCzcxsx6kIOFlRmmXPX tlUbImd5ZwdSjiBQzl3SvfRiBTAd3e4tXtsYYy7A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sebastian Andrzej Siewior , Steven Rostedt , Jiayuan Chen , Thomas Gleixner , Sasha Levin Subject: [PATCH 6.18 225/377] irq_work: Fix use-after-free in irq_work_single() on PREEMPT_RT Date: Thu, 28 May 2026 21:47:43 +0200 Message-ID: <20260528194644.905771180@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260528194638.371537336@linuxfoundation.org> References: <20260528194638.371537336@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiayuan Chen [ Upstream commit 91840be8f710370607f949a627e070896faeddb8 ] On PREEMPT_RT, non-HARD irq_work runs in per-CPU kthreads via run_irq_workd(), so irq_work_sync() uses rcuwait() to wait for BUSY==0. After irq_work_single() clears BUSY via atomic_cmpxchg(), it still dereferences @work for irq_work_is_hard() and rcuwait_wake_up(). An irq_work_sync() caller on another CPU that enters after BUSY is cleared can observe BUSY==0 immediately, return, and free the work before those accesses complete — causing a use-after-free. Fix this by wrapping run_irq_workd() in guard(rcu)() so that the entire irq_work_single() execution is within an RCU read-side critical section. Then add synchronize_rcu() in irq_work_sync() after rcuwait_wait_event() to ensure the caller waits for the RCU grace period before returning, preventing premature frees. Fixes: 810979682ccc ("irq_work: Allow irq_work_sync() to sleep if irq_work() no IRQ support.") Suggested-by: Sebastian Andrzej Siewior Suggested-by: Steven Rostedt Signed-off-by: Jiayuan Chen Signed-off-by: Thomas Gleixner Reviewed-by: Sebastian Andrzej Siewior Link: https://patch.msgid.link/20260330073234.303732-1-jiayuan.chen@linux.dev Signed-off-by: Sasha Levin --- kernel/irq_work.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/irq_work.c b/kernel/irq_work.c index 73f7e1fd4ab4d..bf411656c3160 100644 --- a/kernel/irq_work.c +++ b/kernel/irq_work.c @@ -292,6 +292,12 @@ void irq_work_sync(struct irq_work *work) !arch_irq_work_has_interrupt()) { rcuwait_wait_event(&work->irqwait, !irq_work_is_busy(work), TASK_UNINTERRUPTIBLE); + /* + * Ensure irq_work_single() does not access @work + * after removing IRQ_WORK_BUSY. It is always + * accessed within a RCU-read section. + */ + synchronize_rcu(); return; } @@ -302,6 +308,7 @@ EXPORT_SYMBOL_GPL(irq_work_sync); static void run_irq_workd(unsigned int cpu) { + guard(rcu)(); irq_work_run_list(this_cpu_ptr(&lazy_list)); } -- 2.53.0