Commit Graph

35 Commits (master)

Author SHA1 Message Date
Johannes Thumshirn e388bf386b btrfs-progs: check: warn users about the possible dangers of --repair
The manual page of btrfsck clearly states 'btrfs check --repair' is a
dangerous operation.

Although this warning is in place users do not read the manual page
and/or are used to the behaviour of fsck utilities which repair the
filesystem, and thus potentially cause harm.

Similar to 'btrfs balance' without any filters, add a warning and a
countdown, so users can bail out before eventual corrupting the
filesystem more than it already is.

To override the timeout, let --force skip it and continue.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-22 19:07:20 +01:00
Qu Wenruo d6f5504239 btrfs-progs: test/fuzz: Add image for BUG_ON() when opening the fs by btrfs check
Link: https://bugzilla.kernel.org/show_bug.cgi?id=199839
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 15:03:11 +02:00
Qu Wenruo 3fcef50906 btrfs-progs: tests/fuzz: Add fuzzed test image for btrfs check BUG_ON
This fuzzed image will not only cause kernel BUG_ON(), but also btrfs
check BUG_ON() for original mode.

Checking filesystem on /home/adam/btrfs/crafted_images/runtime/0.img
UUID: 3381d111-94a3-4ac7-8f39-611bbbdab7e6
checking extents
check/main.c:3677: check_owner_ref: BUG_ON `rec->is_root` triggered, value 1
btrfs(+0x572c2)[0x562d65da72c2]
btrfs(+0x6098d)[0x562d65db098d]
btrfs(+0x60bb6)[0x562d65db0bb6]
btrfs(+0x6179b)[0x562d65db179b]
btrfs(cmd_check+0x1199)[0x562d65db5589]
btrfs(main+0x88)[0x562d65d62768]
/usr/lib/libc.so.6(__libc_start_main+0xeb)[0x7f4fcbb1b06b]
btrfs(_start+0x2a)[0x562d65d6288a]

Link: https://bugzilla.kernel.org/show_bug.cgi?id=200403
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 15:03:09 +02:00
Qu Wenruo beb3ede39a btrfs-progs: tests/fuzz: Add image for bko-200409
Reported-by: Xu Wen <wen.xu@gatech.edu>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=200409
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 15:03:02 +02:00
David Sterba 8aee4b000d btrfs-progs: tests: add fuzzed image that triggers crash in reloc setup on mount
Reported-by: Wen Xu <wen.xu@gatech.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 14:59:40 +02:00
David Sterba a855717a87 btrfs-progs: tests: remove trivial use of local variables
No need to use a temporary variable if the parameter usage is obvious
from the context.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:55 +02:00
David Sterba a1e21ec5a8 btrfs-progs: tests: add shell quoting to fuzz test scripts
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:55 +02:00
Gu Jinxiang cebf3b3722 btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests
Use TEST_TOP as base for tests to reference any files, this will be used
for git and external testsuite.

