linux/include
Jann Horn 06eb089489 io_uring: Fix registered ring file refcount leak
commit 12d908116f 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: e7a6c00dc7 ("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>
History 2024-12-27 14:02:17 +01:00
..
acpi mailbox: pcc: Check before sending MCTP PCC response ACK 2024-12-14 20:04:03 +01:00
asm-generic Rename .data.once to .data..once to fix resetting WARN*_ONCE 2024-12-05 14:03:08 +01:00
clocksource x86/hyperv: Fix hv tsc page based sched_clock for hibernation 2024-12-27 14:02:15 +01:00
crypto move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
cxl cxl: Move mailbox related bits to the same context 2024-09-12 08:38:01 -07:00
drm drm/xe/pciid: Add new PCI id for ARL 2024-12-14 20:03:42 +01:00
dt-bindings soc: convert ep93xx to devicetree 2024-09-26 12:00:25 -07:00
keys KEYS: Remove unused declarations 2024-09-20 18:28:26 +03:00
kunit kunit: skb: use "gfp" variable instead of hardcoding GFP_KERNEL 2024-12-05 14:02:13 +01:00
kvm KVM: arm64: Refine PMU defines for number of counters 2024-08-16 13:09:12 +01:00
linux io_uring: Fix registered ring file refcount leak 2024-12-27 14:02:17 +01:00
math-emu powerpc/math-emu: Remove -w build flag and fix warnings 2022-09-05 17:28:25 +10:00
media media: v4l2-core: v4l2-dv-timings: check cvt/gtf result 2024-12-05 14:02:57 +01:00
memory memory: renesas-rpc-if: Remove Runtime PM wrappers 2023-01-23 11:48:00 +01:00
misc cxl: fix typo in comment 2022-11-24 23:12:19 +11:00
net Bluetooth: SCO: Add support for 16 bits transparent voice setting 2024-12-19 18:13:20 +01:00
pcmcia ARM: pxa/sa1100: move I/O space to PCI_IOBASE 2022-05-07 22:56:17 +02:00
ras mm/memory-failure: remove obsolete MF_MSG_DIFFERENT_COMPOUND 2024-07-12 15:52:22 -07:00
rdma RDMA/core: Implement RoCE GID port rescan and export delete function 2024-12-05 14:02:08 +01:00
rv rv: Set variable 'da_mon_##name' to static 2023-09-01 21:00:00 -04:00
scsi move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
soc net: mscc: ocelot: be resilient to loss of PTP packets during transmission 2024-12-19 18:13:14 +01:00
sound ASoC: sdw_utils: Add a quirk to allow the cs42l43 mic DAI to be ignored 2024-12-14 20:03:49 +01:00
target move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
trace tracing/ftrace: disable preemption in syscall probe 2024-12-14 20:03:58 +01:00
uapi fanotify: allow reporting errors on failure to open fd 2024-12-14 20:03:48 +01:00
ufs scsi: ufs: core: Make DMA mask configuration more flexible 2024-12-14 20:03:59 +01:00
vdso random: vDSO: add a __vdso_getrandom prototype for all architectures 2024-09-13 17:28:35 +02:00
video fbdev: da8xx: remove the driver 2024-10-15 10:08:23 +02:00
xen xen: Remove dependency between pciback and privcmd 2024-10-18 11:59:04 +02:00