linux-stable/io_uring
Jens Axboe 094ba14a47 io_uring/msg_ring: ensure io_kiocb freeing is deferred for RCU
Commit fc582cd26e upstream.

syzbot reports that defer/local task_work adding via msg_ring can hit
a request that has been freed:

CPU: 1 UID: 0 PID: 19356 Comm: iou-wrk-19354 Not tainted 6.16.0-rc4-syzkaller-00108-g17bbde2e1716 #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/07/2025
Call Trace:
 <TASK>
 dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
 print_address_description mm/kasan/report.c:408 [inline]
 print_report+0xd2/0x2b0 mm/kasan/report.c:521
 kasan_report+0x118/0x150 mm/kasan/report.c:634
 io_req_local_work_add io_uring/io_uring.c:1184 [inline]
 __io_req_task_work_add+0x589/0x950 io_uring/io_uring.c:1252
 io_msg_remote_post io_uring/msg_ring.c:103 [inline]
 io_msg_data_remote io_uring/msg_ring.c:133 [inline]
 __io_msg_ring_data+0x820/0xaa0 io_uring/msg_ring.c:151
 io_msg_ring_data io_uring/msg_ring.c:173 [inline]
 io_msg_ring+0x134/0xa00 io_uring/msg_ring.c:314
 __io_issue_sqe+0x17e/0x4b0 io_uring/io_uring.c:1739
 io_issue_sqe+0x165/0xfd0 io_uring/io_uring.c:1762
 io_wq_submit_work+0x6e9/0xb90 io_uring/io_uring.c:1874
 io_worker_handle_work+0x7cd/0x1180 io_uring/io-wq.c:642
 io_wq_worker+0x42f/0xeb0 io_uring/io-wq.c:696
 ret_from_fork+0x3fc/0x770 arch/x86/kernel/process.c:148
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
 </TASK>

which is supposed to be safe with how requests are allocated. But msg
ring requests alloc and free on their own, and hence must defer freeing
to a sane time.

Add an rcu_head and use kfree_rcu() in both spots where requests are
freed. Only the one in io_msg_tw_complete() is strictly required as it
has been visible on the other ring, but use it consistently in the other
spot as well.

This should not cause any other issues outside of KASAN rightfully
complaining about it.

Link: https://lore.kernel.org/io-uring/686cd2ea.a00a0220.338033.0007.GAE@google.com/
Reported-by: syzbot+54cbbfb4db9145d26fc2@syzkaller.appspotmail.com
Cc: stable@vger.kernel.org
Fixes: 0617bb500b ("io_uring/msg_ring: improve handling of target CQE posting")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
(cherry picked from commit fc582cd26e)
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-09-09 18:58:15 +02:00
..
advise.c
advise.h
alloc_cache.h
cancel.c
cancel.h
epoll.c
epoll.h
eventfd.c
eventfd.h
fdinfo.c io_uring: fix use-after-free of sq->thread in __io_uring_show_fdinfo() 2025-06-19 15:32:33 +02:00
fdinfo.h
filetable.c
filetable.h
fs.c
fs.h
futex.c io_uring/futex: ensure io_futex_wait() cleans up properly on failure 2025-08-28 16:31:05 +02:00
futex.h
io_uring.c io_uring: account drain memory to cgroup 2025-06-27 11:11:13 +01:00
io_uring.h
io-wq.c io_uring: fix task leak issue in io_wq_create() 2025-06-27 11:11:36 +01:00
io-wq.h
kbuf.c io_uring/kbuf: flag partial buffer mappings 2025-07-06 11:01:48 +02:00
kbuf.h io_uring/kbuf: flag partial buffer mappings 2025-07-06 11:01:48 +02:00
Makefile
memmap.c
memmap.h
msg_ring.c io_uring/msg_ring: ensure io_kiocb freeing is deferred for RCU 2025-09-09 18:58:15 +02:00
msg_ring.h
napi.c
napi.h
net.c io_uring/net: commit partial buffers on retry 2025-08-28 16:31:04 +02:00
net.h
nop.c
nop.h
notif.c
notif.h
opdef.c io_uring: make fallocate be hashed work 2025-07-17 18:37:21 +02:00
opdef.h
openclose.c
openclose.h
poll.c io_uring/poll: fix POLLERR handling 2025-07-24 08:56:23 +02:00
poll.h
refs.h io_uring: always do atomic put from iowq 2025-05-02 07:59:21 +02:00
register.c io_uring: consistently use rcu semantics with sqpoll thread 2025-06-19 15:32:33 +02:00
register.h
rsrc.c io_uring/rsrc: don't rely on user vaddr alignment 2025-07-06 11:01:47 +02:00
rsrc.h io_uring/rsrc: don't rely on user vaddr alignment 2025-07-06 11:01:47 +02:00
rw.c io_uring/rw: cast rw->flags assignment to rwf_t 2025-08-20 18:30:58 +02:00
rw.h
slist.h
splice.c
splice.h
sqpoll.c io_uring/sqpoll: don't put task_struct on tctx setup failure 2025-06-27 11:11:42 +01:00
sqpoll.h io_uring: consistently use rcu semantics with sqpoll thread 2025-06-19 15:32:33 +02:00
statx.c
statx.h
sync.c
sync.h
tctx.c
tctx.h
timeout.c
timeout.h
truncate.c
truncate.h
uring_cmd.c
uring_cmd.h
waitid.c
waitid.h
xattr.c
xattr.h