LWN.net Logo

[PATCH] hfs, hfsplus: don't leak s_fs_info and fix an oops

From:  Linux Kernel Mailing List <linux-kernel-AT-vger.kernel.org>
To:  bk-commits-head-AT-vger.kernel.org
Subject:  [PATCH] hfs, hfsplus: don't leak s_fs_info and fix an oops
Date:  Sun, 1 May 2005 10:08:37 -0700
Archive-link:  Article, Thread

tree 7e0d6b79250aa2a5d0b51e9368e89b5f92cfe88e
parent 954d3e95369cf73b4bc1e570729f68264a0e6fe0
author Colin Leroy <colin@colino.net> Sun, 01 May 2005 22:59:16 -0700
committer Linus Torvalds <torvalds@ppc970.osdl.org> Sun, 01 May 2005 22:59:16 -0700

[PATCH] hfs, hfsplus: don't leak s_fs_info and fix an oops

This patch fixes the leak of sb->s_fs_info in both the HFS and HFS+
modules.  In addition to this, it fixes an oops happening when trying to
mount a non-hfsplus filesystem using hfsplus.  This patch is from Roman
Zippel, based off patches sent by myself.

Signed-off-by: Colin Leroy <colin@colino.net>
Signed-off-by: Roman Zippel <zippel@linux-m68k.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

 hfs/mdb.c       |    5 +++++
 hfs/super.c     |    8 +++-----
 hfsplus/super.c |    6 +++++-
 3 files changed, 13 insertions(+), 6 deletions(-)

Index: fs/hfs/mdb.c
===================================================================
--- 542c6435428848f02a0eb060a83b3dd1a7f90083/fs/hfs/mdb.c  (mode:100644
sha1:4efb640c4d0cc838938a1d1c202c3eb47d44ecc8)
+++ 7e0d6b79250aa2a5d0b51e9368e89b5f92cfe88e/fs/hfs/mdb.c  (mode:100644
sha1:217e32f37e0be7bce323a9962c0cf95adb394b9e)
@@ -333,6 +333,8 @@ void hfs_mdb_close(struct super_block *s
  * Release the resources associated with the in-core MDB.  */
 void hfs_mdb_put(struct super_block *sb)
 {
+	if (!HFS_SB(sb))
+		return;
 	/* free the B-trees */
 	hfs_btree_close(HFS_SB(sb)->ext_tree);
 	hfs_btree_close(HFS_SB(sb)->cat_tree);
@@ -340,4 +342,7 @@ void hfs_mdb_put(struct super_block *sb)
 	/* free the buffers holding the primary and alternate MDBs */
 	brelse(HFS_SB(sb)->mdb_bh);
 	brelse(HFS_SB(sb)->alt_mdb_bh);
+
+	kfree(HFS_SB(sb));
+	sb->s_fs_info = NULL;
 }
Index: fs/hfs/super.c
===================================================================
--- 542c6435428848f02a0eb060a83b3dd1a7f90083/fs/hfs/super.c  (mode:100644
sha1:1e2c193134cc81732cb10f116d647f370b0901ef)
+++ 7e0d6b79250aa2a5d0b51e9368e89b5f92cfe88e/fs/hfs/super.c  (mode:100644
sha1:ab783f6afa3b08d00c18c564b598f353af07084f)
@@ -297,7 +297,7 @@ static int hfs_fill_super(struct super_b
 	res = -EINVAL;
 	if (!parse_options((char *)data, sbi)) {
 		hfs_warn("hfs_fs: unable to parse mount options.\n");
-		goto bail3;
+		goto bail;
 	}
 
 	sb->s_op = &hfs_super_operations;
@@ -310,7 +310,7 @@ static int hfs_fill_super(struct super_b
 			hfs_warn("VFS: Can't find a HFS filesystem on dev %s.\n",
 				hfs_mdb_name(sb));
 		res = -EINVAL;
-		goto bail2;
+		goto bail;
 	}
 
 	/* try to get the root inode */
@@ -340,10 +340,8 @@ bail_iput:
 	iput(root_inode);
 bail_no_root:
 	hfs_warn("hfs_fs: get root inode failed.\n");
+bail:
 	hfs_mdb_put(sb);
-bail2:
-bail3:
-	kfree(sbi);
 	return res;
 }
 
Index: fs/hfsplus/super.c
===================================================================
--- 542c6435428848f02a0eb060a83b3dd1a7f90083/fs/hfsplus/super.c  (mode:100644
sha1:5f8044664a3c4e772e9590344499a79081c946c8)
+++ 7e0d6b79250aa2a5d0b51e9368e89b5f92cfe88e/fs/hfsplus/super.c  (mode:100644
sha1:d55ad67b8e4238e3625f2139b78b353858337657)
@@ -208,7 +208,9 @@ static void hfsplus_write_super(struct s
 static void hfsplus_put_super(struct super_block *sb)
 {
 	dprint(DBG_SUPER, "hfsplus_put_super\n");
-	if (!(sb->s_flags & MS_RDONLY)) {
+	if (!sb->s_fs_info)
+		return;
+	if (!(sb->s_flags & MS_RDONLY) && HFSPLUS_SB(sb).s_vhdr) {
 		struct hfsplus_vh *vhdr = HFSPLUS_SB(sb).s_vhdr;
 
 		vhdr->modify_date = hfsp_now2mt();
@@ -226,6 +228,8 @@ static void hfsplus_put_super(struct sup
 	brelse(HFSPLUS_SB(sb).s_vhbh);
 	if (HFSPLUS_SB(sb).nls)
 		unload_nls(HFSPLUS_SB(sb).nls);
+	kfree(sb->s_fs_info);
+	sb->s_fs_info = NULL;
 }
 
 static int hfsplus_statfs(struct super_block *sb, struct kstatfs *buf)


(Log in to post comments)

Copyright © 2005, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds