linux-yocto/drivers/iommu
Jason Gunthorpe e482536828 iommufd: Fix race during abort for file descriptors
[ Upstream commit 4e034bf045b12852a24d5d33f2451850818ba0c1 ]

fput() doesn't actually call file_operations release() synchronously, it
puts the file on a work queue and it will be released eventually.

This is normally fine, except for iommufd the file and the iommufd_object
are tied to gether. The file has the object as it's private_data and holds
a users refcount, while the object is expected to remain alive as long as
the file is.

When the allocation of a new object aborts before installing the file it
will fput() the file and then go on to immediately kfree() the obj. This
causes a UAF once the workqueue completes the fput() and tries to
decrement the users refcount.

Fix this by putting the core code in charge of the file lifetime, and call
__fput_sync() during abort to ensure that release() is called before
kfree. __fput_sync() is a bit too tricky to open code in all the object
implementations. Instead the objects tell the core code where the file
pointer is and the core will take care of the life cycle.

If the object is successfully allocated then the file will hold a users
refcount and the iommufd_object cannot be destroyed.

It is worth noting that close(); ioctl(IOMMU_DESTROY); doesn't have an
issue because close() is already using a synchronous version of fput().

The UAF looks like this:

    BUG: KASAN: slab-use-after-free in iommufd_eventq_fops_release+0x45/0xc0 drivers/iommu/iommufd/eventq.c:376
    Write of size 4 at addr ffff888059c97804 by task syz.0.46/6164

    CPU: 0 UID: 0 PID: 6164 Comm: syz.0.46 Not tainted syzkaller #0 PREEMPT(full)
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/18/2025
    Call Trace:
     <TASK>
     __dump_stack lib/dump_stack.c:94 [inline]
     dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:120
     print_address_description mm/kasan/report.c:378 [inline]
     print_report+0xcd/0x630 mm/kasan/report.c:482
     kasan_report+0xe0/0x110 mm/kasan/report.c:595
     check_region_inline mm/kasan/generic.c:183 [inline]
     kasan_check_range+0x100/0x1b0 mm/kasan/generic.c:189
     instrument_atomic_read_write include/linux/instrumented.h:96 [inline]
     atomic_fetch_sub_release include/linux/atomic/atomic-instrumented.h:400 [inline]
     __refcount_dec include/linux/refcount.h:455 [inline]
     refcount_dec include/linux/refcount.h:476 [inline]
     iommufd_eventq_fops_release+0x45/0xc0 drivers/iommu/iommufd/eventq.c:376
     __fput+0x402/0xb70 fs/file_table.c:468
     task_work_run+0x14d/0x240 kernel/task_work.c:227
     resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
     exit_to_user_mode_loop+0xeb/0x110 kernel/entry/common.c:43
     exit_to_user_mode_prepare include/linux/irq-entry-common.h:225 [inline]
     syscall_exit_to_user_mode_work include/linux/entry-common.h:175 [inline]
     syscall_exit_to_user_mode include/linux/entry-common.h:210 [inline]
     do_syscall_64+0x41c/0x4c0 arch/x86/entry/syscall_64.c:100
     entry_SYSCALL_64_after_hwframe+0x77/0x7f

