From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795044788; b=A6Fyw2kTD/fObDL+wOzbQAwM6w6JLV3Qp9K4vi/sUvgaqAnhn2YmdXjQprcPrtVY1Hok DVduzfqTbe2xHvSJDqx+uNgzpiLxC9ERuU45L205QAooOSEO2W6guLvf6cAvdQkwPEqxE uoTDA2QL3ZrDmWrmugUuNu1r2USq4VpP+/9X1BYg339Ztx4webiYxN3k2UIQgApDDaqTq UdGaQhlvdx9CRtLJ9s726nUoZkC6JpdMAQokTDVF0piKwa7Ckz8YF5l2Lfd4XGoe5Gt2i c+c5IRchtIUgK0cowadol2LT3HAszy/ADUxpvCYg0P/SXKSlx+WlS8MsEKY5/Nc1msQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795044788; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=o9BZ7O21pdo9OSVNJhq5oCX47G8h2HRb9039luavBI8=; b=qIJd/iVy6BsYJnL3zbNg+lGVRtDWlRAOJIrGIyMNNxWt8dTCFQb/pS0R8NgsdBEWiNns ETSsH6SD72KKOfXp91MgcbqWk5yLJCHEZMcn+ulSLDwEeeJF622Ldp3Hh2UMS3Rr4IMA2 YN/R9OaR2MKme2tmN0haJxixs0FtNYbUCm1cHkprPB2g4sOItn6KBbyP6LrGDvVbWpp8f Dq/mAMK2g3TqoAL9wFK2TLi4cdzXk0zYJVa0v8YDy3w/PE3xLu0ytBiZPVvS7PhfCRzod nERU0eKaBmnFgkm/OjcvuTWQ77FC9RYaYirLOk52O+eJMKvOQVY1We6RJAsYczsM8jA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=VjTRTDv8; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C4A8606D673; Wed, 18 Nov 2026 23:33:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=VjTRTDv8 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55CE91F000C4; Wed, 18 Nov 2026 23:33:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795044787; bh=o9BZ7O21pdo9OSVNJhq5oCX47G8h2HRb9039luavBI8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VjTRTDv8gT8Ta5suZko/8oGw1qGUzgqNO5jVj4XCFUk1XxD6WPdysw5RE5UpJ51Ee T9PZbFFDrbgcKAIpXP1CFus7hzusoclR7oQVNkzY7+0++Cr83pnZSs0MP7dQGjCJbs qsRSwALx2sOXCErfEHNAIWraMMrXoQ0J7mlqqVKE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Richard Patel , Thomas Gleixner , Sasha Levin Subject: [PATCH 6.1 0693/2857] genirq: Defer kfree(irqaction) until irq_thread_dtor() finishes Date: Wed, 18 Nov 2026 15:28:47 +0100 Message-ID: <20261118150226.511330534@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150201.293410965@linuxfoundation.org> References: <20261118150201.293410965@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Richard Patel [ Upstream commit d04adff6860587e843948b0c31174f8ae11b8dfe ] When an interrupt thread exits abnormally via do_exit() (e.g. the interrupt handler oopses) without returning from irq_thread(), a concurrent call to free_irq() could free the irqaction before the irq_thread_dtor() exit task work runs. irq thread (oopsed) free_irq() ------------------- ---------- do_exit() exit_mm() complete_vfork_done() -------> kthread_stop() returns exit_files() ... kfree(action) exit_task_work() irq_thread_dtor() action->... <- use-after-free Track the pending exit work with the IRQTF_EXIT_WORK thread flag, and have __free_irq() wait for the bit to clear before kfree(). irq_thread_dtor() only runs on irq_thread abnormal exit. If that dtor also faults, free_irq() will hang indefinitely, but double IRQ thread faults require a reboot anyways. [ tglx: Add missing include ] Fixes: ed3e694d78cc ("move exit_task_work() past exit_files() et.al.") Signed-off-by: Richard Patel Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261009145842.1616117-2-ripatel@wii.dev [ sashal: Replaced unavailable kthread_stop_put() with kthread_stop() followed by put_task_struct(). ] Signed-off-by: Sasha Levin --- kernel/irq/internals.h | 2 ++ kernel/irq/manage.c | 32 ++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index 35e85323940c3..7f1b7c1534d18 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -30,6 +30,7 @@ extern struct irqaction chained_action; * IRQTF_AFFINITY - irq thread is requested to adjust affinity * IRQTF_FORCED_THREAD - irq action is force threaded * IRQTF_READY - signals that irq thread is ready + * IRQTF_EXIT_WORK - irq thread exit task_work is pending */ enum { IRQTF_RUNTHREAD, @@ -37,6 +38,7 @@ enum { IRQTF_AFFINITY, IRQTF_FORCED_THREAD, IRQTF_READY, + IRQTF_EXIT_WORK, }; /* diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index a5843563d0154..8827e7cb7166e 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "internals.h" @@ -1216,17 +1217,14 @@ static void wake_threads_waitq(struct irq_desc *desc) wake_up(&desc->wait_for_threads); } -static void irq_thread_dtor(struct callback_head *unused) +static void __irq_thread_dtor(struct irqaction *action) { struct task_struct *tsk = current; struct irq_desc *desc; - struct irqaction *action; if (WARN_ON_ONCE(!(current->flags & PF_EXITING))) return; - action = kthread_data(tsk); - pr_err("exiting task \"%s\" (%d) is an active IRQ thread (irq %d)\n", tsk->comm, tsk->pid, action->irq); @@ -1243,6 +1241,14 @@ static void irq_thread_dtor(struct callback_head *unused) irq_finalize_oneshot(desc, action); } +static void irq_thread_dtor(struct callback_head *unused) +{ + struct irqaction *action = kthread_data(current); + + __irq_thread_dtor(action); + clear_and_wake_up_bit(IRQTF_EXIT_WORK, &action->thread_flags); +} + static void irq_wake_secondary(struct irq_desc *desc, struct irqaction *action) { struct irqaction *secondary = action->secondary; @@ -1301,6 +1307,7 @@ static int irq_thread(void *data) else handler_fn = irq_thread_fn; + set_bit(IRQTF_EXIT_WORK, &action->thread_flags); init_task_work(&on_exit_work, irq_thread_dtor); task_work_add(current, &on_exit_work, TWA_NONE); @@ -1325,6 +1332,7 @@ static int irq_thread(void *data) * oneshot mask bit can be set. */ task_work_cancel_func(current, irq_thread_dtor); + clear_and_wake_up_bit(IRQTF_EXIT_WORK, &action->thread_flags); return 0; } @@ -1859,6 +1867,13 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) return ret; } +static void irq_stop_thread(struct irqaction *action) +{ + kthread_stop(action->thread); + put_task_struct(action->thread); + wait_on_bit(&action->thread_flags, IRQTF_EXIT_WORK, TASK_UNINTERRUPTIBLE); +} + /* * Internal function to unregister an irqaction - used to free * regular and special interrupts that are part of the architecture. @@ -1963,12 +1978,9 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id) * the same bit to a newly requested action. */ if (action->thread) { - kthread_stop(action->thread); - put_task_struct(action->thread); - if (action->secondary && action->secondary->thread) { - kthread_stop(action->secondary->thread); - put_task_struct(action->secondary->thread); - } + irq_stop_thread(action); + if (action->secondary && action->secondary->thread) + irq_stop_thread(action->secondary); } /* Last action releases resources */ -- 2.53.0