From: Andreas Dilger <adilger@turbolinux.com>
To: torvalds@transmeta.com
Cc: Linux kernel development list <linux-kernel@vger.kernel.org>
Subject: [PATCH] ext2 root dir sanity checking
Date: Wed, 11 Jul 2001 14:51:46 -0600 (MDT) [thread overview]
Message-ID: <200107112051.f6BKplqg009583@webber.adilger.int> (raw)
This patch adds a couple of extra tests for the root inode to avoid mounting
a filesystem with an obviously corrupt root inode. This patch was prompted
a few months ago when someone was able to mount an ext2 filesystem which had
the inode table wiped out, but the superblock was still intact (they wanted
to see what was on an unused partition, so they tried mounting it).
The patch has been in the -ac kernels for a while now. It also does a bit
of consolidation of error path cleanup code.
Cheers, Andreas
==========================================================================
diff -ru linux-2.4.6.orig/fs/ext2/super.c linux-2.4.6-aed/fs/ext2/super.c
--- linux-2.4.6.orig/fs/ext2/super.c Tue May 29 13:13:19 2001
+++ linux-2.4.6-aed/fs/ext2/super.c Thu Jun 28 15:04:34 2001
@@ -454,12 +469,9 @@
sb->s_magic = le16_to_cpu(es->s_magic);
if (sb->s_magic != EXT2_SUPER_MAGIC) {
if (!silent)
- printk ("VFS: Can't find an ext2 filesystem on dev "
- "%s.\n", bdevname(dev));
- failed_mount:
- if (bh)
- brelse(bh);
- return NULL;
+ printk ("VFS: Can't find ext2 filesystem on dev %s.\n",
+ bdevname(dev));
+ goto failed_mount;
}
if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV &&
(EXT2_HAS_COMPAT_FEATURE(sb, ~0U) ||
@@ -622,11 +617,9 @@
}
}
if (!ext2_check_descriptors (sb)) {
- for (j = 0; j < db_count; j++)
- brelse (sb->u.ext2_sb.s_group_desc[j]);
- kfree(sb->u.ext2_sb.s_group_desc);
- printk ("EXT2-fs: group descriptors corrupted !\n");
- goto failed_mount;
+ printk ("EXT2-fs: group descriptors corrupted!\n");
+ db_count = i;
+ goto failed_mount2;
}
for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++) {
sb->u.ext2_sb.s_inode_bitmap_number[i] = 0;
@@ -642,17 +635,25 @@
*/
sb->s_op = &ext2_sops;
sb->s_root = d_alloc_root(iget(sb, EXT2_ROOT_INO));
- if (!sb->s_root) {
- for (i = 0; i < db_count; i++)
- if (sb->u.ext2_sb.s_group_desc[i])
- brelse (sb->u.ext2_sb.s_group_desc[i]);
- kfree(sb->u.ext2_sb.s_group_desc);
- brelse (bh);
- printk ("EXT2-fs: get root inode failed\n");
- return NULL;
+ if (!sb->s_root || !S_ISDIR(sb->s_root->d_inode->i_mode) ||
+ !sb->s_root->d_inode->i_blocks || !sb->s_root->d_inode->i_size) {
+ if (sb->s_root) {
+ dput(sb->s_root);
+ sb->s_root = NULL;
+ printk ("EXT2-fs: corrupt root inode, run e2fsck\n");
+ } else
+ printk ("EXT2-fs: get root inode failed\n");
+ goto failed_mount2;
}
ext2_setup_super (sb, es, sb->s_flags & MS_RDONLY);
return sb;
+failed_mount2:
+ for (i = 0; i < db_count; i++)
+ brelse(sb->u.ext2_sb.s_group_desc[i]);
+ kfree(sb->u.ext2_sb.s_group_desc);
+failed_mount:
+ brelse(bh);
+ return NULL;
}
static void ext2_commit_super (struct super_block * sb,
--
Andreas Dilger \ "If a man ate a pound of pasta and a pound of antipasto,
\ would they cancel out, leaving him still hungry?"
http://www-mddsp.enel.ucalgary.ca/People/adilger/ -- Dogbert
reply other threads:[~2001-07-11 20:52 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=200107112051.f6BKplqg009583@webber.adilger.int \
--to=adilger@turbolinux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.com \
/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®