Link: https://patch.msgid.link/r/1-v1-02cd136829df+31-iommufd_syz_fput_jgg@nvidia.com
Cc: stable@vger.kernel.org
Fixes: 07838f7fd5 ("iommufd: Add iommufd fault object")
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Nirmoy Das <nirmoyd@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Reported-by: syzbot+80620e2d0d0a33b09f93@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/r/68c8583d.050a0220.2ff435.03a2.GAE@google.com
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
[ Adjust context ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-10-02 13:48:40 +02:00
..
amd iommu/amd: Fix alias device DTE setting 2025-09-25 11:16:51 +02:00
arm iommu/arm-smmu-v3: Fix smmu_domain->nr_ats_masters decrement 2025-08-28 16:34:34 +02:00
intel iommu/vt-d: Fix __domain_mapping()'s usage of switch_to_super_page() 2025-09-25 11:16:48 +02:00
iommufd iommufd: Fix race during abort for file descriptors 2025-10-02 13:48:40 +02:00
riscv iommu: Remove ops.pgsize_bitmap from drivers that don't use it 2025-08-28 16:34:38 +02:00
apple-dart.c iommu: Remove ops.pgsize_bitmap from drivers that don't use it 2025-08-28 16:34:38 +02:00
dma-iommu.c treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
dma-iommu.h iommu: Drop sw_msi from iommu_domain 2025-03-25 10:18:19 -03:00
exynos-iommu.c iommu/pages: Remove iommu_alloc_page/pages() 2025-04-17 16:22:50 +02:00
fsl_pamu_domain.c iommu/fsl_pamu: remove trailing space after \n 2025-05-16 08:39:04 +02:00
fsl_pamu_domain.h
fsl_pamu.c
fsl_pamu.h
hyperv-iommu.c x86/hyperv: Clean up hv_map/unmap_interrupt() return values 2025-07-09 23:49:25 +00:00
io-pgfault.c iommu: Fix potential memory leak in iopf_queue_remove_device() 2025-02-10 14:49:30 +01:00
io-pgtable-arm-v7s.c iommu/io-pgtable-arm-v7s: Remove split on unmap behavior 2024-11-06 15:42:36 +00:00
io-pgtable-arm.c Merge branches 'fixes', 'apple/dart', 'arm/smmu/updates', 'arm/smmu/bindings', 'fsl/pamu', 'mediatek', 'renesas/ipmmu', 's390', 'intel/vt-d', 'amd/amd-vi' and 'core' into next 2025-05-23 17:14:32 +02:00
io-pgtable-arm.h
io-pgtable-dart.c iommu: Update various drivers to pass in lg2sz instead of order to iommu pages 2025-04-17 16:22:48 +02:00
io-pgtable.c
iommu-debugfs.c
iommu-pages.c iommu: Clear the freelist after iommu_put_pages_list() 2025-05-16 14:29:16 +02:00
iommu-pages.h iommu/vtd: Remove iommu_alloc_pages_node() 2025-04-17 16:22:54 +02:00
iommu-priv.h iommufd 6.15 merge window pull 2025-04-01 18:03:46 -07:00
iommu-sva.c iommu: Do not call domain_alloc() in iommu_sva_domain_alloc() 2025-04-28 13:14:59 +02:00
iommu-sysfs.c iommu/sysfs: constify the class struct 2024-10-29 09:50:24 +01:00
iommu-traces.c
iommu.c IOMMU Updates for Linux v6.16: 2025-05-30 10:44:20 -07:00
iova.c - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
ipmmu-vmsa.c iommu: ipmmu-vmsa: avoid Wformat-security warning 2025-04-28 13:20:09 +02:00
irq_remapping.c IOMMU Updates for Linux v6.10 2024-05-18 10:55:13 -07:00
irq_remapping.h iommu/vt-d: Allocate DMAR fault interrupts locally 2024-04-26 11:57:36 +02:00
Kconfig iommu: remove duplicate selection of DMAR_TABLE 2025-05-16 08:46:45 +02:00
Makefile iommu: make inclusion of riscv directory conditional 2025-05-16 08:46:47 +02:00
msm_iommu_hw-8xxx.h
msm_iommu.c iommu/msm: Use helper function devm_clk_get_prepared() 2025-01-06 12:41:00 +01:00
msm_iommu.h
mtk_iommu_v1.c iommu/mediatek-v1: Support COMPILE_TEST 2025-03-13 12:17:30 +01:00
mtk_iommu.c iommu/mediatek: Fix compatible typo for mediatek,mt6893-iommu-mm 2025-05-22 09:13:06 +02:00
of_iommu.c iommu: Get DT/ACPI parsing into the proper probe path 2025-03-11 14:05:43 +01:00
omap-iommu-debug.c
omap-iommu.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
omap-iommu.h
omap-iopgtable.h
rockchip-iommu.c iommu/rockchip: prevent iommus dead loop when two masters share one IOMMU 2025-06-27 09:10:29 +02:00
s390-iommu.c iommu/s390: Make attach succeed when the device was surprise removed 2025-09-25 11:16:48 +02:00
sprd-iommu.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
sun50i-iommu.c iommu: Update various drivers to pass in lg2sz instead of order to iommu pages 2025-04-17 16:22:48 +02:00
tegra-smmu.c iommu/tegra: Fix incorrect size calculation 2025-06-13 17:02:31 +02:00
virtio-iommu.c iommu/virtio: Make instance lookup robust 2025-08-28 16:34:39 +02:00