aio: avoid request count overflow in ioctx_alloc()
Jan Kara
reviewerPATCH 1/1 aio: avoid request count overflow in ioctx_alloc()
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.
--- fs/aio.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/aio.c +2 -3
@@ -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 );
Signature · 1 line
2.51.0
Quoted 8 lines · Jan Kara
ioctx_alloc()saves the 32-bitnr_eventsinmax_reqs, then doublesnr_eventsbefore checking the ring-size bound. For nr_events=0x80000001, the doubled value wraps to 2, so the ring check passes andaio_setup_ring()builds a one-page/127-slot ring. The original0x80000001is still stored inctx->max_reqsand charged to the globalaio_nrquota.[...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes
[1/1] aio: avoid request count overflow in ioctx_alloc()
https://git.kernel.org/vfs/vfs/c/b44341e39d85