aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Bo <bo.li.liu@oracle.com>2016-09-14 20:22:57 -0400
committerDavid Sterba <dsterba@suse.com>2016-09-26 12:03:47 -0400
commit3eb548ee3a8042d95ad81be254e67a5222c24e03 (patch)
tree4c43a736bd3ea8f094c060afed9c000278e65348
parent3561b9db70928f207be4570b48fc19898eeaef54 (diff)
Btrfs: memset to avoid stale content in btree node block
During updating btree, we could push items between sibling nodes/leaves, for leaves data sections starts reversely from the end of the block while for nodes we only have key pairs which are stored one by one from the start of the block. So we could do try to push key pairs from one node to the next node right in the tree, and after that, we update the node's nritems to reflect the correct end while leaving the stale content in the node. One may intentionally corrupt the fs image and access the stale content by bumping the nritems and causes various crashes. This takes the in-memory @nritems as the correct one and gets to memset the unused part of a btree node. Signed-off-by: Liu Bo <bo.li.liu@oracle.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/extent_io.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index c046addd9917..288ee90a9823 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3732,6 +3732,17 @@ static noinline_for_stack int write_one_eb(struct extent_buffer *eb,
3732 if (btrfs_header_owner(eb) == BTRFS_TREE_LOG_OBJECTID) 3732 if (btrfs_header_owner(eb) == BTRFS_TREE_LOG_OBJECTID)
3733 bio_flags = EXTENT_BIO_TREE_LOG; 3733 bio_flags = EXTENT_BIO_TREE_LOG;
3734 3734
3735 /* set btree node beyond nritems with 0 to avoid stale content */
3736 if (btrfs_header_level(eb) > 0) {
3737 u32 nritems;
3738 unsigned long end;
3739
3740 nritems = btrfs_header_nritems(eb);
3741 end = btrfs_node_key_ptr_offset(nritems);
3742
3743 memset_extent_buffer(eb, 0, end, eb->len - end);
3744 }
3745
3735 for (i = 0; i < num_pages; i++) { 3746 for (i = 0; i < num_pages; i++) {
3736 struct page *p = eb->pages[i]; 3747 struct page *p = eb->pages[i];
3737 3748