public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] io_uring: fix filename leak in __io_openat_prep()
@ 2025-12-25  7:28 Prithvi Tambewagh
  2025-12-25 14:58 ` Jens Axboe
  2025-12-25 15:08 ` Jens Axboe
  0 siblings, 2 replies; 4+ messages in thread
From: Prithvi Tambewagh @ 2025-12-25  7:28 UTC (permalink / raw)
  To: axboe
  Cc: io-uring, brauner, jack, viro, linux-fsdevel, linux-kernel,
	linux-kernel-mentees, skhan, david.hunter.linux, khalid,
	Prithvi Tambewagh, syzbot+00e61c43eb5e4740438f, stable

 __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>
---
 io_uring/openclose.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/io_uring/openclose.c b/io_uring/openclose.c
index bfeb91b31bba..15dde9bd6ff6 100644
--- a/io_uring/openclose.c
+++ b/io_uring/openclose.c
@@ -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
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] io_uring: fix filename leak in __io_openat_prep()
  2025-12-25  7:28 [PATCH v2] io_uring: fix filename leak in __io_openat_prep() Prithvi Tambewagh
@ 2025-12-25 14:58 ` Jens Axboe
  2025-12-25 15:08 ` Jens Axboe
  1 sibling, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2025-12-25 14:58 UTC (permalink / raw)
  To: Prithvi Tambewagh
  Cc: io-uring, brauner, jack, viro, linux-fsdevel, linux-kernel,
	linux-kernel-mentees, skhan, david.hunter.linux, khalid,
	syzbot+00e61c43eb5e4740438f, stable

On 12/25/25 12:28 AM, Prithvi Tambewagh wrote:
>  __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>

Thanks, just missing a:

Fixes: b9445598d8c6 ("io_uring: openat directly into fixed fd table")

which I'll add when applying.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] io_uring: fix filename leak in __io_openat_prep()
  2025-12-25  7:28 [PATCH v2] io_uring: fix filename leak in __io_openat_prep() Prithvi Tambewagh
  2025-12-25 14:58 ` Jens Axboe
@ 2025-12-25 15:08 ` Jens Axboe
  2025-12-25 15:18   ` Prithvi
  1 sibling, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2025-12-25 15:08 UTC (permalink / raw)
  To: Prithvi Tambewagh
  Cc: io-uring, brauner, jack, viro, linux-fsdevel, linux-kernel,
	linux-kernel-mentees, skhan, david.hunter.linux, khalid,
	syzbot+00e61c43eb5e4740438f, stable


On Thu, 25 Dec 2025 12:58:29 +0530, Prithvi Tambewagh wrote:
>  __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.
> 
> [...]

Applied, thanks!

[1/1] io_uring: fix filename leak in __io_openat_prep()
      commit: b14fad555302a2104948feaff70503b64c80ac01

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] io_uring: fix filename leak in __io_openat_prep()
  2025-12-25 15:08 ` Jens Axboe
@ 2025-12-25 15:18   ` Prithvi
  0 siblings, 0 replies; 4+ messages in thread
From: Prithvi @ 2025-12-25 15:18 UTC (permalink / raw)
  To: Jens Axboe
  Cc: io-uring, brauner, jack, viro, linux-fsdevel, linux-kernel,
	linux-kernel-mentees, skhan, david.hunter.linux, khalid,
	syzbot+00e61c43eb5e4740438f, stable

On Thu, Dec 25, 2025 at 08:08:50AM -0700, Jens Axboe wrote:
> 
> On Thu, 25 Dec 2025 12:58:29 +0530, Prithvi Tambewagh wrote:
> >  __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.
> > 
> > [...]
> 
> Applied, thanks!
> 
> [1/1] io_uring: fix filename leak in __io_openat_prep()
>       commit: b14fad555302a2104948feaff70503b64c80ac01
> 
> Best regards,
> -- 
> Jens Axboe
> 
> 
> 

Thank you!

Best Regards,
Prithvi

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-12-25 15:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-25  7:28 [PATCH v2] io_uring: fix filename leak in __io_openat_prep() Prithvi Tambewagh
2025-12-25 14:58 ` Jens Axboe
2025-12-25 15:08 ` Jens Axboe
2025-12-25 15:18   ` Prithvi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox