Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1223768 > unrolled thread

[PATCH] userfaultfd: add missing mmput() in error path

Started byEric Biggers <ebiggers3@gmail.com>
First post2015-09-14 02:00 +0200
Last post2015-09-15 02:10 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] userfaultfd: add missing mmput() in error path Eric Biggers <ebiggers3@gmail.com> - 2015-09-14 02:00 +0200
    Re: [PATCH] userfaultfd: add missing mmput() in error path Andrea Arcangeli <aarcange@redhat.com> - 2015-09-15 02:10 +0200

#1223768 — [PATCH] userfaultfd: add missing mmput() in error path

FromEric Biggers <ebiggers3@gmail.com>
Date2015-09-14 02:00 +0200
Subject[PATCH] userfaultfd: add missing mmput() in error path
Message-ID<q8plE-5Zj-9@gated-at.bofh.it>
Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
---
 fs/userfaultfd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index 634e676..f9aeb40 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -1287,8 +1287,10 @@ static struct file *userfaultfd_file_create(int flags)
 
 	file = anon_inode_getfile("[userfaultfd]", &userfaultfd_fops, ctx,
 				  O_RDWR | (flags & UFFD_SHARED_FCNTL_FLAGS));
-	if (IS_ERR(file))
+	if (IS_ERR(file)) {
+		mmput(ctx->mm);
 		kmem_cache_free(userfaultfd_ctx_cachep, ctx);
+	}
 out:
 	return file;
 }
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1224557

FromAndrea Arcangeli <aarcange@redhat.com>
Date2015-09-15 02:10 +0200
Message-ID<q8LYS-530-37@gated-at.bofh.it>
In reply to#1223768
Hello Eric,

On Sun, Sep 13, 2015 at 06:57:27PM -0500, Eric Biggers wrote:
> Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
> ---
>  fs/userfaultfd.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
> index 634e676..f9aeb40 100644
> --- a/fs/userfaultfd.c
> +++ b/fs/userfaultfd.c
> @@ -1287,8 +1287,10 @@ static struct file *userfaultfd_file_create(int flags)
>  
>  	file = anon_inode_getfile("[userfaultfd]", &userfaultfd_fops, ctx,
>  				  O_RDWR | (flags & UFFD_SHARED_FCNTL_FLAGS));
> -	if (IS_ERR(file))
> +	if (IS_ERR(file)) {
> +		mmput(ctx->mm);
>  		kmem_cache_free(userfaultfd_ctx_cachep, ctx);
> +	}
>  out:
>  	return file;
>  }

This bug would have generated a memleak in the error code path (which
could only run if running out of files or memory, unfortunately not a
condition that gets routinely exercised).

It's great you spotted it now, we can fix it before final 4.3. I'll
forward it to Andrew to be sure it's not missed.

Thanks,
Andrea
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web