diff options
author | Qu Wenruo <quwenruo@cn.fujitsu.com> | 2016-08-30 15:22:15 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-09-05 10:04:40 +0200 |
commit | 77deae9cb712e543dc7a8cbd4d80ca219f798084 (patch) | |
tree | 5ca9f2ef4d2371544dfb542bc14f83bcff4154a7 /cmds-check.c | |
parent | f51a34696bff9c60bc03d6a9c2934121d9423061 (diff) |
btrfs-progs: fsck: Check bytenr alignment for extent item
Check bytenr alignment for extent item to filter invalid items early.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-check.c')
-rw-r--r-- | cmds-check.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/cmds-check.c b/cmds-check.c index 2aa0a7bf..c56b176d 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -5422,6 +5422,11 @@ static int process_extent_item(struct btrfs_root *root, num_bytes = key.offset; } + if (!IS_ALIGNED(key.objectid, root->sectorsize)) { + error("ignoring invalid extent, bytenr %llu is not aligned to %u", + key.objectid, root->sectorsize); + return -EIO; + } if (item_size < sizeof(*ei)) { #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 struct btrfs_extent_item_v0 *ei0; @@ -5448,6 +5453,16 @@ static int process_extent_item(struct btrfs_root *root, metadata = 1; else metadata = 0; + if (metadata && num_bytes != root->nodesize) { + error("ignore invalid metadata extent, length %llu does not equal to %u", + num_bytes, root->nodesize); + return -EIO; + } + if (!metadata && !IS_ALIGNED(num_bytes, root->sectorsize)) { + error("ignore invalid data extent, length %llu is not aligned to %u", + num_bytes, root->sectorsize); + return -EIO; + } memset(&tmpl, 0, sizeof(tmpl)); tmpl.start = key.objectid; |