All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] iommu/io-pgfault: reject partial faults after device removal
@ 2026-11-17  1:54 Qihang
  2026-11-17  1:54 ` [PATCH 1/2] iommu/io-pgfault: unlink partial faults before freeing them Qihang
  2026-11-17  1:54 ` [PATCH 2/2] iommu/io-pgfault: reject partial faults after the device is removed Qihang
  0 siblings, 2 replies; 3+ messages in thread
From: Qihang @ 2026-11-17  1:54 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon; +Cc: Qihang, Robin Murphy, iommu, linux-kernel

iopf_queue_remove_device() kfree()s the entries on
fault_param->partial without unlinking them, leaving the list head
pointing into freed memory.  Since a74c077b9021 the fault parameter is
refcounted and can outlive the drain, a report that took its reference
earlier can still list_add() through those pointers.  Unlinking
instead turns that into a leak: the late node lands on a parameter
that is no longer on queue->devices, whose final put does not free
partial faults.

This needs a device removed from its iopf queue while a non-last
(partial) request is in flight, with the caller not blocking new reports
for the duration.

Patch 1 unlinks each partial before freeing it, matching
iopf_queue_discard_partial().

Patch 2 adds fault_param->removing, set and tested under
fault_param->lock: a late partial is either drained, or rejected and
freed by report_partial_fault() (-ENODEV).  It covers partial-list
admission only; callers must still quiesce reports for the remaining
lifetimes.

Both patches are scoped to fault_param->partial, not the group path,
the attach handle, or paths that never call iopf_queue_remove_device().

Verified on v7.4-rc3 with KASAN + DEBUG_LIST and the iommufd mock
driver, its caller-side IOPF serialization deliberately removed and
test-only delays added; this shows the mechanism, not production
reachability.  The runs cover queue-before-removal,
removal-before-insertion, concurrent late reporters and re-enable.
Each round queues one partial before the removal and then races the
late reporters against the drain, so a clean run ends with every node
accounted for: 1800 = 900 + 900 and 3600 = 900 + 2700 (allocated =
drained + rejected), counted at a final removal with no reporter in
flight.  Nothing was left on fault_param->partial and KASAN stayed
quiet.

With patch 1 reverted, the report is:

  BUG: KASAN: slab-use-after-free in __list_add_valid_or_report
  Freed by task 1: kfree <- iopf_queue_remove_device
  56 bytes inside a freed 64-byte region (struct iopf_fault, list.prev)

With patch 1 only, the same reproducer runs 1460 rounds without a KASAN
report and leaks one late node per round, which patch 2 addresses.

Reachability on an unmodified production kernel, and any security
impact, remain unconfirmed: the test shows memory corruption and a
KASAN panic on the modified mock driver, not a user-triggerable bug on
a stock kernel.

An AI coding assistant helped find this defect and build the
reproducer and instrumentation, which are available on request along
with the KASAN logs.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-17  1:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17  1:54 [PATCH 0/2] iommu/io-pgfault: reject partial faults after device removal Qihang
2026-11-17  1:54 ` [PATCH 1/2] iommu/io-pgfault: unlink partial faults before freeing them Qihang
2026-11-17  1:54 ` [PATCH 2/2] iommu/io-pgfault: reject partial faults after the device is removed Qihang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.