From: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
To: Konstantin Khorenko <khorenko@virtuozzo.com>
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1] ms/aio: avoid request count overflow in ioctx_alloc()
Date: Tue, 17 Nov 2026 14:58:04 +0100 [thread overview]
Message-ID: <20261117-pr-ptikhomirov-vstor-155110-aio-nr-overflow-v1-1-b54fa34e3ee5@virtuozzo.com> (raw)
From: Jan Kara <jack@suse.cz>
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>
Link: https://patch.msgid.link/20261022112534.3513745-2-jack@suse.cz
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
(cherry picked from commit b44341e39d856e4cc6ad8ed94ebffd440f39846c)
https://virtuozzo.atlassian.net/browse/VSTOR-155110
Feature: fix ms/aio
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
fs/aio.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/fs/aio.c b/fs/aio.c
index 2ff1758507611..173b35ebed991 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -773,13 +773,12 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
nr_events = max(nr_events, num_possible_cpus() * 4);
else if (nr_events < num_possible_cpus() * 4)
no_percpu_reqs = true;
- 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 > ve->aio_max_nr)
return ERR_PTR(-EAGAIN);
---
base-commit: a656d0a24ddd1939d7deea2f7450873e662c828e
change-id: 20261117-pr-ptikhomirov-vstor-155110-aio-nr-overflow-ac6d336ee111
Best regards,
--
Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next reply other threads:[~2026-11-17 13:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 13:58 Pavel Tikhomirov [this message]
2026-11-17 15:10 ` Konstantin Khorenko
2026-11-17 15:10 ` Konstantin Khorenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117-pr-ptikhomirov-vstor-155110-aio-nr-overflow-v1-1-b54fa34e3ee5@virtuozzo.com \
--to=ptikhomirov@virtuozzo.com \
--cc=devel@openvz.org \
--cc=khorenko@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox