[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20121114115945.539ab5ba.akpm@linux-foundation.org>
Date: Wed, 14 Nov 2012 11:59:45 -0800
From: Andrew Morton <akpm@...ux-foundation.org>
To: Xiaotian Feng <xtfeng@...il.com>
Cc: linux-kernel@...r.kernel.org,
Xiaotian Feng <dannyfeng@...cent.com>,
Jeff Layton <jlayton@...hat.com>,
Al Viro <viro@...iv.linux.org.uk>
Subject: Re: [PATCH] swapfile: fix name leak in swapoff
On Thu, 1 Nov 2012 17:36:55 +0800
Xiaotian Feng <xtfeng@...il.com> wrote:
> there's a name leak introduced by commit 91a27b2, add the missing
> putname.
>
> Signed-off-by: Xiaotian Feng <dannyfeng@...cent.com>
> Cc: Jeff Layton <jlayton@...hat.com>
> Cc: Al Viro <viro@...iv.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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists