linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] swapfile: fix name leak in swapoff
@ 2012-11-01  9:36 Xiaotian Feng
  2012-11-01 10:04 ` Jeff Layton
  2012-11-14 19:59 ` Andrew Morton
  0 siblings, 2 replies; 3+ messages in thread
From: Xiaotian Feng @ 2012-11-01  9:36 UTC (permalink / raw)
  To: linux-kernel; +Cc: Xiaotian Feng, Xiaotian Feng, Jeff Layton, Al Viro

there's a name leak introduced by commit 91a27b2, add the missing
putname.

Signed-off-by: Xiaotian Feng <dannyfeng@tencent.com>
Cc: Jeff Layton <jlayton@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
---
 mm/swapfile.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 71cd288..459fe30 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1608,6 +1608,8 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
 out_dput:
 	filp_close(victim, NULL);
 out:
+	if (pathname && !IS_ERR(pathname))
+		putname(pathname);
 	return err;
 }
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] swapfile: fix name leak in swapoff
  2012-11-01  9:36 [PATCH] swapfile: fix name leak in swapoff Xiaotian Feng
@ 2012-11-01 10:04 ` Jeff Layton
  2012-11-14 19:59 ` Andrew Morton
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff Layton @ 2012-11-01 10:04 UTC (permalink / raw)
  To: Xiaotian Feng; +Cc: linux-kernel, Xiaotian Feng, Al Viro

On Thu,  1 Nov 2012 17:36:55 +0800
Xiaotian Feng <xtfeng@gmail.com> wrote:

> there's a name leak introduced by commit 91a27b2, add the missing
> putname.
> 
> Signed-off-by: Xiaotian Feng <dannyfeng@tencent.com>
> Cc: Jeff Layton <jlayton@redhat.com>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> ---
>  mm/swapfile.c |    2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 71cd288..459fe30 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -1608,6 +1608,8 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
>  out_dput:
>  	filp_close(victim, NULL);
>  out:
> +	if (pathname && !IS_ERR(pathname))
> +		putname(pathname);
>  	return err;
>  }
>  

Nice catch.

Reviewed-by: Jeff Layton <jlayton@redhat.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] swapfile: fix name leak in swapoff
  2012-11-01  9:36 [PATCH] swapfile: fix name leak in swapoff Xiaotian Feng
  2012-11-01 10:04 ` Jeff Layton
@ 2012-11-14 19:59 ` Andrew Morton
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2012-11-14 19:59 UTC (permalink / raw)
  To: Xiaotian Feng; +Cc: linux-kernel, Xiaotian Feng, Jeff Layton, Al Viro

On Thu,  1 Nov 2012 17:36:55 +0800
Xiaotian Feng <xtfeng@gmail.com> wrote:

> there's a name leak introduced by commit 91a27b2, add the missing
> putname.
> 
> Signed-off-by: Xiaotian Feng <dannyfeng@tencent.com>
> Cc: Jeff Layton <jlayton@redhat.com>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> ---
>  mm/swapfile.c |    2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 71cd288..459fe30 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -1608,6 +1608,8 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
>  out_dput:
>  	filp_close(victim, NULL);
>  out:
> +	if (pathname && !IS_ERR(pathname))
> +		putname(pathname);
>  	return err;
>  }

This way is simpler:

--- a/mm/swapfile.c~swapfile-fix-name-leak-in-swapoff-fix
+++ a/mm/swapfile.c
@@ -1507,9 +1507,8 @@ SYSCALL_DEFINE1(swapoff, const char __us
 	BUG_ON(!current->mm);
 
 	pathname = getname(specialfile);
-	err = PTR_ERR(pathname);
 	if (IS_ERR(pathname))
-		goto out;
+		return PTR_ERR(pathname);
 
 	victim = file_open_name(pathname, O_RDWR|O_LARGEFILE, 0);
 	err = PTR_ERR(victim);
@@ -1615,8 +1614,7 @@ SYSCALL_DEFINE1(swapoff, const char __us
 out_dput:
 	filp_close(victim, NULL);
 out:
-	if (pathname && !IS_ERR(pathname))
-		putname(pathname);
+	putname(pathname);
 	return err;
 }
 
_


It would be even simpler to do the putname() immediately after
file_open_name(), but it is nice to keep `pathname' live for the whole
function in case it gets used by later code.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-11-14 19:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-01  9:36 [PATCH] swapfile: fix name leak in swapoff Xiaotian Feng
2012-11-01 10:04 ` Jeff Layton
2012-11-14 19:59 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).