INTERNAL_BIN is needed for referencing binaries that could reside in
different paths in git vs external testsuite.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
[ add quotes around sourced files, update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-13 15:41:32 +01:00
David Sterba 092698b40a btrfs-progs: tests: add more fuzzed images from bugzilla
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-08 16:15:05 +02:00
Qu Wenruo fa77a1b5a3 btrfs-progs: tests: Move fsck-tests/015 to fuzz tests
The test case fsck-tests/015-check-bad-memory-access can't be repair by
btrfs check, and it's a fortunate bug makes original mode to forget the
error code from extent tree, making original mode pass it.

So fuzz-tests is more suitable for it.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:49 +01:00
David Sterba 5ee216a86f btrfs-progs: tests: add more fuzzed images from bugzilla
Fixing the problems by one does not scale now. Add more images despite
the fuzz tests will fail. They have been for some time already.

Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-23 10:49:37 +01:00
David Sterba a5ac954153 btrfs-progs: tests: split test 004 to separate tests
Makes testing specific tool easier.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-05 12:39:01 +02:00
David Sterba 35d0588b64 btrfs-progs: tests: add fuzzed image with bad parent refs, qgroup-verify
Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-03 15:07:24 +02:00
David Sterba 801f15bdf1 btrfs-progs: tests: add fuzzed images with bad blocksize/lengh of eb
Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-03 15:07:24 +02:00
David Sterba 5a38a52194 btrfs-progs: tests: iterate over fuzzed images and test various tools
Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-03 15:07:21 +02:00
David Sterba da64ae3a0f btrfs-progs: reorganize extent_buffer and fix alignment of data
Reported by UBSAN, the checksum code tries to access unaligned data that
come from the extent_buffer.

struct extent_buffer {
        struct cache_extent        cache_node;           /*     0    48 */
        u64                        start;                /*    48     8 */
        u64                        dev_bytenr;           /*    56     8 */
        /* --- cacheline 1 boundary (64 bytes) --- */
        u32                        len;                  /*    64     4 */

        /* XXX 4 bytes hole, try to pack */

        struct extent_io_tree *    tree;                 /*    72     8 */
        struct list_head           lru;                  /*    80    16 */
        struct list_head           recow;                /*    96    16 */
        int                        refs;                 /*   112     4 */
        u32                        flags;                /*   116     4 */
        int                        fd;                   /*   120     4 */
        char                       data[0];              /*   124     0 */

        /* size: 128, cachelines: 2, members: 11 */
        /* sum members: 120, holes: 1, sum holes: 4 */
        /* padding: 4 */
};

Add explicit alignment to data.

Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=156471
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 11:50:05 +02:00
David Sterba 2125a65533 btrfs-progs: tests: add fuzzed images for bad block group offset
Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 11:49:41 +02:00
David Sterba 5150103fcf btrfs-progs: tests: run check with various options on the fuzzed images
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 11:48:41 +02:00
David Sterba faaeee5bf3 btrfs-progs: tests: add fuzz test to try btrfs-image on all images
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 11:48:37 +02:00
David Sterba 9fc5aefe45 btrfs-progs: tests: rename test 001 to mention check
Make it more clear that the test does 'btrfs check'.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 11:48:24 +02:00
David Sterba 05b6d8b187 btrfs-progs: tests: add fuzzed image for a bad backref
Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 11:48:16 +02:00
David Sterba 7d6307dcf3 btrfs-progs: tests: add fuzzed image for heap overflow while checking chunk items
Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-05 12:20:24 +02:00
David Sterba 386cdcd741 btrfs-progs: tests: add fuzzed image for invalid chunk sectorsize
Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-05 12:20:24 +02:00
David Sterba 083721de5c btrfs-progs: tests: add fuzzed image for invalid sys_array and stripe_len
Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-05 12:20:24 +02:00
David Sterba 1e4ef75053 btrfs-progs: tests: add fuzzed image for invalid sub_stripe value
Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-05 12:20:24 +02:00
Qu Wenruo 8607100a9b btrfs-progs: fuzz-test: Add test case for unaligned extent item
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:05:05 +02:00
Qu Wenruo f51a34696b btrfs-progs: fuzz-test: Add test case for invalid drop level
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:36 +02:00
Qu Wenruo ba23b7679f btrfs-progs: fuzz-test: Add image for unaligned tree block ptr
Add test case image for unaligned tree block ptr.
It should lead to BUG_ON in free_extent_buffer().

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:27 +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
Luis Henriques 82aaf603e0 btrfs-progs: tests: 001-simple-unmounted: fix test failure due to bashism
The usage of 'source' is a bashism, and '.' should be used instead.  This
is causing fuzz-tests/001-simple-unmounted to fail in systems where
/bin/sh isn't bash:

    [TEST/fuzz]   001-simple-unmounted
./test.sh: 5: ./test.sh: source: not found
./test.sh: 7: ./test.sh: setup_root_helper: not found
./test.sh: 8: ./test.sh: check_prereq: not found
./test.sh: 18: ./test.sh: check_all_images: not found

Since most (all?) tests actually use /bin/bash, change this test to use
bash too.

Signed-off-by: Luis Henriques <henrix@camandro.org>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-04 13:37:24 +02:00
Liu Bo f2873c47d7 btrfs-progs: add fuzzed testing images, superblock and chunks
This adds 4 fuzz testing images, btrfsck either doesn't detect errors
in them or crashes immediately.

Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Reported-by: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-11 16:37:48 +02:00
David Sterba 9f76654de8 btrfs-progs: tests: add image for bko#96971 (bad checksum type)
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
David Sterba 5f03d1fc23 btrfs-progs: tests: add sys-array-num-stripes-0.raw.xz
Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-04 11:28:24 +01:00
David Sterba dfed5799db btrfs-progs: tests: 001-simple-unmounted: iterate over fuzzed images and run check
Signed-off-by: David Sterba <dsterba@suse.com>
2015-11-02 09:35:07 +01:00
David Sterba a365b84a32 btrfs-progs: tests: add crafted and fuzzed images
A collection of several images that were produced in a non-standard way
and cause various errors in check or image tools. They do not fit into
the fsck tests as we're not able to repair any of them, but the tools
should not crash or do out-of-bounds access.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-09 17:09:01 +02:00