* iio: trigger: hrtimer: use-after-free when the trigger is removed while a buffer uses it
@ 2026-12-01 15:49 Lin Tzu Yang
0 siblings, 0 replies; only message in thread
From: Lin Tzu Yang @ 2026-12-01 15:49 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno Sá,
Andy Shevchenko, Changyul Lee, linux-iio, linux-kernel
Hi,
Removing an hrtimer trigger through configfs while a device's buffer
is using it leaves the device pointing at the trigger, and the
trigger's iio_hrtimer_info is freed under it. This is with
8fb20cdf9c86 ("iio: trigger: free hrtimer and loop triggers on configfs
release") from fixes-togreg applied, which fixes the plain mkdir/rmdir
case. Without that commit, the buffer disable step below gives the
same hrtimer_active() reports.
Reproducer (QEMU arm64, KASAN, iio_simple_dummy with buffer support):
cd /sys/kernel/config/iio
mkdir devices/dummy/d0 triggers/hrtimer/t0
D=/sys/bus/iio/devices/iio:device0
echo 1000 > /sys/bus/iio/devices/trigger0/sampling_frequency
for f in $D/scan_elements/*_en; do echo 1 > $f; done
echo t0 > $D/trigger/current_trigger
echo 1 > $D/buffer/enable
rmdir triggers/hrtimer/t0 # succeeds
cat $D/trigger/current_trigger # still "t0"
echo 0 > $D/buffer/enable # 5 KASAN reports, hrtimer_active()
echo 1 > $D/buffer/enable # 22 more, from the timer interrupt
After the re-enable, the freed hrtimer is started again and the timer
interrupt walks it:
BUG: KASAN: slab-use-after-free in timerqueue_linked_add+0x2d4/0x344
Read of size 8 at addr ffff0000117036b0 by task swapper/0/0
timerqueue_linked_add+0x2d4/0x344
enqueue_hrtimer+0x1bc/0x480
__hrtimer_run_queues+0x5fc/0x8e4
hrtimer_interrupt+0x320/0xb20
arch_timer_handler_virt+0x48/0x6c
...
Allocated by task 102:
iio_trig_hrtimer_probe+0x4c/0x25c
iio_sw_trigger_create+0x100/0x200
trigger_make_group+0x38/0x80
configfs_mkdir+0x3a0/0xc60
...
Freed by task 118:
kfree+0x1e0/0x590
iio_hrtimer_release+0x14/0x20
config_item_cleanup+0xf4/0x174
config_item_put+0x84/0xa8
...
As far as I can tell, iio_trig_hrtimer_remove() unregisters and puts
the iio_trigger, but the consumer still holds its reference through
indio_dev->trig, so the trigger outlives the removal while its
iio_hrtimer_info does not. Disabling the buffer then calls
iio_trig_hrtimer_set_state() on freed memory, and enabling it again
re-arms the freed hrtimer.
I am not sure what the right fix is: refusing the rmdir while the
trigger is in use (drop_item can't fail, so this would need something
like configfs_depend_item() when the trigger is attached), or keeping
iio_hrtimer_info alive until the iio_trigger itself is released. I
have not checked the loop trigger in the same way yet. I am happy to
test patches.
This was found with a configfs/sysfs fuzzing script; the analysis was
done with the help of an AI coding assistant (Claude), and I ran the
reproducer above.
Thanks,
Lin Tzu Yang
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-01 15:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 15:49 iio: trigger: hrtimer: use-after-free when the trigger is removed while a buffer uses it Lin Tzu Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®