Patch "io_uring: fix memory leak when removing provided buffers" has been added to the 6.2-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    io_uring: fix memory leak when removing provided buffers

to the 6.2-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     io_uring-fix-memory-leak-when-removing-provided-buff.patch
and it can be found in the queue-6.2 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 0ed00dcb0c795efc0722ccd715affe4370038f66
Author: Wojciech Lukowicz <wlukowicz01@xxxxxxxxx>
Date:   Sat Apr 1 20:50:39 2023 +0100

    io_uring: fix memory leak when removing provided buffers
    
    [ Upstream commit b4a72c0589fdea6259720375426179888969d6a2 ]
    
    When removing provided buffers, io_buffer structs are not being disposed
    of, leading to a memory leak. They can't be freed individually, because
    they are allocated in page-sized groups. They need to be added to some
    free list instead, such as io_buffers_cache. All callers already hold
    the lock protecting it, apart from when destroying buffers, so had to
    extend the lock there.
    
    Fixes: cc3cec8367cb ("io_uring: speedup provided buffer handling")
    Signed-off-by: Wojciech Lukowicz <wlukowicz01@xxxxxxxxx>
    Link: https://lore.kernel.org/r/20230401195039.404909-2-wlukowicz01@xxxxxxxxx
    Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index a4e9dbc7b67a8..add5cff7952c5 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2722,8 +2722,8 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
 	io_eventfd_unregister(ctx);
 	io_alloc_cache_free(&ctx->apoll_cache, io_apoll_cache_free);
 	io_alloc_cache_free(&ctx->netmsg_cache, io_netmsg_cache_free);
-	mutex_unlock(&ctx->uring_lock);
 	io_destroy_buffers(ctx);
+	mutex_unlock(&ctx->uring_lock);
 	if (ctx->sq_creds)
 		put_cred(ctx->sq_creds);
 	if (ctx->submitter_task)
diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index 0fdcc0adbdbcc..a90c820ce99e1 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -228,11 +228,14 @@ static int __io_remove_buffers(struct io_ring_ctx *ctx,
 		return i;
 	}
 
+	/* protects io_buffers_cache */
+	lockdep_assert_held(&ctx->uring_lock);
+
 	while (!list_empty(&bl->buf_list)) {
 		struct io_buffer *nxt;
 
 		nxt = list_first_entry(&bl->buf_list, struct io_buffer, list);
-		list_del(&nxt->list);
+		list_move(&nxt->list, &ctx->io_buffers_cache);
 		if (++i == nbufs)
 			return i;
 		cond_resched();



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux