]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
io_uring: fix filename leak in __io_openat_prep()
authorPrithvi Tambewagh <activprithvi@gmail.com>
Thu, 25 Dec 2025 07:28:29 +0000 (12:58 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Jan 2026 12:09:54 +0000 (13:09 +0100)
commit b14fad555302a2104948feaff70503b64c80ac01 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: b9445598d8c6 ("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>
io_uring/io_uring.c

index 43dd54c576d68f043589063cb4ee39a4bb3d3ed2..e5889ec0273fa57e5677988d571ee5e3196f1145 100644 (file)
@@ -4326,13 +4326,13 @@ static int __io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
                req->open.filename = NULL;
                return ret;
        }
+       req->flags |= REQ_F_NEED_CLEANUP;
 
        req->open.file_slot = READ_ONCE(sqe->file_index);
        if (req->open.file_slot && (req->open.how.flags & O_CLOEXEC))
                return -EINVAL;
 
        req->open.nofile = rlimit(RLIMIT_NOFILE);
-       req->flags |= REQ_F_NEED_CLEANUP;
        return 0;
 }