Skip to contentSkip to conversation

btrfs-progs: block group: do not exclude bytenr adjacent to block group

PATCH In review [email protected] 2 participants 3 messages Nov 18, 2019 – Nov 20, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 btrfs-progs: block group: do not exclude bytenr adjacent to block group

From: Su Yue <[email protected]>

While checking the image provided by the reporter, the btrfsck aborts:
======================================================================
Opening filesystem to check...
extent_io.c:158: insert_state: BUG_ON end < start triggered, value 1 btrfs check(+0xa3fa8)[0x5614c14c7fa8]
btrfs check(+0xa4046)[0x5614c14c8046]
btrfs check(+0xa45f1)[0x5614c14c85f1]
btrfs check(set_extent_bits+0x83)[0x5614c14c8c63]
btrfs check(+0xbfb90)[0x5614c14e3b90]
btrfs check(exclude_super_stripes+0x1fc)[0x5614c14e3de9] btrfs check(+0xbd85d)[0x5614c14e185d]
btrfs check(btrfs_read_block_groups+0xd3)[0x5614c14e19f5] btrfs check(btrfs_setup_all_roots+0x454)[0x5614c14d7740] btrfs check(+0xb4219)[0x5614c14d8219]
btrfs check(open_ctree_fs_info+0x177)[0x5614c14d8415]
btrfs check(+0x693dd)[0x5614c148d3dd]
btrfs check(+0x14dc7)[0x5614c1438dc7]
btrfs check(main+0x126)[0x5614c1439713] /usr/lib/libc.so.6(__libc_start_main+0xf3)[0x7fe3f1ecf153] btrfs check(_start+0x2e)[0x5614c1438cce]
[1] 6196 abort (core dumped)
======================================================================

It's excluding super stripes from one block group, the bytenr equals block group's start + len, so the @num_bytes is 0. Then add_exclude_extent() calculates the @end is less than the @start which trigers the abort.

Anyway, the logical bytenr should not be excluded if the block group's start + len equals it, because it's not belong to the block group.

---
 extent-tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
