Skip to content

Commit 7fbfb85

Browse files
rkt-1597gregkh
authored andcommitted
io_uring: fix filename leak in __io_openat_prep()
commit b14fad5 upstream. __io_openat_prep() allocates a struct filename using getname(). However, for the condition of the file being installed in the fixed file table as well as having O_CLOEXEC flag set, the function returns early. At that point, the request doesn't have REQ_F_NEED_CLEANUP flag set. Due to this, the memory for the newly allocated struct filename is not cleaned up, causing a memory leak. Fix this by setting the REQ_F_NEED_CLEANUP for the request just after the successful getname() call, so that when the request is torn down, the filename will be cleaned up, along with other resources needing cleanup. Reported-by: syzbot+00e61c43eb5e4740438f@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=00e61c43eb5e4740438f Tested-by: syzbot+00e61c43eb5e4740438f@syzkaller.appspotmail.com Cc: stable@vger.kernel.org Signed-off-by: Prithvi Tambewagh <activprithvi@gmail.com> Fixes: b944559 ("io_uring: openat directly into fixed fd table") Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent dcb0d8b commit 7fbfb85

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

io_uring/openclose.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ static int __io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
7373
open->filename = NULL;
7474
return ret;
7575
}
76+
req->flags |= REQ_F_NEED_CLEANUP;
7677

7778
open->file_slot = READ_ONCE(sqe->file_index);
7879
if (open->file_slot && (open->how.flags & O_CLOEXEC))
7980
return -EINVAL;
8081

8182
open->nofile = rlimit(RLIMIT_NOFILE);
82-
req->flags |= REQ_F_NEED_CLEANUP;
8383
if (io_openat_force_async(open))
8484
req->flags |= REQ_F_FORCE_ASYNC;
8585
return 0;

0 commit comments

Comments
 (0)