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=1793831473; b=OC4i2/0q0OwnqPiJ+JWdPWh7mrC3Uy+X0PLrJfwcSUpJIPTCgwqwSSMF9VobFew1ODb5 rg5FxuU68LanzmR0l4WKZc1wsi3NT8vRn+BlhncttBhAYkwOLFuWD7R8Ji+WPDhXJ2/dW SgQMAuSY0cVZ+MGUqQ4r7eLNIfb6WKFkVH0qJnKc26TEBSZXZcLGWf7McF2p5QCZ6ZfDP dXtVTg9xS3xdG2HA2fqGLR4xDwosIVMfrs4l9GpLgwomiMDP1chQe0WoDGq1GBcyHSVWa hvt165Z8o4jRY1jCA9tf2vBe776MAiS7pU3fqkT6gMPIWJ12EvVgtw/FhIMsqb9U9jA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793831473; 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=RFqpSsxNZx3ARjIhBVshtO8ukGiqj9zbDf/2/e3kk8E=; b=buU3cFr8C1ODLIO3zN+yZywkLpETfmnjQ5fNLN6v0DBUZZpDZi/blHR9z/iOjcsPMe2m rRq//etI41q7EPQoPuXd3XUW6Z479nuxgcj/uoOXBTTbtLQD7+x358v9ZRM+qGa1cFIA4 hcK98Ck+w+bow69GKc31Yzg+QPuAp12y4QCFl0MMA5l3wBaHZoOYCvbVAcTqWnVcLYeht UbouedksYCDODO3gQahnAW7w9exDmkNoAAy6NB+V9+l4q+oGNplBHFpUG8ocyuI2n3ga2 AiWqNP4XeaRCrIEe+tCqN/X8pWHLS23xAo34IqRa2eqz8hv/JCpOKMZL9ohrDpvhXfQ== 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=iASvbRHk; 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 40EF2606AC2A; Wed, 4 Nov 2026 22:31:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=iASvbRHk Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF3B81F00919; Wed, 4 Nov 2026 22:31:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793831468; bh=RFqpSsxNZx3ARjIhBVshtO8ukGiqj9zbDf/2/e3kk8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iASvbRHkqYEWgdOZ4t1fVGJRWk2shUm9v201rV5GAR1lmiWnq5w6ZN0JShnzwkAp2 ebMglZZrsVEBuUeZmhxDS2pdGonqudfpq7ORBTFzRksmohc8bmS6EteaedPDkWZtxZ Cbp2haarpzbVYHwxZCtr2xaeD2Lpl8G3bQVqwy9Y= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Richard Patel , Thomas Gleixner Subject: [PATCH 6.18 0714/1005] genirq: Defer kfree(irqaction) until irq_thread_dtor() finishes Date: Wed, 4 Nov 2026 16:07:27 -0500 Message-ID: <20261104211103.546434022@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261104211043.516122098@linuxfoundation.org> References: <20261104211043.516122098@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Richard Patel commit d04adff6860587e843948b0c31174f8ae11b8dfe upstream. 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 Signed-off-by: Greg Kroah-Hartman --- kernel/irq/internals.h | 2 ++ kernel/irq/manage.c | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -31,6 +31,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, @@ -38,6 +39,7 @@ enum { IRQTF_AFFINITY, IRQTF_FORCED_THREAD, IRQTF_READY, + IRQTF_EXIT_WORK, }; /* --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "internals.h" @@ -1173,17 +1174,14 @@ void wake_threads_waitq(struct irq_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); @@ -1200,6 +1198,14 @@ static void irq_thread_dtor(struct callb 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; @@ -1257,6 +1263,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); @@ -1277,6 +1284,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; } @@ -1811,6 +1819,12 @@ out_mput: return ret; } +static void irq_stop_thread(struct irqaction *action) +{ + kthread_stop_put(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. @@ -1915,9 +1929,9 @@ static struct irqaction *__free_irq(stru * the same bit to a newly requested action. */ if (action->thread) { - kthread_stop_put(action->thread); + irq_stop_thread(action); if (action->secondary && action->secondary->thread) - kthread_stop_put(action->secondary->thread); + irq_stop_thread(action->secondary); } /* Last action releases resources */