Commit Graph

2880 Commits

Author SHA1 Message Date
Qu Wenruo
245cf06dfa btrfs-progs: check: do early check for read_tree_block
Although we have enhanced read_tree_block() from a lot of different
aspects, it lacks the early bytenr/blocksize alignment check.

And the lack of such check can lead to strange use-after-free bugs, due
to the fact that alloc_extent_buffer() will free overlapping extent
buffers, and allocate new eb for the usage.

So we should not allow invalid bytenr/blocksize even passed to
btrfs_find_create_tree_block().

This patch will add such check so we won't trigger use-after-free bug
then.

Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-05 10:04:24 +02:00
Qu Wenruo
767ae9e348 btrfs-progs: fuzz-test: Add image for wrong chunk item in root tree
Reported by Lukas and the same image from him.

DATA_RELOC tree's key type is modifed to CHUNK_ITEM, causing btrfsck
interpret it as CHUNK_ITEM and cause 0 num_stripes.

Add the image to fuzz-test.

Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ added bko-NNN- prefix to the files ]
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-05 10:04:19 +02:00
Qu Wenruo
2f242115d1 btrfs-progs: Do extra chunk check before processing chunk item
Current we only do chunk validation check at mount time.

It's good for most case, but for fuzzed or manually crafted images, we
can insert a CHUNK_ITEM key into root tree.

Since mount time check will only check chunk tree, it will not check
CHUNK_ITEM in root tree.

Even with previous key type check against leaf owner, it is still
possible to modify the leaf owner to by-pass it.

So we still need to check chunk validation before processing it.

Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-05 10:04:16 +02:00
Qu Wenruo
f1934f4c78 btrfs-progs: check: ignore invalid key in invalid root
Btrfs tree implies a lot of restriction on which key types are allowed
in specific roots.

Like CHUNK_ITEM keys are only valid in chunk root.

This patch will add such check at run_next_block() for original mode.

Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-05 10:04:13 +02:00
Qu Wenruo
00045ff485 btrfs-progs: Enhance and export print_key_type function
Just the same thing done for print_objectid().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-05 10:04:07 +02:00
Qu Wenruo
7aafabd2b8 btrfs-progs: Enhance and export print_objectid function
This function is quite useful for a lot of error report.
Enhance it to support custom output other than stdout.
And export it for later btrfsck enhancement.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-05 10:04:04 +02:00
David Sterba
6819fbcdca
Btrfs progs v4.7.1
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-25 19:33:48 +02:00
David Sterba
bb2ec09d51 btrfs-progs: update CHANGES for 4.7.1
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-25 19:32:50 +02:00
David Sterba
d57187703e btrfs-progs: add rest of stack operations for btrfs_dir_item
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-25 19:02:18 +02:00
David Sterba
df1d2918c3 btrfs-progs: convert: switch to common error helpers in do_rollback
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
9135ee9274 btrfs-progs: convert: reword message when conversion fails
The filesystem will not be finalized, no difference if it's before or
after the chunk mapping fixups.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
ef0db7e748 btrfs-progs: convert: switch to message helpers in do_convert
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
7cad06d970 btrfs-progs: convert: remove redundant check
The check for sectorsize is properly done in do_convert, remove the
BUG_ON.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
d4a6c73aac btrfs-progs: convert: improve error hanling of init_btrfs
Replace BUG_ONs and verbosely report the errors.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
60e45f8aa3 btrfs-progs: convert: improve error hanling of create_subvol
Replace BUG_ONs and verbosely report the errors.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
5c2e13f853 btrfs-progs: convert: improve error hanling of link_subvol
Replace BUG_ONs and verbosely report the errors.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
e0c6cf3c0e btrfs-progs: convert: make ext2 compilation honor the configure options
Now ext2 conversion will be built in iff it's selected by --with-convert
option. Default is yes.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
d7244f9582 btrfs-progs: convert: move prepare_system_chunk_sb
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
9e89a1cd42 btrfs-progs: convert: move migrate_super_block
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
a1177242d8 btrfs-progs: convert: move init_btrfs
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
c4c17f4c52 btrfs-progs: convert: move make_convert_data_block_groups
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
65eca20739 btrfs-progs: convert: move create_subvol
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
6ffb89577f btrfs-progs: convert: move link_subvol
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
c946c415dd btrfs-progs: convert: move create_image
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
3c3c59f077 btrfs-progs: convert: move convert_read_used_space
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
52df1d80a3 btrfs-progs: convert: move calculate_available_space
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
0baa7a7e68 btrfs-progs: convert: move wipe_reserved_ranges
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
f7318e2509 btrfs-progs: convert: move wipe_one_reserved_range
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
1a7ee0c296 btrfs-progs: convert: move _expand_extent_cache
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
0e4cabc479 btrfs-progs: convert: move migrate_reserved_ranges
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
d44d9fb4f0 btrfs-progs: convert: move migrate_one_reserved_range
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
3a62c6845b btrfs-progs: convert: move create_image_file_range
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
14e6cbe973 btrfs-progs: convert: move block_iterate_proc
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
58e58ab38c btrfs-progs: convert: move record_file_blocks
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
09dac60638 btrfs-progs: convert: move init_blk_iterate_data
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
70b5221bfb btrfs-progs: convert: move csum_disk_extent
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
3ec64ddf00 btrfs-progs: convert: move read_disk_extent
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
411de0cf4a btrfs-progs: convert: move convert_insert_dirent
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
f507d20d2f btrfs-progs: convert: move intersect_with_sb
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
a1e8a8739c btrfs-progs: convert: prefix all ext2-related helpers
Add ext2_ prefix to all functions that seem to be ext2-specific.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
73071f0ce4 btrfs-progs: build: extend convert options
Add --with-convert[=VALUE] option to configure. Accepts ext2, auto, yes,
or no, but will be extended to more in the future. The configure-time
defines are not used in the code, ext2 is built-in unconditionally.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
aa07e4be00 btrfs-progs: build: add per-tool cflags variable
The standalone tools are built from pattern rules, add support for
per-tool cflaags, like btrfs_something_clfags.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
b762b78a60 btrfs-progs: mkfs: cleanup, open_ctree to fs_info and use directly
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
2060b682df btrfs-progs: mkfs: kill print_version
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
e44415f713 btrfs-progs: mkfs: clean up make_image
The exact errors are printed, the removed message does not seem to be
necessary. Return proper errors.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
e1c8514705 btrfs-progs: mkfs: help and usage now to to stdout
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
b1ebc6df7b btrfs-progs: mkfs: handle and report transaction commit failures
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
33a9723066 btrfs-progs: mkfs: switch BUG_ON to error handling in traverse_directory
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
4fd93da3cf btrfs-progs: document all btrfs_open_ctree_flags
Document and add unsigned type to the values.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00
David Sterba
fa4559e424 btrfs-progs: mkfs: improve error handling in recow_roots
Return and handle errors in the callchain.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:36 +02:00