linux-yocto/drivers
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
..
accel accel/ivpu: Prevent recovery work from being queued during device removal 2025-09-09 19:02:28 +02:00
accessibility
acpi ACPI: RISC-V: Fix FFH_CPPC_CSR error handling 2025-09-09 19:02:39 +02:00
amba
android binder: Fix selftest page indexing 2025-08-20 18:40:58 +02:00
ata ata: libata-scsi: Fix CDL control 2025-08-28 16:34:18 +02:00
atm atm: atmtcp: Prevent arbitrary write in atmtcp_recv_control(). 2025-09-04 16:55:36 +02:00
auxdisplay treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
base x86/vmscape: Enable the mitigation 2025-09-11 17:23:22 +02:00
bcma
block zram: fix slot write race condition 2025-09-25 11:16:45 +02:00
bluetooth Bluetooth: vhci: Prevent use-after-free by removing debugfs files early 2025-09-09 19:02:21 +02:00
bus bus: mhi: host: Detect events pointing to unexpected TREs 2025-08-28 16:34:13 +02:00
cache
cdrom
cdx cdx: Fix off-by-one error in cdx_rpmsg_probe() 2025-08-28 16:34:40 +02:00
char ipmi: Fix strcpy source and destination the same 2025-08-20 18:41:31 +02:00
clk clk: sunxi-ng: mp: Fix dual-divider clock rate readback 2025-09-25 11:16:54 +02:00
clocksource clocksource: hyper-v: Fix warnings for missing export.h header inclusion 2025-07-09 23:46:06 +00:00
comedi comedi: Fix use of uninitialized memory in do_insn_ioctl() and do_insnlist_ioctl() 2025-08-28 16:34:40 +02:00
connector
counter
cpufreq cpufreq: Initialize cpufreq-based invariance before subsys 2025-10-02 13:48:27 +02:00
cpuidle cpuidle: governors: menu: Avoid selecting states with too much latency 2025-08-28 16:34:32 +02:00
crypto crypto: ccp - Always pass in an error pointer to __sev_platform_shutdown_locked() 2025-09-25 11:16:50 +02:00
cxl cxl/edac: Fix wrong dpa checking for PPR operation 2025-08-15 16:39:06 +02:00
dax
dca
devfreq PM / devfreq: governor: Replace sscanf() with kstrtoul() in set_freq_store() 2025-08-20 18:40:58 +02:00
dio
dma dmaengine: dw: dmamux: Fix device reference leak in rzn1_dmamux_route_allocate 2025-09-19 16:37:39 +02:00
dma-buf udmabuf: fix vmap missed offset page 2025-08-15 16:38:36 +02:00
dpll dpll: fix clock quality level reporting 2025-09-25 11:16:43 +02:00
edac EDAC/altera: Delete an inappropriate dma_free_coherent() call 2025-09-19 16:37:29 +02:00
eisa
extcon
firewire firewire: core: fix overlooked update of subsystem ABI version 2025-10-02 13:48:22 +02:00
firmware firmware: qcom: scm: request the waitqueue irq *after* initializing SCM 2025-09-04 16:55:51 +02:00
fpga fpga: zynq_fpga: Fix the wrong usage of dma_map_sgtable() 2025-08-28 16:34:39 +02:00
fsi
fwctl
gnss
gpio gpiolib: Extend software-node support to support secondary software-nodes 2025-10-02 13:48:38 +02:00
gpu drm/amd/display: Only restore backlight after amdgpu_dm_init or dm_resume 2025-10-02 13:48:37 +02:00
greybus treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
hid HID: asus: add support for missing PX series fn keys 2025-10-02 13:48:34 +02:00
hsi treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
hte
hv Drivers: hv: Use nested hypercall for post message and signal event 2025-07-15 06:24:16 +00:00
hwmon hwmon: (ina238) Correctly clamp power limits 2025-09-09 19:02:38 +02:00
hwspinlock
hwtracing
i2c i2c: designware: Add quirk for Intel Xe 2025-10-02 13:48:25 +02:00
i3c i3c: master: Initialize ret in i3c_i2c_notifier_call() 2025-08-20 18:41:29 +02:00
idle intel_idle: Allow loading ACPI tables for any family 2025-08-20 18:40:51 +02:00
iio iio: imu: inv_icm42600: change invalid data error to -EBUSY 2025-08-28 16:34:42 +02:00
infiniband IB/mlx5: Fix obj_type mismatch for SRQ event subscriptions 2025-10-02 13:48:26 +02:00
input Input: xpad - add support for Flydigi Apex 5 2025-09-19 16:37:34 +02:00
interconnect interconnect: qcom: sc8180x: specify num_nodes 2025-08-15 16:38:35 +02:00
iommu iommufd: Fix race during abort for file descriptors 2025-10-02 13:48:40 +02:00
ipack
irqchip irqchip/mvebu-gicp: Fix an IS_ERR() vs NULL check in probe() 2025-09-19 16:37:26 +02:00
isdn mISDN: Fix memory leak in dsp_hwec_enable() 2025-09-09 19:02:22 +02:00
leds leds: leds-lp50xx: Handle reg to get correct multi_index 2025-08-20 18:41:25 +02:00
macintosh
mailbox treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
mcb
md dm-stripe: fix a possible integer overflow 2025-09-25 11:16:46 +02:00
media media: iris: Remove unnecessary re-initialization of flush completion 2025-08-28 16:34:29 +02:00
memory treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
memstick memstick: Fix deadlock by moving removing flag earlier 2025-08-28 16:34:35 +02:00
message
mfd mfd: mt6397: Do not use generic name for keypad sub-devices 2025-08-28 16:34:24 +02:00
misc misc: rtsx: usb: Ensure mmc child device is active when card is present 2025-08-20 18:41:37 +02:00
mmc mmc: sdhci-cadence: add Mobileye eyeQ support 2025-10-02 13:48:25 +02:00
most most: core: Drop device reference after usage in get_channel() 2025-08-28 16:34:40 +02:00
mtd mtd: rawnand: nuvoton: Fix an error handling path in ma35_nand_chips_init() 2025-09-19 16:37:35 +02:00
mux mux: mmio: Fix missing CONFIG_REGMAP_MMIO 2025-07-04 16:27:08 +02:00
net wifi: iwlwifi: pcie: fix byte count table for some devices 2025-10-02 13:48:39 +02:00
nfc treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
ntb
nubus
nvdimm
nvme nvme: fix PI insert on write 2025-09-25 11:16:41 +02:00
nvmem nvmem: layouts: u-boot-env: remove crc32 endianness conversion 2025-07-16 16:51:04 +02:00
of of_numa: fix uninitialized memory nodes causing kernel panic 2025-09-09 19:02:31 +02:00
opp
parisc
parport treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
pci PCI: mvebu: Fix use of for_each_of_range() iterator 2025-09-19 16:37:35 +02:00
pcmcia pcmcia: omap_cf: Mark driver struct with __refdata to prevent section mismatch 2025-09-25 11:16:42 +02:00
peci
perf perf/arm: Add missing .suppress_bind_attrs 2025-08-20 18:41:12 +02:00
phy phy: ti-pipe3: fix device leak at unbind 2025-09-19 16:37:39 +02:00
pinctrl pinctrl: airoha: fix wrong MDIO function bitmaks 2025-10-02 13:48:37 +02:00
platform platform/x86: lg-laptop: Fix WMAB call in fan_mode_store() 2025-10-02 13:48:34 +02:00
pmdomain imx8m-blk-ctrl: set ISI panic write hurry level 2025-08-20 18:41:03 +02:00
pnp
power power: supply: bq27xxx: restrict no-battery detection to bq27000 2025-09-25 11:16:46 +02:00
powercap powercap: dtpm_cpu: Fix NULL pointer dereference in get_pd_power_uw() 2025-08-15 16:38:31 +02:00
pps pps: clients: gpio: fix interrupt handling order in remove path 2025-08-20 18:41:01 +02:00
ps3
ptp ptp: ocp: fix use-after-free bugs causing by ptp_ocp_watchdog 2025-09-09 19:02:22 +02:00
pwm pwm: mediatek: Fix duty and period setting 2025-08-28 16:34:23 +02:00
rapidio drivers/rapidio/rio_cm.c: prevent possible heap overwrite 2025-06-11 22:42:36 -07:00
ras
regulator regulator: sy7636a: fix lifecycle of power good gpio 2025-09-19 16:37:38 +02:00
remoteproc remoteproc: imx_rproc: skip clock enable when M-core is managed by the SCU 2025-08-20 18:40:57 +02:00
reset reset: brcmstb: Enable reset drivers for ARCH_BCM2835 2025-08-20 18:41:01 +02:00
rpmsg
rtc rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe 2025-08-20 18:41:33 +02:00
s390 s390/sclp: Fix SCCB present check 2025-08-28 16:34:36 +02:00
sbus
scsi scsi: sr: Reinstate rotational media flag 2025-09-09 19:02:37 +02:00
sh
siox
slimbus
soc soc: qcom: mdt_loader: Deal with zero e_shentsize 2025-09-09 19:02:31 +02:00
soundwire soundwire: Move handle_nested_irq outside of sdw_dev_lock 2025-08-20 18:41:28 +02:00
spi spi: cadence-qspi: defer runtime support on socfpga if reset bit is enabled 2025-10-02 13:48:39 +02:00
spmi
ssb
staging media: imx: fix a potential memory leak in imx_media_csc_scaler_device_init() 2025-08-28 16:34:27 +02:00
target scsi: target: core: Generate correct identifiers for PR OUT transport IDs 2025-08-20 18:41:30 +02:00
tc
tee tee: optee: ffa: fix a typo of "optee_ffa_api_is_compatible" 2025-09-09 19:02:17 +02:00
thermal thermal/drivers/mediatek/lvts_thermal: Add mt7988 lvts commands 2025-09-04 16:55:52 +02:00
thunderbolt thunderbolt: Fix copy+paste error in match_service_id() 2025-08-20 18:41:37 +02:00
tty serial: sc16is7xx: fix bug in flow control levels init 2025-09-19 16:37:34 +02:00
ufs scsi: ufs: mcq: Fix memory allocation checks for SQE and CQE 2025-10-02 13:48:22 +02:00
uio Char/Misc/IIO pull request for 6.16-rc1 2025-06-06 11:50:47 -07:00
usb usb: core: Add 0x prefix to quirks debug output 2025-10-02 13:48:24 +02:00
vdpa vdpa: Fix IDR memory leak in VDUSE module exit 2025-08-15 16:39:15 +02:00
vfio vfio/mlx5: fix possible overflow in tracking max message size 2025-08-20 18:41:30 +02:00
vhost vhost-net: flush batched before enabling notifications 2025-10-02 13:48:37 +02:00
video fbcon: Fix OOB access in font allocation 2025-10-02 13:48:39 +02:00
virt fix locking in efi_secret_unlink() 2025-08-20 18:40:56 +02:00
virtio virtio_ring: Fix error reporting in virtqueue_resize 2025-07-03 11:40:02 +02:00
w1 Char/Misc/IIO pull request for 6.16-rc1 2025-06-06 11:50:47 -07:00
watchdog watchdog: iTCO_wdt: Report error if timeout configuration fails 2025-08-20 18:41:23 +02:00
xen xen/gntdev: remove struct gntdev_copy_batch from stack 2025-08-15 16:38:47 +02:00
zorro
Kconfig
Makefile