public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH v1] io_uring: Fix memory leak if file setup fails.
@ 2022-04-29  0:42 Noah Goldstein
  2022-04-29 12:47 ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Noah Goldstein @ 2022-04-29  0:42 UTC (permalink / raw)
  Cc: goldstein.w.n, axboe, asml.silence, io-uring, linux-kernel

If `get_unused_fd_flags` files fails (either in setting up `ctx` as
`tctx->last` or `get_unused_fd_flags`) `ctx` will never be freed.

Signed-off-by: Noah Goldstein <[email protected]>
---
I very well may be missing something (or there may be a double
free if the failure is after `get_unused_fd_flags`) but looks
to me to be a memory leak.
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index a3b76e63f9da..9685a7be48e3 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -11863,7 +11863,7 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
 	if (ret < 0) {
 		/* fput will clean it up */
 		fput(file);
-		return ret;
+		goto err;
 	}
 
 	trace_io_uring_create(ret, ctx, p->sq_entries, p->cq_entries, p->flags);
-- 
2.25.1



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

* Re: [PATCH v1] io_uring: Fix memory leak if file setup fails.
  2022-04-29  0:42 [PATCH v1] io_uring: Fix memory leak if file setup fails Noah Goldstein
@ 2022-04-29 12:47 ` Jens Axboe
  2022-04-29 15:36   ` Noah Goldstein
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2022-04-29 12:47 UTC (permalink / raw)
  To: Noah Goldstein; +Cc: asml.silence, io-uring, linux-kernel

On 4/28/22 6:42 PM, Noah Goldstein wrote:
> If `get_unused_fd_flags` files fails (either in setting up `ctx` as
> `tctx->last` or `get_unused_fd_flags`) `ctx` will never be freed.

There's a comment there telling you why, the fput will end up
releasing it just like it would when an application closes it.

> I very well may be missing something (or there may be a double
> free if the failure is after `get_unused_fd_flags`) but looks
> to me to be a memory leak.

Have you tried synthetically reproducing the two failures you're
thinking of and tracing cleanup?

-- 
Jens Axboe



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

* Re: [PATCH v1] io_uring: Fix memory leak if file setup fails.
  2022-04-29 12:47 ` Jens Axboe
@ 2022-04-29 15:36   ` Noah Goldstein
  0 siblings, 0 replies; 3+ messages in thread
From: Noah Goldstein @ 2022-04-29 15:36 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Pavel Begunkov, open list:IO_URING, open list

On Fri, Apr 29, 2022 at 7:47 AM Jens Axboe <[email protected]> wrote:
>
> On 4/28/22 6:42 PM, Noah Goldstein wrote:
> > If `get_unused_fd_flags` files fails (either in setting up `ctx` as
> > `tctx->last` or `get_unused_fd_flags`) `ctx` will never be freed.
>
> There's a comment there telling you why, the fput will end up
> releasing it just like it would when an application closes it.

I see. Thought the 'it' refered to in the comment was the file, not
ctx.


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

end of thread, other threads:[~2022-04-29 15:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-29  0:42 [PATCH v1] io_uring: Fix memory leak if file setup fails Noah Goldstein
2022-04-29 12:47 ` Jens Axboe
2022-04-29 15:36   ` Noah Goldstein

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