aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-04-01 13:48:14 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:01 -0400
commit0999df54f850fe1aba29b10d5c869493af107478 (patch)
treec67e0ca38e89d0872f6246093d962ce598b49ec7 /fs/btrfs/ctree.c
parentecbe2402cb4e4e7413544dc392c1a78d0f290292 (diff)
Btrfs: Verify checksums on tree blocks found without read_tree_block
Checksums were only verified by btrfs_read_tree_block, which meant the functions to probe the page cache for blocks were not validating checksums. Normally this is fine because the buffers will only be in cache if they have already been validated. But, there is a window while the buffer is being read from disk where it could be up to date in the cache but not yet verified. This patch makes sure all buffers go through checksum verification before they are used. This is safer, and it prevents modification of buffers before they go through the csum code. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.c')
-rw-r--r--fs/btrfs/ctree.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 6ba5394834be..df090bf2eec0 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -158,6 +158,8 @@ int __btrfs_cow_block(struct btrfs_trans_handle *trans,
158 } else { 158 } else {
159 root_gen = 0; 159 root_gen = 0;
160 } 160 }
161 if (!(buf->flags & EXTENT_CSUM))
162 WARN_ON(1);
161 163
162 WARN_ON(root->ref_cows && trans->transid != 164 WARN_ON(root->ref_cows && trans->transid !=
163 root->fs_info->running_transaction->transid); 165 root->fs_info->running_transaction->transid);
@@ -245,6 +247,8 @@ int btrfs_cow_block(struct btrfs_trans_handle *trans,
245 root->fs_info->generation); 247 root->fs_info->generation);
246 WARN_ON(1); 248 WARN_ON(1);
247 } 249 }
250 if (!(buf->flags & EXTENT_CSUM))
251 WARN_ON(1);
248 252
249 header_trans = btrfs_header_generation(buf); 253 header_trans = btrfs_header_generation(buf);
250 spin_lock(&root->fs_info->hash_lock); 254 spin_lock(&root->fs_info->hash_lock);
@@ -396,6 +400,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
396 if (search_start == 0) 400 if (search_start == 0)
397 search_start = last_block; 401 search_start = last_block;
398 402
403 btrfs_verify_block_csum(root, cur);
399 err = __btrfs_cow_block(trans, root, cur, parent, i, 404 err = __btrfs_cow_block(trans, root, cur, parent, i,
400 &tmp, search_start, 405 &tmp, search_start,
401 min(16 * blocksize, 406 min(16 * blocksize,