Qu Wenruo
62fdaa52a3
btrfs: Detect unbalanced tree with empty leaf before crashing btree operations
[BUG]
With crafted image, btrfs will panic at btree operations:
kernel BUG at fs/btrfs/ctree.c:3894!
invalid opcode: 0000 [#1] SMP PTI
CPU: 0 PID: 1138 Comm: btrfs-transacti Not tainted 5.0.0-rc8+ #9
RIP: 0010:__push_leaf_left+0x6b6/0x6e0
RSP: 0018:ffffc0bd4128b990 EFLAGS: 00010246
RAX: 0000000000000000 RBX: ffffa0a4ab8f0e38 RCX: 0000000000000000
RDX: ffffa0a280000000 RSI: 0000000000000000 RDI: ffffa0a4b3814000
RBP: ffffc0bd4128ba38 R08: 0000000000001000 R09: ffffc0bd4128b948
R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000240
R13: ffffa0a4b556fb60 R14: ffffa0a4ab8f0af0 R15: ffffa0a4ab8f0af0
FS: 0000000000000000(0000) GS:ffffa0a4b7a00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f2461c80020 CR3: 000000022b32a006 CR4: 00000000000206f0
Call Trace:
? _cond_resched+0x1a/0x50
push_leaf_left+0x179/0x190
btrfs_del_items+0x316/0x470
btrfs_del_csums+0x215/0x3a0
__btrfs_free_extent.isra.72+0x5a7/0xbe0
__btrfs_run_delayed_refs+0x539/0x1120
btrfs_run_delayed_refs+0xdb/0x1b0
btrfs_commit_transaction+0x52/0x950
? start_transaction+0x94/0x450
transaction_kthread+0x163/0x190
kthread+0x105/0x140
? btrfs_cleanup_transaction+0x560/0x560
? kthread_destroy_worker+0x50/0x50
ret_from_fork+0x35/0x40
Modules linked in:
---[ end trace c2425e6e89b5558f ]---
[CAUSE]
The offending csum tree looks like this:
checksum tree key (CSUM_TREE ROOT_ITEM 0)
node 29741056 level 1 items 14 free 107 generation 19 owner CSUM_TREE
...
key (EXTENT_CSUM EXTENT_CSUM 85975040) block 29630464 gen 17
key (EXTENT_CSUM EXTENT_CSUM 89911296) block 29642752 gen 17 <<<
key (EXTENT_CSUM EXTENT_CSUM 92274688) block 29646848 gen 17
...
leaf 29630464 items 6 free space 1 generation 17 owner CSUM_TREE
item 0 key (EXTENT_CSUM EXTENT_CSUM 85975040) itemoff 3987 itemsize 8
range start 85975040 end 85983232 length 8192
...
leaf 29642752 items 0 free space 3995 generation 17 owner 0
^ empty leaf invalid owner ^
leaf 29646848 items 1 free space 602 generation 17 owner CSUM_TREE
item 0 key (EXTENT_CSUM EXTENT_CSUM 92274688) itemoff 627 itemsize 3368
range start 92274688 end 95723520 length 3448832
So we have a corrupted csum tree where one tree leaf is completely
empty, causing unbalanced btree, thus leading to unexpected btree
balance error.
[FIX]
For this particular case, we handle it in two directions to catch it:
- Check if the tree block is empty through btrfs_verify_level_key()
So that invalid tree blocks won't be read out through
btrfs_search_slot() and its variants.
- Check 0 tree owner in tree checker
NO tree is using 0 as its tree owner, detect it and reject at tree
block read time.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=202821
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-09-09 14:59:14 +02:00
..
2019-07-12 11:05:43 -07:00
2019-07-19 11:33:22 -07:00
2019-05-21 10:50:46 +02:00
2019-08-22 13:33:27 +01:00
2019-05-24 17:37:52 +02:00
2019-05-21 10:50:46 +02:00
2019-05-21 10:50:46 +02:00
2019-09-09 14:59:14 +02:00
2019-05-24 17:27:11 +02:00
2019-08-22 10:47:41 +02:00
2019-08-27 17:29:56 -05:00
2019-07-16 19:23:23 -07:00
2019-09-04 22:33:51 +02:00
2019-05-21 10:50:46 +02:00
2019-07-10 18:43:43 -07:00
2019-07-12 12:24:03 -07:00
2019-06-20 14:46:34 +02:00
2019-07-12 17:37:53 -07:00
2019-07-14 19:29:04 -07:00
2019-07-19 10:42:02 -07:00
2019-05-21 10:50:46 +02:00
2019-05-21 10:50:46 +02:00
2019-07-12 16:54:37 -07:00
2019-07-18 10:52:08 -07:00
2019-07-30 13:15:39 -07:00
2019-06-05 17:36:37 +02:00
2019-05-21 10:50:46 +02:00
2019-07-10 18:43:43 -07:00
2019-07-19 10:42:02 -07:00
2019-08-09 16:56:12 +01:00
2019-05-21 10:50:46 +02:00
2019-07-16 19:23:23 -07:00
2019-05-12 17:52:13 -04:00
2019-05-21 10:50:46 +02:00
2019-07-19 10:42:02 -07:00
2019-07-25 11:05:11 +02:00
2019-05-30 11:25:17 -07:00
2019-06-20 17:32:21 -04:00
2019-07-12 11:05:43 -07:00
2019-07-01 08:25:34 -07:00
2019-06-05 17:37:16 +02:00
2019-07-03 17:52:09 -04:00
2019-05-21 10:50:46 +02:00
2019-09-02 13:10:19 -04:00
2019-05-21 10:50:46 +02:00
2019-08-16 13:36:55 -04:00
2019-07-01 08:25:34 -07:00
2019-05-21 10:50:46 +02:00
2019-07-18 17:08:07 -07:00
2019-05-24 17:37:53 +02:00
2019-08-03 07:02:00 -07:00
2019-05-30 11:29:53 -07:00
2019-07-19 10:42:02 -07:00
2019-07-16 15:15:29 -07:00
2019-06-21 09:58:42 -07:00
2019-07-19 10:42:02 -07:00
2019-07-08 21:04:42 -07:00
2019-05-21 10:50:46 +02:00
2019-05-21 10:50:46 +02:00
2019-07-10 20:27:07 -07:00
2019-07-19 10:42:02 -07:00
2019-07-16 19:23:24 -07:00
2019-05-30 11:26:32 -07:00
2019-06-19 17:09:53 +02:00
2019-07-19 10:42:02 -07:00
2019-05-21 10:50:46 +02:00
2019-07-10 20:09:17 -07:00
2019-08-22 17:25:33 +02:00
2019-07-10 20:27:07 -07:00
2019-07-16 19:23:23 -07:00
2019-07-10 21:06:01 -07:00
2019-08-22 20:55:54 -07:00
2019-07-19 10:42:02 -07:00
2019-07-19 10:42:02 -07:00
2019-05-21 10:50:45 +02:00
2019-05-30 11:26:32 -07:00
2019-07-16 19:23:22 -07:00
2019-05-21 10:50:45 +02:00
2019-07-16 19:23:22 -07:00
2019-07-19 10:42:02 -07:00
2019-05-21 10:50:45 +02:00
2019-08-15 11:09:16 -06:00
2019-07-15 21:20:52 -07:00
2019-05-24 20:50:36 +02:00
2019-05-30 11:29:21 -07:00
2019-07-30 14:42:13 -07:00
2019-06-19 17:09:55 +02:00
2019-08-03 07:02:01 -07:00
2019-05-21 08:23:41 +01:00
2019-08-05 14:59:05 -07:00
2019-07-20 09:15:51 -07:00
2019-05-21 10:50:45 +02:00
2019-06-29 09:47:31 -06:00
2019-02-01 15:46:24 -08:00
2019-05-21 10:50:45 +02:00
2019-07-18 17:08:07 -07:00
2019-07-25 15:37:04 +02:00
2019-04-08 18:21:02 -05:00
2019-05-21 10:50:45 +02:00
2019-03-08 14:48:40 -08:00
2019-02-28 03:29:26 -05:00
2019-05-25 18:00:01 -04:00
2019-07-19 10:42:02 -07:00
2019-07-16 22:52:37 -04:00
2019-05-21 10:50:45 +02:00
2019-01-21 17:48:13 +01:00
2019-07-10 09:00:57 -06:00
2019-07-19 10:42:02 -07:00
2019-07-12 16:54:37 -07:00
2019-07-20 09:15:51 -07:00
2019-08-22 15:32:28 -06:00
2019-01-03 18:57:57 -08:00
2019-07-05 11:22:11 -04:00
2019-06-24 09:16:47 +10:00
2019-07-19 10:42:02 -07:00
2019-07-10 21:22:43 -07:00
2019-07-17 07:20:43 -07:00
2019-05-21 10:50:45 +02:00
2019-07-16 22:52:37 -04:00
2019-07-10 09:00:57 -06:00
2019-06-20 14:44:55 +02:00
2019-07-26 07:59:06 -04:00
2019-05-30 11:26:32 -07:00
2019-05-25 18:00:06 -04:00
2019-07-24 10:12:09 -07:00
2019-05-25 18:00:07 -04:00
2019-06-17 17:36:09 -04:00
2019-05-30 11:29:53 -07:00
2019-05-21 10:50:45 +02:00
2019-08-16 18:43:24 -07:00
2019-01-03 18:57:57 -08:00
2019-07-16 19:23:25 -07:00
2019-08-13 16:06:52 -07:00
2019-04-08 18:21:02 -05:00
2019-05-31 15:30:03 -06:00
2019-05-21 10:50:45 +02:00
2019-02-01 01:55:45 -05:00
2019-02-07 16:38:35 +01:00
2019-07-31 12:22:32 -04:00
2019-05-14 09:47:50 -07:00
2019-02-07 00:13:27 +01:00
2019-08-24 19:48:42 -07:00
2019-02-07 00:13:27 +01:00
2019-05-21 10:50:45 +02:00