Commit 86b62a2c authored by Al Viro's avatar Al Viro Committed by Linus Torvalds
Browse files

aio: fix io_setup/io_destroy race

Have ioctx_alloc() return an extra reference, so that caller would drop it
on success and not bother with re-grabbing it on failure exit.  The current
code is obviously broken - io_destroy() from another thread that managed
to guess the address io_setup() would've returned would free ioctx right
under us; gets especially interesting if aio_context_t * we pass to
io_setup() points to PROT_READ mapping, so put_user() fails and we end
up doing io_destroy() on kioctx another thread has just got freed...
Signed-off-by: default avatarAl Viro <>
Acked-by: default avatarBenjamin LaHaise <>
Reviewed-by: default avatarJeff Moyer <>
Signed-off-by: default avatarLinus Torvalds <>
parent 86e06008
......@@ -273,7 +273,7 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
mm = ctx->mm = current->mm;
atomic_set(&ctx->users, 1);
atomic_set(&ctx->users, 2);
......@@ -1338,10 +1338,10 @@ SYSCALL_DEFINE2(io_setup, unsigned, nr_events, aio_context_t __user *, ctxp)
ret = PTR_ERR(ioctx);
if (!IS_ERR(ioctx)) {
ret = put_user(ioctx->user_id, ctxp);
if (!ret)
if (!ret) {
return 0;
get_ioctx(ioctx); /* io_destroy() expects us to hold a ref */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment