aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEryu Guan <guaneryu@gmail.com>2011-11-01 19:04:59 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2011-12-21 15:57:40 -0500
commitb98eb43012d8679aa6c9e5527a7cc5706ee192f6 (patch)
tree8bda82a1966d0765095a78f0d87c948469f281b6
parentf4347eb6d2aae437d9552a26704bcb07f4626d6c (diff)
jbd/jbd2: validate sb->s_first in journal_get_superblock()
commit 8762202dd0d6e46854f786bdb6fb3780a1625efe upstream. I hit a J_ASSERT(blocknr != 0) failure in cleanup_journal_tail() when mounting a fsfuzzed ext3 image. It turns out that the corrupted ext3 image has s_first = 0 in journal superblock, and the 0 is passed to journal->j_head in journal_reset(), then to blocknr in cleanup_journal_tail(), in the end the J_ASSERT failed. So validate s_first after reading journal superblock from disk in journal_get_superblock() to ensure s_first is valid. The following script could reproduce it: fstype=ext3 blocksize=1024 img=$fstype.img offset=0 found=0 magic="c0 3b 39 98" dd if=/dev/zero of=$img bs=1M count=8 mkfs -t $fstype -b $blocksize -F $img filesize=`stat -c %s $img` while [ $offset -lt $filesize ] do if od -j $offset -N 4 -t x1 $img | grep -i "$magic";then echo "Found journal: $offset" found=1 break fi offset=`echo "$offset+$blocksize" | bc` done if [ $found -ne 1 ];then echo "Magic \"$magic\" not found" exit 1 fi dd if=/dev/zero of=$img seek=$(($offset+23)) conv=notrunc bs=1 count=1 mkdir -p ./mnt mount -o loop $img ./mnt Cc: Jan Kara <jack@suse.cz> Signed-off-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Cc: Moritz Mühlenhoff <jmm@inutil.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--fs/jbd/journal.c8
-rw-r--r--fs/jbd2/journal.c8
2 files changed, 16 insertions, 0 deletions
diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c
index e2d4285fbe9..9f36384e2e8 100644
--- a/fs/jbd/journal.c
+++ b/fs/jbd/journal.c
@@ -1131,6 +1131,14 @@ static int journal_get_superblock(journal_t *journal)
1131 goto out; 1131 goto out;
1132 } 1132 }
1133 1133
1134 if (be32_to_cpu(sb->s_first) == 0 ||
1135 be32_to_cpu(sb->s_first) >= journal->j_maxlen) {
1136 printk(KERN_WARNING
1137 "JBD: Invalid start block of journal: %u\n",
1138 be32_to_cpu(sb->s_first));
1139 goto out;
1140 }
1141
1134 return 0; 1142 return 0;
1135 1143
1136out: 1144out:
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 0dfa5b598e6..40c5fb73e9c 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1251,6 +1251,14 @@ static int journal_get_superblock(journal_t *journal)
1251 goto out; 1251 goto out;
1252 } 1252 }
1253 1253
1254 if (be32_to_cpu(sb->s_first) == 0 ||
1255 be32_to_cpu(sb->s_first) >= journal->j_maxlen) {
1256 printk(KERN_WARNING
1257 "JBD2: Invalid start block of journal: %u\n",
1258 be32_to_cpu(sb->s_first));
1259 goto out;
1260 }
1261
1254 return 0; 1262 return 0;
1255 1263
1256out: 1264out: