All of lore.kernel.org
 help / color / mirror / Atom feed
From: KaiGai Kohei <kaigai@ak.jp.nec.com>
To: Julia Lawall <julia@diku.dk>
Cc: linux-mtd@lists.infradead.org, kernel-janitors@vger.kernel.org,
	dwmw2@infradead.org, linux-kernel@vger.kernel.org,
	KaiGai Kohei <kaigai@ak.jp.nec.com>
Subject: Re: [PATCH] fs/jffs2: Add missing call to posix_acl_release
Date: Mon, 07 Jan 2008 16:02:57 +0000	[thread overview]
Message-ID: <47824D31.8040104@ak.jp.nec.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0801061749490.24950@ask.diku.dk>

Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> posix_acl_clone does a memory allocation and sets a reference count, so
> posix_acl_release is needed afterwards to free it.
> 
> 
> The problem was fixed using the following semantic patch.
> (http://www.emn.fr/x-info/coccinelle/)
> 
> // <smpl>
> @@
> type T;
> identifier E;
> expression E1, E2;
> int ret;
> statement S;
> @@
> 
>   T E;
>   <+...
> (
>   E = \(posix_acl_clone\|posix_acl_alloc\|posix_acl_dup\)(...);
>   if (E = NULL) S
> |
>   if ((E = \(posix_acl_clone\|posix_acl_alloc\|posix_acl_dup\)(...)) = NULL) S
> )
>   ... when != E2 = E
>       when strict
> (
>   posix_acl_release(E);
> |
>   E1 = E;
> |
> + posix_acl_release(E);
>   return;
> |
> + posix_acl_release(E);
>   return ret;
> )
>   ...+>
> // </smpl>
> 
> Signed-off-by: Julia Lawall <julia@diku.dk>
> ---
> 
> diff -u -p a/fs/jffs2/acl.c b/fs/jffs2/acl.c
> --- a/fs/jffs2/acl.c 2008-01-03 09:49:31.000000000 +0100
> +++ b/fs/jffs2/acl.c 2008-01-06 17:38:52.000000000 +0100
> @@ -345,8 +345,10 @@ int jffs2_init_acl_pre(struct inode *dir
>  		if (!clone)
>  			return -ENOMEM;
>  		rc = posix_acl_create_masq(clone, (mode_t *)i_mode);
> -		if (rc < 0)
> +		if (rc < 0) {
> +			posix_acl_release(clone);
>  			return rc;
> +		}
>  		if (rc > 0)
>  			jffs2_iset_acl(inode, &f->i_acl_access, clone);

Indeed, there was a possibility to cause memory leaking.

Acked-by: KaiGai Kohei <kaigai@ak.jp.nec.com>

-- 
OSS Platform Development Division, NEC
KaiGai Kohei <kaigai@ak.jp.nec.com>


WARNING: multiple messages have this Message-ID (diff)
From: KaiGai Kohei <kaigai@ak.jp.nec.com>
To: Julia Lawall <julia@diku.dk>
Cc: linux-mtd@lists.infradead.org, kernel-janitors@vger.kernel.org,
	dwmw2@infradead.org, linux-kernel@vger.kernel.org,
	KaiGai Kohei <kaigai@ak.jp.nec.com>
Subject: Re: [PATCH] fs/jffs2: Add missing call to posix_acl_release
Date: Tue, 08 Jan 2008 01:02:57 +0900	[thread overview]
Message-ID: <47824D31.8040104@ak.jp.nec.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0801061749490.24950@ask.diku.dk>

Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> posix_acl_clone does a memory allocation and sets a reference count, so
> posix_acl_release is needed afterwards to free it.
> 
> 
> The problem was fixed using the following semantic patch.
> (http://www.emn.fr/x-info/coccinelle/)
> 
> // <smpl>
> @@
> type T;
> identifier E;
> expression E1, E2;
> int ret;
> statement S;
> @@
> 
>   T E;
>   <+...
> (
>   E = \(posix_acl_clone\|posix_acl_alloc\|posix_acl_dup\)(...);
>   if (E == NULL) S
> |
>   if ((E = \(posix_acl_clone\|posix_acl_alloc\|posix_acl_dup\)(...)) == NULL) S
> )
>   ... when != E2 = E
>       when strict
> (
>   posix_acl_release(E);
> |
>   E1 = E;
> |
> + posix_acl_release(E);
>   return;
> |
> + posix_acl_release(E);
>   return ret;
> )
>   ...+>
> // </smpl>
> 
> Signed-off-by: Julia Lawall <julia@diku.dk>
> ---
> 
> diff -u -p a/fs/jffs2/acl.c b/fs/jffs2/acl.c
> --- a/fs/jffs2/acl.c 2008-01-03 09:49:31.000000000 +0100
> +++ b/fs/jffs2/acl.c 2008-01-06 17:38:52.000000000 +0100
> @@ -345,8 +345,10 @@ int jffs2_init_acl_pre(struct inode *dir
>  		if (!clone)
>  			return -ENOMEM;
>  		rc = posix_acl_create_masq(clone, (mode_t *)i_mode);
> -		if (rc < 0)
> +		if (rc < 0) {
> +			posix_acl_release(clone);
>  			return rc;
> +		}
>  		if (rc > 0)
>  			jffs2_iset_acl(inode, &f->i_acl_access, clone);

Indeed, there was a possibility to cause memory leaking.

Acked-by: KaiGai Kohei <kaigai@ak.jp.nec.com>

-- 
OSS Platform Development Division, NEC
KaiGai Kohei <kaigai@ak.jp.nec.com>

WARNING: multiple messages have this Message-ID (diff)
From: KaiGai Kohei <kaigai@ak.jp.nec.com>
To: Julia Lawall <julia@diku.dk>
Cc: dwmw2@infradead.org, linux-mtd@lists.infradead.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	KaiGai Kohei <kaigai@ak.jp.nec.com>
Subject: Re: [PATCH] fs/jffs2: Add missing call to posix_acl_release
Date: Tue, 08 Jan 2008 01:02:57 +0900	[thread overview]
Message-ID: <47824D31.8040104@ak.jp.nec.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0801061749490.24950@ask.diku.dk>

Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> posix_acl_clone does a memory allocation and sets a reference count, so
> posix_acl_release is needed afterwards to free it.
> 
> 
> The problem was fixed using the following semantic patch.
> (http://www.emn.fr/x-info/coccinelle/)
> 
> // <smpl>
> @@
> type T;
> identifier E;
> expression E1, E2;
> int ret;
> statement S;
> @@
> 
>   T E;
>   <+...
> (
>   E = \(posix_acl_clone\|posix_acl_alloc\|posix_acl_dup\)(...);
>   if (E == NULL) S
> |
>   if ((E = \(posix_acl_clone\|posix_acl_alloc\|posix_acl_dup\)(...)) == NULL) S
> )
>   ... when != E2 = E
>       when strict
> (
>   posix_acl_release(E);
> |
>   E1 = E;
> |
> + posix_acl_release(E);
>   return;
> |
> + posix_acl_release(E);
>   return ret;
> )
>   ...+>
> // </smpl>
> 
> Signed-off-by: Julia Lawall <julia@diku.dk>
> ---
> 
> diff -u -p a/fs/jffs2/acl.c b/fs/jffs2/acl.c
> --- a/fs/jffs2/acl.c 2008-01-03 09:49:31.000000000 +0100
> +++ b/fs/jffs2/acl.c 2008-01-06 17:38:52.000000000 +0100
> @@ -345,8 +345,10 @@ int jffs2_init_acl_pre(struct inode *dir
>  		if (!clone)
>  			return -ENOMEM;
>  		rc = posix_acl_create_masq(clone, (mode_t *)i_mode);
> -		if (rc < 0)
> +		if (rc < 0) {
> +			posix_acl_release(clone);
>  			return rc;
> +		}
>  		if (rc > 0)
>  			jffs2_iset_acl(inode, &f->i_acl_access, clone);

Indeed, there was a possibility to cause memory leaking.

Acked-by: KaiGai Kohei <kaigai@ak.jp.nec.com>

-- 
OSS Platform Development Division, NEC
KaiGai Kohei <kaigai@ak.jp.nec.com>


  reply	other threads:[~2008-01-07 16:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-06 16:50 [PATCH] fs/jffs2: Add missing call to posix_acl_release Julia Lawall
2008-01-06 16:50 ` Julia Lawall
2008-01-07 16:02 ` KaiGai Kohei [this message]
2008-01-07 16:02   ` KaiGai Kohei
2008-01-07 16:02   ` KaiGai Kohei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47824D31.8040104@ak.jp.nec.com \
    --to=kaigai@ak.jp.nec.com \
    --cc=dwmw2@infradead.org \
    --cc=julia@diku.dk \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.