Btrfs: add tree block level sanity check
authorJosef Bacik <jbacik@fusionio.com>
Tue, 23 Apr 2013 15:30:14 +0000 (11:30 -0400)
committerJosef Bacik <jbacik@fusionio.com>
Mon, 6 May 2013 19:55:05 +0000 (15:55 -0400)
With a users corrupted fs I was getting weird behavior and panics and it turns
out it was because one of his tree blocks had a bogus header level.  So add this
to the sanity checks in the endio handler for tree blocks.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
fs/btrfs/disk-io.c

index bb6cdbda4f56a6539a7310ee51292df609add146..c7d8fb0dbff6686dbfbf4a4cde579932c9db0c3a 100644 (file)
@@ -613,6 +613,12 @@ static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end,
                goto err;
        }
        found_level = btrfs_header_level(eb);
+       if (found_level >= BTRFS_MAX_LEVEL) {
+               btrfs_info(root->fs_info, "bad tree block level %d\n",
+                          (int)btrfs_header_level(eb));
+               ret = -EIO;
+               goto err;
+       }
 
        btrfs_set_buffer_lockdep_class(btrfs_header_owner(eb),
                                       eb, found_level);