aio: prevent double free in ioctx_alloc
PATCH 1/2 aio: prevent double free in ioctx_alloc
ioctx_alloc() calls aio_setup_ring() to allocate a ring. If aio_setup_ring() fails to do so it would call aio_free_ring() before returning, but ioctx_alloc() would call aio_free_ring() again causing a double free of the ring.
This is easily reproducible from userspace.
--- fs/aio.c | 1 - 1 file changed, 1 deletion(-)
fs/aio.c +0 -1
@@ -661,7 +661,6 @@ static struct kioctx *ioctx_alloc(unsigned nr_events) err_cleanup:aio_nr_sub (ctx->max_reqs); err: -aio_free_ring (ctx);free_percpu (ctx->cpu);free_percpu (ctx->reqs.pcpu_count);free_percpu (ctx->users.pcpu_count);
Signature · 7 lines
1.7.10.4 -- To unsubscribe, send a message with 'unsubscribe linux-aio' in the body to [email protected]. For more info on Linux AIO, see: http://www.kvack.org/aio/ Don't email: <a href=mailto:"[email protected]">[email protected]</a>
PATCH 2/2 aio: nullify aio->ring_pages after freeing it
After freeing ring_pages we leave it as is causing a dangling pointer. This has already caused an issue so to help catching any issues in the future NULL it out.
--- fs/aio.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/aio.c +3 -1
@@ -251,8 +251,10 @@ static void aio_free_ring(struct kioctx *ctx)put_aio_ring_file (ctx); -if (ctx->ring_pages && ctx->ring_pages != ctx->internal_pages) +if (ctx->ring_pages && ctx->ring_pages != ctx->internal_pages) {kfree (ctx->ring_pages); + ctx->ring_pages =NULL ; + } }static int aio_ring_mmap (struct file *file,struct vm_area_struct *vma)
Signature · 7 lines
1.7.10.4 -- To unsubscribe, send a message with 'unsubscribe linux-aio' in the body to [email protected]. For more info on Linux AIO, see: http://www.kvack.org/aio/ Don't email: <a href=mailto:"[email protected]">[email protected]</a>
Benjamin LaHaise
maintainerRe: [PATCH 2/2] aio: nullify aio->ring_pages after freeing it
Quoted 3 lines · Sasha Levin
After freeing
ring_pageswe leave it as is causing a dangling pointer. This has already caused an issue so to help catching any issues in the future NULL it out.
Applied as well, I'll send this out after running some tests on the resulting tree tonight.
-ben
Signature · 7 lines
"Thought is the essence of where you are now." -- To unsubscribe, send a message with 'unsubscribe linux-aio' in the body to [email protected]. For more info on Linux AIO, see: http://www.kvack.org/aio/ Don't email: <a href=mailto:"[email protected]">[email protected]</a>
Benjamin LaHaise
maintainerQuoted 6 lines · Sasha Levin
ioctx_alloc()callsaio_setup_ring()to allocate a ring. Ifaio_setup_ring()fails to do so it would callaio_free_ring()before returning, butioctx_alloc()would callaio_free_ring()again causing a double free of the ring.This is easily reproducible from userspace.
I've applied this to my aio-next tree at git://git.kvack.org/~bcrl/aio-next.git
. Please verify that it applied correctly, as that tree also includes another fix from Kent relating to the percpu reference bits.
-ben
Signature · 7 lines
"Thought is the essence of where you are now." -- To unsubscribe, send a message with 'unsubscribe linux-aio' in the body to [email protected]. For more info on Linux AIO, see: http://www.kvack.org/aio/ Don't email: <a href=mailto:"[email protected]">[email protected]</a>