Linux filesystem development
 help / color / mirror / Atom feed
* [PATCH] aio: avoid request count overflow in ioctx_alloc()
@ 2026-10-22 11:25 Jan Kara
  0 siblings, 0 replies; only message in thread
From: Jan Kara @ 2026-10-22 11:25 UTC (permalink / raw)
  To: Christian Brauner; +Cc: linux-fsdevel, linux-aio, Jan Kara, Cheng Yongkang

ioctx_alloc() saves the 32-bit nr_events in max_reqs, then doubles
nr_events before checking the ring-size bound.  For
nr_events=0x80000001, the doubled value wraps to 2, so the ring check
passes and aio_setup_ring() builds a one-page/127-slot ring.  The
original 0x80000001 is still stored in ctx->max_reqs and charged to the
global aio_nr quota.

If an administrator has raised fs.aio-max-nr to at least 0x80000001,
an unprivileged process can create that context and make later normal
io_setup() calls fail with -EAGAIN until the wrapped context is
destroyed.

Check for too large number of requests before multiplying.

Link: https://lore.kernel.org/all/20261022091748.3653127-1-teel4res@gmail.com
Reported-by: Cheng Yongkang <teel4res@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/aio.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/aio.c b/fs/aio.c
index 4f32b45cb8a0..2086c0f263f6 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -805,13 +805,12 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
 	 * counters at a time, so make sure that isn't 0:
 	 */
 	nr_events = max(nr_events, num_possible_cpus() * 4);
-	nr_events *= 2;
-
 	/* Prevent overflows */
-	if (nr_events > (0x10000000U / sizeof(struct io_event))) {
+	if (nr_events > (0x8000000U / sizeof(struct io_event))) {
 		pr_debug("ENOMEM: nr_events too high\n");
 		return ERR_PTR(-EINVAL);
 	}
+	nr_events *= 2;
 
 	if (!nr_events || (unsigned long)max_reqs > aio_max_nr)
 		return ERR_PTR(-EAGAIN);
-- 
2.51.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-22 11:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-22 11:25 [PATCH] aio: avoid request count overflow in ioctx_alloc() Jan Kara

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