This is a note to let you know that I've just added the patch titled

    ioctx_alloc(): fix vma (and file) leak on failure

to the 3.14-stable tree which can be found at:
    
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     ioctx_alloc-fix-vma-and-file-leak-on-failure.patch
and it can be found in the queue-3.14 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <[email protected]> know about it.


>From deeb8525f9bcea60f5e86521880c1161de7a5829 Mon Sep 17 00:00:00 2001
From: Al Viro <[email protected]>
Date: Mon, 6 Apr 2015 17:57:44 -0400
Subject: ioctx_alloc(): fix vma (and file) leak on failure

From: Al Viro <[email protected]>

commit deeb8525f9bcea60f5e86521880c1161de7a5829 upstream.

If we fail past the aio_setup_ring(), we need to destroy the
mapping.  We don't need to care about anybody having found ctx,
or added requests to it, since the last failure exit is exactly
the failure to make ctx visible to lookups.

Reproducer (based on one by Joe Mario <[email protected]>):

void count(char *p)
{
        char s[80];
        printf("%s: ", p);
        fflush(stdout);
        sprintf(s, "/bin/cat /proc/%d/maps|/bin/fgrep -c '/[aio] (deleted)'", 
getpid());
        system(s);
}

int main()
{
        io_context_t *ctx;
        int created, limit, i, destroyed;
        FILE *f;

        count("before");
        if ((f = fopen("/proc/sys/fs/aio-max-nr", "r")) == NULL)
                perror("opening aio-max-nr");
        else if (fscanf(f, "%d", &limit) != 1)
                fprintf(stderr, "can't parse aio-max-nr\n");
        else if ((ctx = calloc(limit, sizeof(io_context_t))) == NULL)
                perror("allocating aio_context_t array");
        else {
                for (i = 0, created = 0; i < limit; i++) {
                        if (io_setup(1000, ctx + created) == 0)
                                created++;
                }
                for (i = 0, destroyed = 0; i < created; i++)
                        if (io_destroy(ctx[i]) == 0)
                                destroyed++;
                printf("created %d, failed %d, destroyed %d\n",
                        created, limit - created, destroyed);
                count("after");
        }
}

Found-by: Joe Mario <[email protected]>
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

---
 fs/aio.c |    3 +++
 1 file changed, 3 insertions(+)

--- a/fs/aio.c
+++ b/fs/aio.c
@@ -719,6 +719,9 @@ static struct kioctx *ioctx_alloc(unsign
 err_cleanup:
        aio_nr_sub(ctx->max_reqs);
 err_ctx:
+       atomic_set(&ctx->dead, 1);
+       if (ctx->mmap_size)
+               vm_munmap(ctx->mmap_base, ctx->mmap_size);
        aio_free_ring(ctx);
 err:
        mutex_unlock(&ctx->ring_lock);


Patches currently in stable-queue which might be from [email protected] 
are

queue-3.14/ioctx_alloc-fix-vma-and-file-leak-on-failure.patch
queue-3.14/ocfs2-_really_-sync-the-right-range.patch
--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to