io_uring: fix filename leak in __io_openat_prep()
Subsystems (3)
PATCH v2 1/1 io_uring: fix filename leak in __io_openat_prep()
__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.
--- io_uring/openclose.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
io_uring/openclose.c +1 -1
@@ -73,13 +73,13 @@ static int __io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe open->filename =NULL ;return ret; } + req->flags |=REQ_F_NEED_CLEANUP ; open->file_slot =READ_ONCE (sqe->file_index);if (open->file_slot && (open->how.flags &O_CLOEXEC ))return -EINVAL ; open->nofile =rlimit (RLIMIT_NOFILE ); - req->flags |=REQ_F_NEED_CLEANUP ;if (io_openat_force_async (open)) req->flags |=REQ_F_FORCE_ASYNC ;return 0 ;
base-commit: b927546677c876e26eba308550207c2ddf812a43
Signature · 1 line
2.34.1
Jens Axboe
maintainerQuoted 11 lines · Prithvi Tambewagh
__io_openat_prep()allocates a struct filename usinggetname(). However,
for the condition of the file being installed in the fixed file table as well as havingO_CLOEXECflag set, the function returns early. At that point, the request doesn't haveREQ_F_NEED_CLEANUPflag 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_CLEANUPfor the request just after the successfulgetname()call, so that when the request is torn down, the filename will be cleaned up, along with other resources needing cleanup.
Quoted 5 lines
Reported-by [email protected]Tested-by [email protected]Signed-off-by Prithvi Tambewagh <[email protected]>
Thanks, just missing a:
which I'll add when applying.
Signature · 1 line
Jens Axboe
Quoted 8 lines · Prithvi Tambewagh
__io_openat_prep()allocates a struct filename usinggetname(). However,
for the condition of the file being installed in the fixed file table as well as havingO_CLOEXECflag set, the function returns early. At that point, the request doesn't haveREQ_F_NEED_CLEANUPflag set. Due to this, the memory for the newly allocated struct filename is not cleaned up, causing a memory leak.[...]
Applied, thanks!
[1/1] io_uring: fix filename leak in __io_openat_prep()
commit: b14fad555302a2104948feaff70503b64c80ac01
Best regards,
Signature · 1 line
Jens Axboe
Quoted 9 lines · Jens Axboe
Quoted 7 lines · Prithvi Tambewagh
__io_openat_prep()allocates a struct filename usinggetname(). However,
for the condition of the file being installed in the fixed file table as well as havingO_CLOEXECflag set, the function returns early. At that point, the request doesn't haveREQ_F_NEED_CLEANUPflag set. Due to this, the memory for the newly allocated struct filename is not cleaned up, causing a memory leak.
Quoted 13 lines
Quoted 1 line
[...]
Applied, thanks!
[1/1]
io_uring: fix filename leak in__io_openat_prep()commit: b14fad555302a2104948feaff70503b64c80ac01Best regards,
Signature · 1 line
Jens Axboe
Thank you!
Best Regards,
Prithvi