Thread (8 messages) 8 messages, 3 authors, 2016-08-30
STALE3595d

[PATCH 3/5] btrfs-progs: fsck: Check bytenr alignment for extent item

From: Qu Wenruo <hidden>
Date: 2016-08-30 07:22:29
Subsystem: the rest · Maintainer: Linus Torvalds

Check bytenr alignment for extent item to filter invalid items early.

Signed-off-by: Qu Wenruo <redacted>
---
 cmds-check.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff --git a/cmds-check.c b/cmds-check.c
index 2aa0a7b..c56b176 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;
-- 
2.9.3


Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help