Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Qihang <q.h.hack.winter@gmail.com>
To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>
Cc: Qihang <q.h.hack.winter@gmail.com>,
	Robin Murphy <robin.murphy@arm.com>,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH 1/2] iommu/io-pgfault: unlink partial faults before freeing them
Date: Tue, 17 Nov 2026 09:54:08 +0800	[thread overview]
Message-ID: <20261117015409.25492-2-q.h.hack.winter@gmail.com> (raw)
In-Reply-To: <20261117015409.25492-1-q.h.hack.winter@gmail.com>

iopf_queue_remove_device() frees the pending partial faults without
unlinking them, so fault_param->partial keeps pointing into freed
memory.  A report that is still in flight can then list_add() through
those dangling pointers.  The unlink has been missing since
iopf_queue_remove_device() was first added, but the race only became
reachable with a74c077b9021, which made the fault parameter
refcounted and able to outlive the removal.

Unlink each entry before freeing it, matching
iopf_queue_discard_partial().

This fixes the dangling-list access only: a partial that arrives after
the drain now leaks, because the parameter is no longer on
queue->devices and its final put does not free partial faults.  The
next patch gives such a partial a defined fate.

Fixes: a74c077b9021 ("iommu: Use refcount for fault data access")
Cc: stable@vger.kernel.org
Signed-off-by: Qihang <q.h.hack.winter@gmail.com>
---
iopf_queue_discard_partial() cannot be called directly from here: it
takes queue->lock, which iopf_queue_remove_device() already holds.

 drivers/iommu/io-pgfault.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/io-pgfault.c b/drivers/iommu/io-pgfault.c
index c16ff1f..55a3c29 100644
--- a/drivers/iommu/io-pgfault.c
+++ b/drivers/iommu/io-pgfault.c
@@ -479,8 +479,10 @@ void iopf_queue_remove_device(struct iopf_queue *queue, struct device *dev)
 		goto unlock;
 
 	mutex_lock(&fault_param->lock);
-	list_for_each_entry_safe(partial_iopf, next, &fault_param->partial, list)
+	list_for_each_entry_safe(partial_iopf, next, &fault_param->partial, list) {
+		list_del(&partial_iopf->list);
 		kfree(partial_iopf);
+	}
 
 	list_for_each_entry_safe(group, temp, &fault_param->faults, pending_node) {
 		struct iopf_fault *iopf = &group->last_fault;

       reply	other threads:[~2026-11-17  1:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261117015409.25492-1-q.h.hack.winter@gmail.com>
2026-11-17  1:54 ` Qihang [this message]
2026-11-17  1:54 ` [PATCH 2/2] iommu/io-pgfault: reject partial faults after the device is removed Qihang

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=20261117015409.25492-2-q.h.hack.winter@gmail.com \
    --to=q.h.hack.winter@gmail.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=will@kernel.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