jbd2: Fail to load a journal if it is too short
authorJan Kara <jack@suse.cz>
Fri, 17 Jul 2009 14:40:01 +0000 (10:40 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 17 Jul 2009 14:40:01 +0000 (10:40 -0400)
Due to on disk corruption, it can happen that journal is too short. Fail
to load it in such case so that we don't oops somewhere later.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
fs/jbd2/journal.c

index e378cb383979a3e8e54234b14aa354e890c54e26..a8a358bc0f21792f5f675889f63d0c4123ecc04d 100644 (file)
@@ -1187,6 +1187,12 @@ static int journal_reset(journal_t *journal)
 
        first = be32_to_cpu(sb->s_first);
        last = be32_to_cpu(sb->s_maxlen);
+       if (first + JBD2_MIN_JOURNAL_BLOCKS > last + 1) {
+               printk(KERN_ERR "JBD: Journal too short (blocks %llu-%llu).\n",
+                      first, last);
+               journal_fail_superblock(journal);
+               return -EINVAL;
+       }
 
        journal->j_first = first;
        journal->j_last = last;