From: Lin Tzu Yang <rongh7426@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Changyul Lee" <lcy8047@gmail.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: iio: trigger: hrtimer: use-after-free when the trigger is removed while a buffer uses it
Date: Tue, 1 Dec 2026 23:49:46 +0800 [thread overview]
Message-ID: <20261201154946.904264-1-rongh7426@gmail.com> (raw)
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
reply other threads:[~2026-12-01 15:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201154946.904264-1-rongh7426@gmail.com \
--to=rongh7426@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=lcy8047@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®