extent-tree.c +1 -1
index f690ae999f37..848fb72f90a4 100644
@@ -3630,7 +3630,7 @@ int exclude_super_stripes(struct btrfs_fs_info *fs_info,
 		while (nr--) {
 			u64 start, len;
 
-			if (logical[nr] > cache->key.objectid +
+			if (logical[nr] >= cache->key.objectid +
 			    cache->key.offset)
 				continue;
 
Signature · 1 line
2.23.0
#1 lore raw

PATCH 2/2 btrfs-progs: fuzz-tests: add image trigers abort of open_ctree()

From: Su Yue <[email protected]>

This test case contains a bad block of dev tree and trigers abort while open_ctree() due to its exquisite chunk layout. It can't be repaired by fsck, so put it into fuzz-tests/images.

The image is provided by Ruud van Asseldonk. This commit just did xz and writes the record.

---
 .../images/bad-dev-tree-node.raw.txt          |  58 ++++++++++++++++++
 .../images/bad-dev-tree-node.raw.xz           | Bin 0 -> 18788 bytes
 2 files changed, 58 insertions(+)
 create mode 100644 tests/fuzz-tests/images/bad-dev-tree-node.raw.txt
 create mode 100644 tests/fuzz-tests/images/bad-dev-tree-node.raw.xz
tests/fuzz-tests/images/bad-dev-tree-node.raw.txt new file +58 -0
new file mode 100644
index 000000000000..64935568c7a6
@@ -0,0 +1,58 @@
+URL: https://github.com/kdave/btrfs-progs/issues/210
+
+ruuda commented on Sep 24
+Running btrfs check on the attached minimal file system causes the following:
+
+Opening filesystem to check...
+extent_io.c:158: insert_state: BUG_ON `end < start` triggered, value 1
+btrfs(+0x2de57)[0x560c4d7cfe57]
+btrfs(+0x2e210)[0x560c4d7d0210]
+btrfs(set_extent_bits+0x254)[0x560c4d7d0854]
+btrfs(exclude_super_stripes+0xbf)[0x560c4d7c65ff]
+btrfs(btrfs_read_block_groups+0x29d)[0x560c4d7c698d]
+btrfs(btrfs_setup_all_roots+0x3f3)[0x560c4d7c0b23]
+btrfs(+0x1ef53)[0x560c4d7c0f53]
+btrfs(open_ctree_fs_info+0x90)[0x560c4d7c11a0]
+btrfs(+0x6d3f9)[0x560c4d80f3f9]
+btrfs(main+0x94)[0x560c4d7b60c4]
+/usr/lib/libc.so.6(__libc_start_main+0xf3)[0x7fd189773ee3]
+btrfs(_start+0x2e)[0x560c4d7b635e]
+zsh: abort (core dumped)  btrfs check /tmp/bad.btrfs
+Tested versions:
+
+v5.2.1 as shipped by Arch in 5.2.1-1
+v5.2.2 built from source (55a8c96)
+Data to reproduce:
+
+4a2d85625461bfed3cb60c53e5e913.zip
+
+GDB output:
+Starting program: /btrfs-progs/btrfs check bad-dev-tree-node.raw
+[Thread debugging using libthread_db enabled]
+Using host libthread_db library "/usr/lib/libthread_db.so.1".
+Opening filesystem to check...
+extent_io.c:158: insert_state: BUG_ON `end < start` triggered, value 1
+/btrfs-progs/btrfs(+0xa3fa8)[0x5555555f7fa8]
+/btrfs-progs/btrfs(+0xa4046)[0x5555555f8046]
+/btrfs-progs/btrfs(+0xa45f1)[0x5555555f85f1]
+/btrfs-progs/btrfs(set_extent_bits+0x83)[0x5555555f8c63]
+/btrfs-progs/btrfs(+0xbfb90)[0x555555613b90]
+/btrfs-progs/btrfs(exclude_super_stripes+0x1fc)[0x555555613de9]
+/btrfs-progs/btrfs(+0xbd85d)[0x55555561185d]
+/btrfs-progs/btrfs(btrfs_read_block_groups+0xd3)[0x5555556119f5]
+/btrfs-progs/btrfs(btrfs_setup_all_roots+0x454)[0x555555607740]
+/btrfs-progs/btrfs(+0xb4219)[0x555555608219]
+/btrfs-progs/btrfs(open_ctree_fs_info+0x177)[0x555555608415]
+/btrfs-progs/btrfs(+0x693dd)[0x5555555bd3dd]
+/btrfs-progs/btrfs(+0x14dc7)[0x555555568dc7]
+/btrfs-progs/btrfs(main+0x126)[0x555555569713]
+/usr/lib/libc.so.6(__libc_start_main+0xf3)[0x7ffff7a85153]
+/btrfs-progs/btrfs(_start+0x2e)[0x555555568cce]
+
+Program received signal SIGABRT, Aborted.
+0x00007ffff7a99f25 in raise () from /usr/lib/libc.so.6
+
+
+The compressed fuzz image causes above btrfsck abort.
+Fixed by commit "btrfs-progs: block group: do not exclude bytenr
+adjacent to block group".
tests/fuzz-tests/images/bad-dev-tree-node.raw.xz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..a6e62106da03d81a2dbafa23f0c8082d75f82af0
GIT binary patch
Signature · 1 line
2.23.0
#2 lore raw
In reply to [email protected]

Drop those too, will send new version fixed by another method.

Quoted 54 lines · On 2019/11/18 at 13:53, [email protected] wrote:

From: Su Yue <[email protected]>

While checking the image provided by the reporter, the btrfsck aborts:
======================================================================
Opening filesystem to check...
extent_io.c:158: insert_state: BUG_ON end < start triggered, value 1 btrfs check(+0xa3fa8)[0x5614c14c7fa8]
btrfs check(+0xa4046)[0x5614c14c8046]
btrfs check(+0xa45f1)[0x5614c14c85f1]
btrfs check(set_extent_bits+0x83)[0x5614c14c8c63]
btrfs check(+0xbfb90)[0x5614c14e3b90]
btrfs check(exclude_super_stripes+0x1fc)[0x5614c14e3de9] btrfs check(+0xbd85d)[0x5614c14e185d]
btrfs check(btrfs_read_block_groups+0xd3)[0x5614c14e19f5] btrfs check(btrfs_setup_all_roots+0x454)[0x5614c14d7740] btrfs check(+0xb4219)[0x5614c14d8219]
btrfs check(open_ctree_fs_info+0x177)[0x5614c14d8415]
btrfs check(+0x693dd)[0x5614c148d3dd]
btrfs check(+0x14dc7)[0x5614c1438dc7]
btrfs check(main+0x126)[0x5614c1439713] /usr/lib/libc.so.6(__libc_start_main+0xf3)[0x7fe3f1ecf153] btrfs check(_start+0x2e)[0x5614c1438cce]
[1] 6196 abort (core dumped)
======================================================================

It's excluding super stripes from one block group, the bytenr equals block group's start + len, so the @num_bytes is 0. Then add_exclude_extent() calculates the @end is less than the @start which trigers the abort.

Anyway, the logical bytenr should not be excluded if the block group's start + len equals it, because it's not belong to the block group.

---
 extent-tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
extent-tree.c +1 -2
index f690ae999f37..848fb72f90a4 100644
@@ -3630,7 +3630,7 @@ int exclude_super_stripes(struct btrfs_fs_info *fs_info,
 		while (nr--) {
 			u64 start, len;
 
-			if (logical[nr] > cache->key.objectid +
+			if (logical[nr] >= cache->key.objectid +
 			    cache->key.offset)
 				continue;
 
--

2.23.0