From: Wu Fengguang <fengguang.wu@intel.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Avan Anishchuk <matimatik@gmail.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Pekka Enberg <penberg@cs.helsinki.fi>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
Subject: [PATCH] ramfs: fix double freeing s_fs_info on failed mount
Date: Tue, 7 Apr 2009 14:16:50 +0800 [thread overview]
Message-ID: <20090407061650.GA31745@localhost> (raw)
In-Reply-To: <20090407060309.GA21788@elte.hu>
From: Ingo Molnar <mingo@elte.hu>
If ramfs mount fails, s_fs_info will be freed twice in ramfs_fill_super()
and ramfs_kill_sb(), leading to kernel oops.
Consolidate and beautify the code.
Make sure s_fs_info and s_root are in known good states.
Acked-by: Wu Fengguang <fengguang.wu@intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
fs/ramfs/inode.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
--- mm.orig/fs/ramfs/inode.c
+++ mm/fs/ramfs/inode.c
@@ -221,22 +221,23 @@ static int ramfs_fill_super(struct super
save_mount_options(sb, data);
fsi = kzalloc(sizeof(struct ramfs_fs_info), GFP_KERNEL);
+ sb->s_fs_info = fsi;
if (!fsi) {
err = -ENOMEM;
goto fail;
}
- sb->s_fs_info = fsi;
err = ramfs_parse_options(data, &fsi->mount_opts);
if (err)
goto fail;
- sb->s_maxbytes = MAX_LFS_FILESIZE;
- sb->s_blocksize = PAGE_CACHE_SIZE;
- sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
- sb->s_magic = RAMFS_MAGIC;
- sb->s_op = &ramfs_ops;
- sb->s_time_gran = 1;
+ sb->s_maxbytes = MAX_LFS_FILESIZE;
+ sb->s_blocksize = PAGE_CACHE_SIZE;
+ sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
+ sb->s_magic = RAMFS_MAGIC;
+ sb->s_op = &ramfs_ops;
+ sb->s_time_gran = 1;
+
inode = ramfs_get_inode(sb, S_IFDIR | fsi->mount_opts.mode, 0);
if (!inode) {
err = -ENOMEM;
@@ -244,14 +245,16 @@ static int ramfs_fill_super(struct super
}
root = d_alloc_root(inode);
+ sb->s_root = root;
if (!root) {
err = -ENOMEM;
goto fail;
}
- sb->s_root = root;
+
return 0;
fail:
kfree(fsi);
+ sb->s_fs_info = NULL;
iput(inode);
return err;
}
next prev parent reply other threads:[~2009-04-07 6:17 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-05 19:39 [GIT PULL] SLAB include file dependency fixes + kmemtrace updates Ingo Molnar
2009-04-05 19:56 ` Linus Torvalds
2009-04-05 20:02 ` Linus Torvalds
2009-04-07 1:51 ` Linus Torvalds
2009-04-07 3:51 ` Linus Torvalds
2009-04-07 4:20 ` Linus Torvalds
2009-04-07 4:45 ` Linus Torvalds
2009-04-07 5:02 ` Wu Fengguang
2009-04-07 5:28 ` [patch] ramfs: add support for "mode=" mount option, fix Ingo Molnar
2009-04-07 5:55 ` Wu Fengguang
2009-04-07 6:03 ` Ingo Molnar
2009-04-07 6:16 ` Wu Fengguang [this message]
2009-04-07 6:53 ` [PATCH] ramfs: fix double freeing s_fs_info on failed mount Ingo Molnar
2009-04-07 7:05 ` Wu Fengguang
2009-04-07 6:20 ` [PATCH] ramfs: add support for "mode=" mount option, fix Ingo Molnar
2009-04-07 5:30 ` [GIT PULL] SLAB include file dependency fixes + kmemtrace updates Wu Fengguang
2009-04-07 4:58 ` Ingo Molnar
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=20090407061650.GA31745@localhost \
--to=fengguang.wu@intel.com \
--cc=akpm@linux-foundation.org \
--cc=eduard.munteanu@linux360.ro \
--cc=linux-kernel@vger.kernel.org \
--cc=matimatik@gmail.com \
--cc=mingo@elte.hu \
--cc=penberg@cs.helsinki.fi \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox