From bb6659cc0ad3c2afc3801b708b19c4c67e55ddf2 Mon Sep 17 00:00:00 2001 From: Zqiang Date: Fri, 30 Apr 2021 16:25:15 +0800 Subject: [PATCH] io_uring: Fix memory leak in io_sqe_buffers_register() unreferenced object 0xffff8881123bf0a0 (size 32): comm "syz-executor557", pid 8384, jiffies 4294946143 (age 12.360s) backtrace: [] kmalloc_node include/linux/slab.h:579 [inline] [] kvmalloc_node+0x61/0xf0 mm/util.c:587 [] kvmalloc include/linux/mm.h:795 [inline] [] kvmalloc_array include/linux/mm.h:813 [inline] [] kvcalloc include/linux/mm.h:818 [inline] [] io_rsrc_data_alloc+0x4f/0xc0 fs/io_uring.c:7164 [] io_sqe_buffers_register+0x98/0x3d0 fs/io_uring.c:8383 [] __io_uring_register+0xf67/0x18c0 fs/io_uring.c:9986 [] __do_sys_io_uring_register fs/io_uring.c:10091 [inline] [] __se_sys_io_uring_register fs/io_uring.c:10071 [inline] [] __x64_sys_io_uring_register+0x112/0x230 fs/io_uring.c:10071 [] do_syscall_64+0x3a/0xb0 arch/x86/entry/common.c:47 [] entry_SYSCALL_64_after_hwframe+0x44/0xae Fix data->tags memory leak, through io_rsrc_data_free() to release data memory space. Reported-by: syzbot+0f32d05d8b6cd8d7ea3e@syzkaller.appspotmail.com Signed-off-by: Zqiang Link: https://lore.kernel.org/r/20210430082515.13886-1-qiang.zhang@windriver.com Signed-off-by: Jens Axboe --- fs/io_uring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index a880edb90d0c..7a2e83bc005d 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -8140,7 +8140,7 @@ static void __io_sqe_buffers_unregister(struct io_ring_ctx *ctx) for (i = 0; i < ctx->nr_user_bufs; i++) io_buffer_unmap(ctx, &ctx->user_bufs[i]); kfree(ctx->user_bufs); - kfree(ctx->buf_data); + io_rsrc_data_free(ctx->buf_data); ctx->user_bufs = NULL; ctx->buf_data = NULL; ctx->nr_user_bufs = 0; @@ -8400,7 +8400,7 @@ static int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg, return -ENOMEM; ret = io_buffers_map_alloc(ctx, nr_args); if (ret) { - kfree(data); + io_rsrc_data_free(data); return ret; }