From: Miklos Szeredi <miklos@szeredi.hu>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] vfs: fix possible use after free in finish_open()
Date: Mon, 25 Oct 2010 15:16:51 +0200 [thread overview]
Message-ID: <E1PAMux-0002CG-8a@pomaz-ex.szeredi.hu> (raw)
From: Miklos Szeredi <mszeredi@suse.cz>
In finish_open() nd->path is used after nameidata_to_filp() already
released it. Fix by acquiring a ref to nd->path and releasing after
the last use.
Similar fix needed in do_last().
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
CC: stable@kernel.org
---
fs/namei.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
Index: linux-2.6/fs/namei.c
===================================================================
--- linux-2.6.orig/fs/namei.c 2010-10-25 15:07:17.000000000 +0200
+++ linux-2.6/fs/namei.c 2010-10-25 15:07:32.000000000 +0200
@@ -1549,11 +1549,16 @@ static struct file *finish_open(struct n
error = mnt_want_write(nd->path.mnt);
if (error)
goto exit;
+
+ /* nameidata_to_filp() puts nd->path */
+ path_get(&nd->path);
}
error = may_open(&nd->path, acc_mode, open_flag);
if (error) {
- if (will_truncate)
+ if (will_truncate) {
mnt_drop_write(nd->path.mnt);
+ path_put(&nd->path);
+ }
goto exit;
}
filp = nameidata_to_filp(nd);
@@ -1578,8 +1583,10 @@ static struct file *finish_open(struct n
* because the filp has had a write taken
* on its behalf.
*/
- if (will_truncate)
+ if (will_truncate) {
mnt_drop_write(nd->path.mnt);
+ path_put(&nd->path);
+ }
return filp;
exit:
@@ -1679,8 +1686,12 @@ static struct file *do_last(struct namei
mnt_drop_write(nd->path.mnt);
goto exit;
}
+ /* nameidata_to_filp() puts nd->path */
+ mntget(nd->path.mnt);
filp = nameidata_to_filp(nd);
mnt_drop_write(nd->path.mnt);
+ mntput(nd->path.mnt);
+ path_put(&nd->path);
if (!IS_ERR(filp)) {
error = ima_file_check(filp, acc_mode);
if (error) {
next reply other threads:[~2010-10-25 13:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-25 13:16 Miklos Szeredi [this message]
2010-10-26 10:28 ` Miklos Szeredi
2010-10-29 6:58 ` Al Viro
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=E1PAMux-0002CG-8a@pomaz-ex.szeredi.hu \
--to=miklos@szeredi.hu \
--cc=akpm@linux-foundation.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@ZenIV.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®