fs/befs/linuxvfs.c: check superblock before dump operation
authorFabian Frederick <fabf@skynet.be>
Fri, 8 Aug 2014 21:20:31 +0000 (14:20 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 8 Aug 2014 22:57:20 +0000 (15:57 -0700)
befs_dump_super_block was called between befs_load_sb and befs_check_sb.
It has been reported to crash (5/900) with null block testing.

This patch loads, checks and only dump superblock if it's a valid one
then brelse bh.

(befs_dump_super_block uses disk_sb (bh->b_data) so it seems we need to
call it before brelse(bh) but I don't know why befs_check_sb was called
after brelse.  Another thing I don't understand is why this problem
appears now).

Signed-off-by: Fabian Frederick <fabf@skynet.be>
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/befs/linuxvfs.c

index 0d6c07cc1149191d0f46e38e87142987e0fd41ad..4cf61ec6b7a8ee539e0caa63d548f8aa4222ad0f 100644 (file)
@@ -832,16 +832,14 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
                    (befs_super_block *) ((void *) bh->b_data + x86_sb_off);
        }
 
-       if (befs_load_sb(sb, disk_sb) != BEFS_OK)
+       if ((befs_load_sb(sb, disk_sb) != BEFS_OK) ||
+           (befs_check_sb(sb) != BEFS_OK))
                goto unacquire_bh;
 
        befs_dump_super_block(sb, disk_sb);
 
        brelse(bh);
 
-       if (befs_check_sb(sb) != BEFS_OK)
-               goto unacquire_priv_sbp;
-
        if( befs_sb->num_blocks > ~((sector_t)0) ) {
                befs_error(sb, "blocks count: %llu "
                        "is larger than the host can use",