diff options
author | Pavel Begunkov <asml.silence@gmail.com> | 2021-02-22 11:45:55 +0000 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2021-02-22 06:31:31 -0700 |
commit | 8e5c66c485a8af3f39a8b0358e9e09f002016d92 (patch) | |
tree | 7575e5e33d2855bb16e9f4bc8a15ea66ea731998 /fs/io_uring.c | |
parent | b6c23dd5a483174f386e4c2e1711d9532e090c00 (diff) | |
download | lwn-8e5c66c485a8af3f39a8b0358e9e09f002016d92.tar.gz lwn-8e5c66c485a8af3f39a8b0358e9e09f002016d92.zip |
io_uring: clear request count when freeing caches
BUG: KASAN: double-free or invalid-free in io_req_caches_free.constprop.0+0x3ce/0x530 fs/io_uring.c:8709
Workqueue: events_unbound io_ring_exit_work
Call Trace:
[...]
__cache_free mm/slab.c:3424 [inline]
kmem_cache_free_bulk+0x4b/0x1b0 mm/slab.c:3744
io_req_caches_free.constprop.0+0x3ce/0x530 fs/io_uring.c:8709
io_ring_ctx_free fs/io_uring.c:8764 [inline]
io_ring_exit_work+0x518/0x6b0 fs/io_uring.c:8846
process_one_work+0x98d/0x1600 kernel/workqueue.c:2275
worker_thread+0x64c/0x1120 kernel/workqueue.c:2421
kthread+0x3b1/0x4a0 kernel/kthread.c:292
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294
Freed by task 11900:
[...]
kmem_cache_free_bulk+0x4b/0x1b0 mm/slab.c:3744
io_req_caches_free.constprop.0+0x3ce/0x530 fs/io_uring.c:8709
io_uring_flush+0x483/0x6e0 fs/io_uring.c:9237
filp_close+0xb4/0x170 fs/open.c:1286
close_files fs/file.c:403 [inline]
put_files_struct fs/file.c:418 [inline]
put_files_struct+0x1d0/0x350 fs/file.c:415
exit_files+0x7e/0xa0 fs/file.c:435
do_exit+0xc27/0x2ae0 kernel/exit.c:820
do_group_exit+0x125/0x310 kernel/exit.c:922
[...]
io_req_caches_free() doesn't zero submit_state->free_reqs, so io_uring
considers just freed requests to be good and sound and will reuse or
double free them. Zero the counter.
Reported-by: syzbot+30b4936dcdb3aafa4fb4@syzkaller.appspotmail.com
Fixes: 41be53e94fb04 ("io_uring: kill cached requests from exiting task closing the ring")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'fs/io_uring.c')
-rw-r--r-- | fs/io_uring.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c index 3ecc3c08bf12..bf9ad810c621 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -8704,9 +8704,11 @@ static void io_req_caches_free(struct io_ring_ctx *ctx, struct task_struct *tsk) mutex_lock(&ctx->uring_lock); - if (submit_state->free_reqs) + if (submit_state->free_reqs) { kmem_cache_free_bulk(req_cachep, submit_state->free_reqs, submit_state->reqs); + submit_state->free_reqs = 0; + } io_req_cache_free(&submit_state->comp.free_list, NULL); |