summaryrefslogtreecommitdiff
path: root/io_uring
diff options
context:
space:
mode:
authorJann Horn <jannh@google.com>2024-12-18 17:56:25 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-12-27 13:58:55 +0100
commita73f0425f44ba087751d8e0fa5738f6cd3adf7b9 (patch)
treeac6af32ee10d5e2faf61fb07ef30e4a6b1565b97 /io_uring
parent24047899f94ee696a1c62988d52b955d457b584e (diff)
downloadlinux-a73f0425f44ba087751d8e0fa5738f6cd3adf7b9.tar.gz
linux-a73f0425f44ba087751d8e0fa5738f6cd3adf7b9.tar.bz2
linux-a73f0425f44ba087751d8e0fa5738f6cd3adf7b9.zip
io_uring: Fix registered ring file refcount leak
commit 12d908116f7efd34f255a482b9afc729d7a5fb78 upstream. Currently, io_uring_unreg_ringfd() (which cleans up registered rings) is only called on exit, but __io_uring_free (which frees the tctx in which the registered ring pointers are stored) is also called on execve (via begin_new_exec -> io_uring_task_cancel -> __io_uring_cancel -> io_uring_cancel_generic -> __io_uring_free). This means: A process going through execve while having registered rings will leak references to the rings' `struct file`. Fix it by zapping registered rings on execve(). This is implemented by moving the io_uring_unreg_ringfd() from io_uring_files_cancel() into its callee __io_uring_cancel(), which is called from io_uring_task_cancel() on execve. This could probably be exploited *on 32-bit kernels* by leaking 2^32 references to the same ring, because the file refcount is stored in a pointer-sized field and get_file() doesn't have protection against refcount overflow, just a WARN_ONCE(); but on 64-bit it should have no impact beyond a memory leak. Cc: stable@vger.kernel.org Fixes: e7a6c00dc77a ("io_uring: add support for registering ring file descriptors") Signed-off-by: Jann Horn <jannh@google.com> Link: https://lore.kernel.org/r/20241218-uring-reg-ring-cleanup-v1-1-8f63e999045b@google.com Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'io_uring')
-rw-r--r--io_uring/io_uring.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 70dd6a5b9647..cc31643b7069 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3431,6 +3431,7 @@ end_wait:
void __io_uring_cancel(bool cancel_all)
{
+ io_uring_unreg_ringfd();
io_uring_cancel_generic(cancel_all, NULL);
}