diff options
| author | David Hildenbrand (Arm) <david@kernel.org> | 2026-11-12 23:53:23 +0100 |
|---|---|---|
| committer | David Hildenbrand (Arm) <david@kernel.org> | 2026-11-14 16:36:05 +0100 |
| commit | b8ba6cc9943222676d46ac77d3d3de2685a55bf8 (patch) | |
| tree | 67014ae9a4c6b79dbdcca584119489edebb459c6 /kernel/debug/debug_core.c | |
| parent | 317bd7d28b248fd4d4e14614d7c30b17a36ef4d7 (diff) | |
iommufd: fix cleanup when adding memfd folio pins fails
folio_add_pins() can fail after memfd_pin_folios() succeeded pinning a
folio. Upcoming folio refcount limit checks will make this easier to
trigger.
Let's fix three problems in the error handling:
1. pfn_reader_release_pins() uses the allocated array size instead of the
number of folios returned by memfd_pin_folios(). With large folios,
cleanup can unpin uninitialized entries. Remember the number of returned
folios and use that during cleanup.
2. pin_memfd_pages() returns on failure without releasing the pins acquired
by the current call. Release the per-page pins for folios already
expanded into the page array, and the single pins for the remaining
folios.
3. pfn_reader_next() returns on failure before updating batch_end_index,
even if the batch already contains successfully expanded folios. Update
it before propagating the error so cleanup releases those pins as well.
Fixes: 92687c793644 ("iommufd: pfn_reader for file mappings")
Cc: stable@vger.kernel.org
Reviewed-by: Lance Yang <lance.yang@linux.dev>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://patch.msgid.link/20261112-refcount_overflow_stable-v4-4-ad3deef0bd23@kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Diffstat (limited to 'kernel/debug/debug_core.c')
0 files changed, 0 insertions, 0 deletions
