diff options
author | Al Viro <viro@ZenIV.linux.org.uk> | 2012-03-07 00:16:35 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-09 21:59:59 -0500 |
commit | 86b62a2cb4fc09037bbce2959d2992962396fd7f (patch) | |
tree | ea45bb1de1f49862415b5643dea840318d02ee67 /fs | |
parent | 86e06008338e5712603613a0f6770500f79e83bd (diff) |
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: Al Viro <viro@zeniv.linux.org.uk>
Acked-by: Benjamin LaHaise <bcrl@kvack.org>
Reviewed-by: Jeff Moyer <jmoyer@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/aio.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -273,7 +273,7 @@ static struct kioctx *ioctx_alloc(unsigned nr_events) | |||
273 | mm = ctx->mm = current->mm; | 273 | mm = ctx->mm = current->mm; |
274 | atomic_inc(&mm->mm_count); | 274 | atomic_inc(&mm->mm_count); |
275 | 275 | ||
276 | atomic_set(&ctx->users, 1); | 276 | atomic_set(&ctx->users, 2); |
277 | spin_lock_init(&ctx->ctx_lock); | 277 | spin_lock_init(&ctx->ctx_lock); |
278 | spin_lock_init(&ctx->ring_info.ring_lock); | 278 | spin_lock_init(&ctx->ring_info.ring_lock); |
279 | init_waitqueue_head(&ctx->wait); | 279 | init_waitqueue_head(&ctx->wait); |
@@ -1338,10 +1338,10 @@ SYSCALL_DEFINE2(io_setup, unsigned, nr_events, aio_context_t __user *, ctxp) | |||
1338 | ret = PTR_ERR(ioctx); | 1338 | ret = PTR_ERR(ioctx); |
1339 | if (!IS_ERR(ioctx)) { | 1339 | if (!IS_ERR(ioctx)) { |
1340 | ret = put_user(ioctx->user_id, ctxp); | 1340 | ret = put_user(ioctx->user_id, ctxp); |
1341 | if (!ret) | 1341 | if (!ret) { |
1342 | put_ioctx(ioctx); | ||
1342 | return 0; | 1343 | return 0; |
1343 | 1344 | } | |
1344 | get_ioctx(ioctx); /* io_destroy() expects us to hold a ref */ | ||
1345 | io_destroy(ioctx); | 1345 | io_destroy(ioctx); |
1346 | } | 1346 | } |
1347 | 1347 | ||