public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
From: "Chen, Kenneth W" <kenneth.w.chen@intel.com>
To: linux-ia64@vger.kernel.org
Subject: Hugetlbf segv on invalid mount option and mem leak
Date: Fri, 26 Sep 2003 22:00:50 +0000	[thread overview]
Message-ID: <marc-linux-ia64-106461366326303@msgid-missing> (raw)

[-- Attachment #1: Type: text/plain, Size: 627 bytes --]

Here is a patch that fixes a rather nasty bug in hugetlbfs.  If root
tries to mount a hugetlbfs with invalid mount option,
hugetlbfs_fill_super incorrectly returns error code instead of NULL on
couple error conditions, causing generic vfs layer to segfault and took
some semaphore with it, the end result is kernel hang on any subsequent
file system mount/unmount.  There are some other cases that has memory
leak upon error conditions.

The first problem is 2.4 specific, while memleak problem exist in both
2.4 and 2.6.
Bjorn, again, would you please merge in your 2.4 tree?  I'll push the
rest for 2.6.

- Ken

[-- Attachment #2: hugetlbfs-memleak.patch --]
[-- Type: application/octet-stream, Size: 1574 bytes --]

diff -Nurp 2.4.23-pre5/fs/hugetlbfs/inode.c 2.4.23-pre5.ken/fs/hugetlbfs/inode.c
--- 2.4.23-pre5/fs/hugetlbfs/inode.c	Fri Sep 26 14:47:03 2003
+++ 2.4.23-pre5.ken/fs/hugetlbfs/inode.c	Fri Sep 26 14:28:21 2003
@@ -622,23 +622,21 @@ hugetlbfs_fill_super(struct super_block 
 {
 	struct inode * inode;
 	struct dentry * root;
-	int ret;
 	struct hugetlbfs_config config;
 	struct hugetlbfs_sb_info *sbinfo;
 
-	sbinfo = kmalloc(sizeof(struct hugetlbfs_sb_info), GFP_KERNEL);
-	if (!sbinfo)
-		return -ENOMEM;
-	sb->u.generic_sbp = sbinfo;
- 
 	config.nr_blocks = -1; /* No limit on size by default. */
 	config.nr_inodes = -1; /* No limit on number of inodes by default. */
 	config.uid = current->fsuid;
 	config.gid = current->fsgid;
 	config.mode = 0755;
-	ret = hugetlbfs_parse_options(data, &config);
-	if (ret)
-		return ret;
+	if (hugetlbfs_parse_options(data, &config))
+		return NULL;
+
+	sbinfo = kmalloc(sizeof(struct hugetlbfs_sb_info), GFP_KERNEL);
+	if (!sbinfo)
+		return NULL;
+	sb->u.generic_sbp = sbinfo;
 
 	spin_lock_init(&sbinfo->stat_lock);
 	sbinfo->max_blocks = config.nr_blocks;
@@ -652,15 +650,18 @@ hugetlbfs_fill_super(struct super_block 
 	inode = hugetlbfs_get_inode(sb, config.uid, config.gid,
 				S_IFDIR | config.mode, 0);
 	if (!inode)
-		return NULL;
+		goto out_free;
 
 	root = d_alloc_root(inode);
 	if (!root) {
 		iput(inode);
-		return NULL;
+		goto out_free;
 	}
 	sb->s_root = root;
 	return sb;
+out_free:
+	kfree(sbinfo);
+	return NULL;
 }
 
 static DECLARE_FSTYPE(hugetlbfs_fs_type, "hugetlbfs", hugetlbfs_fill_super, FS_LITTER);

                 reply	other threads:[~2003-09-26 22:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=marc-linux-ia64-106461366326303@msgid-missing \
    --to=kenneth.w.chen@intel.com \
    --cc=linux-ia64@vger.kernel.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