media: dvb-core: don't reinitialize dvr_buffer waitqueue on open
dvb_dvr_open() calls dvb_ringbuffer_init() when a new reader opens the
DVR device. dvb_ringbuffer_init() calls init_waitqueue_head(), which
reinitializes the waitqueue list head to empty. Since
dmxdev->dvr_buffer.queue is a shared waitqueue (all opens of the same
DVR device share it), this orphans any existing waitqueue entries from
io_uring poll or epoll, leaving them with stale prev/next pointers
while the list head is reset to {self, self}.
A straightforward way to trigger this:
1. Open /dev/dvb/adapter0/dvr0 with O_ACCMODE=3 (an atypical flag
combination that skips the need_ringbuffer path in dvb_dvr_open,
so the ringbuffer is not initialized, but dvbdev->users is
incremented).
2. Set up io_uring and arm POLL_ADD on the DVB fd. This adds a
wait_queue_entry to dmxdev->dvr_buffer.queue.
3. Open /proc/self/fd/<dvr_fd> with O_RDONLY. This calls dvb_dvr_open
again, which enters the need_ringbuffer path and calls
dvb_ringbuffer_init() -> init_waitqueue_head(), resetting the
waitqueue list head to empty. io_uring's poll entry is now
orphaned: its ->prev still points to the list head, but the list
head's ->next now points to itself.
4. Process exits. io_uring task work runs io_poll_task_func() ->
io_poll_remove_entries() -> list_del_init() on the orphaned entry.
The list validation finds prev->next == prev instead of the entry
being deleted, triggering the BUG:
list_del corruption. prev->next should be X, but was Y. (prev=Y)
kernel BUG at lib/list_debug.c:62!
RIP: __list_del_entry_valid_or_report
Call Trace:
io_poll_remove_entries
io_poll_task_func
io_handle_tw_list
tctx_task_work_run
tctx_task_work
task_work_run
do_exit
The waitqueue and spinlock in dvr_buffer are already properly
initialized once in dvb_dmxdev_init(). The open path only needs to
reset the buffer data pointer, size, and read/write positions. Replace
the dvb_ringbuffer_init() call in dvb_dvr_open() with direct
assignment of data/size and a call to dvb_ringbuffer_reset(), which
properly resets pread, pwrite, and error with correct memory ordering
without touching the waitqueue or spinlock.
Reported-by: syzbot
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 file changed