summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/tree-checker.c
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2019-05-02 20:30:54 -0400
committerDavid Sterba <dsterba@suse.com>2019-07-01 07:34:55 -0400
commit4c094c33c9ed4b8d0d814bd1d7ff78e123d15d00 (patch)
tree86ef74dc7d56ae2f936d1f8c3c799daeac78f522 /fs/btrfs/tree-checker.c
parent2ed95d2d59b065f4db2fd42752cbe9a00969f2bd (diff)
btrfs: tree-checker: Check if the file extent end overflows
Under certain conditions, we could have strange file extent item in log tree like: item 18 key (69599 108 397312) itemoff 15208 itemsize 53 extent data disk bytenr 0 nr 0 extent data offset 0 nr 18446744073709547520 ram 18446744073709547520 The num_bytes + ram_bytes overflow 64 bit type. For num_bytes part, we can detect such overflow along with file offset (key->offset), as file_offset + num_bytes should never go beyond u64. For ram_bytes part, it's about the decompressed size of the extent, not directly related to the size. In theory it is OK to have a large value, and put extra limitation on RAM bytes may cause unexpected false alerts. So in tree-checker, we only check if the file offset and num bytes overflow. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/tree-checker.c')
-rw-r--r--fs/btrfs/tree-checker.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
index 96fce4bef4e7..ccd5706199d7 100644
--- a/fs/btrfs/tree-checker.c
+++ b/fs/btrfs/tree-checker.c
@@ -132,6 +132,7 @@ static int check_extent_data_item(struct extent_buffer *leaf,
132 struct btrfs_file_extent_item *fi; 132 struct btrfs_file_extent_item *fi;
133 u32 sectorsize = fs_info->sectorsize; 133 u32 sectorsize = fs_info->sectorsize;
134 u32 item_size = btrfs_item_size_nr(leaf, slot); 134 u32 item_size = btrfs_item_size_nr(leaf, slot);
135 u64 extent_end;
135 136
136 if (!IS_ALIGNED(key->offset, sectorsize)) { 137 if (!IS_ALIGNED(key->offset, sectorsize)) {
137 file_extent_err(leaf, slot, 138 file_extent_err(leaf, slot,
@@ -207,6 +208,16 @@ static int check_extent_data_item(struct extent_buffer *leaf,
207 CHECK_FE_ALIGNED(leaf, slot, fi, num_bytes, sectorsize)) 208 CHECK_FE_ALIGNED(leaf, slot, fi, num_bytes, sectorsize))
208 return -EUCLEAN; 209 return -EUCLEAN;
209 210
211 /* Catch extent end overflow */
212 if (check_add_overflow(btrfs_file_extent_num_bytes(leaf, fi),
213 key->offset, &extent_end)) {
214 file_extent_err(leaf, slot,
215 "extent end overflow, have file offset %llu extent num bytes %llu",
216 key->offset,
217 btrfs_file_extent_num_bytes(leaf, fi));
218 return -EUCLEAN;
219 }
220
210 /* 221 /*
211 * Check that no two consecutive file extent items, in the same leaf, 222 * Check that no two consecutive file extent items, in the same leaf,
212 * present ranges that overlap each other. 223 * present ranges that overlap each other.