Su Yue
0c982944af
btrfs: tree-checker: check item_size for inode_item
...
while mounting the crafted image, out-of-bounds access happens:
[350.429619] UBSAN: array-index-out-of-bounds in fs/btrfs/struct-funcs.c:161:1
[350.429636] index 1048096 is out of range for type 'page *[16]'
[350.429650] CPU: 0 PID: 9 Comm: kworker/u8:1 Not tainted 5.16.0-rc4 #1
[350.429652] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014
[350.429653] Workqueue: btrfs-endio-meta btrfs_work_helper [btrfs]
[350.429772] Call Trace:
[350.429774] <TASK>
[350.429776] dump_stack_lvl+0x47/0x5c
[350.429780] ubsan_epilogue+0x5/0x50
[350.429786] __ubsan_handle_out_of_bounds+0x66/0x70
[350.429791] btrfs_get_16+0xfd/0x120 [btrfs]
[350.429832] check_leaf+0x754/0x1a40 [btrfs]
[350.429874] ? filemap_read+0x34a/0x390
[350.429878] ? load_balance+0x175/0xfc0
[350.429881] validate_extent_buffer+0x244/0x310 [btrfs]
[350.429911] btrfs_validate_metadata_buffer+0xf8/0x100 [btrfs]
[350.429935] end_bio_extent_readpage+0x3af/0x850 [btrfs]
[350.429969] ? newidle_balance+0x259/0x480
[350.429972] end_workqueue_fn+0x29/0x40 [btrfs]
[350.429995] btrfs_work_helper+0x71/0x330 [btrfs]
[350.430030] ? __schedule+0x2fb/0xa40
[350.430033] process_one_work+0x1f6/0x400
[350.430035] ? process_one_work+0x400/0x400
[350.430036] worker_thread+0x2d/0x3d0
[350.430037] ? process_one_work+0x400/0x400
[350.430038] kthread+0x165/0x190
[350.430041] ? set_kthread_struct+0x40/0x40
[350.430043] ret_from_fork+0x1f/0x30
[350.430047] </TASK>
[350.430077] BTRFS warning (device loop0): bad eb member start: ptr 0xffe20f4e start 20975616 member offset 4293005178 size 2
check_leaf() is checking the leaf:
corrupt leaf: root=4 block=29396992 slot=1, bad key order, prev (16140901064495857664 1 0) current (1 204 12582912)
leaf 29396992 items 6 free space 3565 generation 6 owner DEV_TREE
leaf 29396992 flags 0x1(WRITTEN) backref revision 1
fs uuid a62e00e8-e94e-4200-8217-12444de93c2e
chunk uuid cecbd0f7-9ca0-441e-ae9f-f782f9732bd8
item 0 key (16140901064495857664 INODE_ITEM 0) itemoff 3955 itemsize 40
generation 0 transid 0 size 0 nbytes 17592186044416
block group 0 mode 52667 links 33 uid 0 gid 2104132511 rdev 94223634821136
sequence 100305 flags 0x2409000(none)
atime 0.0 (1970-01-01 08:00:00)
ctime 2973280098083405823.4294967295 (-269783007-01-01 21:37:03)
mtime 18446744071572723616.4026825121 (1902-04-16 12:40:00)
otime 9249929404488876031.4294967295 (622322949-04-16 04:25:58)
item 1 key (1 DEV_EXTENT 12582912) itemoff 3907 itemsize 48
dev extent chunk_tree 3
chunk_objectid 256 chunk_offset 12582912 length 8388608
chunk_tree_uuid cecbd0f7-9ca0-441e-ae9f-f782f9732bd8
The corrupted leaf of device tree has an inode item. The leaf passed
checksum and others checks in validate_extent_buffer until check_leaf_item().
Because of the key type BTRFS_INODE_ITEM, check_inode_item() is called even we
are in the device tree. Since the
item offset + sizeof(struct btrfs_inode_item) > eb->len, out-of-bounds access
is triggered.
The item end vs leaf boundary check has been done before
check_leaf_item(), so fix it by checking item size in check_inode_item()
before access of the inode item in extent buffer.
Other check functions except check_dev_item() in check_leaf_item()
have their item size checks.
The commit for check_dev_item() is followed.
No regression observed during running fstests.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=215299
CC: stable@vger.kernel.org # 5.10+
CC: Wenqing Liu <wenqingliu0120@gmail.com>
Signed-off-by: Su Yue <l@damenly.su>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-01-31 16:05:54 +01:00
..
2021-11-10 21:16:56 +00:00
2021-06-29 10:53:48 -07:00
2021-10-18 14:43:22 -06:00
2021-12-16 09:10:13 -08:00
2021-10-20 21:09:02 -04:00
2021-08-19 09:02:55 +09:00
2021-06-29 10:53:48 -07:00
2022-01-31 16:05:54 +01:00
2021-11-01 10:17:11 -07:00
2021-12-01 17:08:27 +01:00
2021-12-17 19:16:49 -06:00
2021-11-09 10:02:51 -08:00
2021-08-25 07:58:49 +02:00
2021-10-18 14:43:22 -06:00
2021-10-25 19:11:50 -07:00
2021-09-21 09:09:06 +02:00
2021-09-01 11:29:14 -05:00
2021-06-29 10:53:48 -07:00
2021-04-12 15:04:29 +02:00
2021-11-23 14:58:16 +08:00
2021-11-01 07:49:21 +09:00
2021-09-22 13:05:23 +02:00
2021-11-10 17:05:37 -08:00
2021-11-13 15:32:30 -08:00
2021-11-01 10:25:27 -07:00
2021-10-04 22:13:12 +01:00
2021-11-25 14:05:18 +01:00
2021-12-02 12:41:10 +01:00
2021-11-09 10:11:53 -08:00
2021-11-09 10:11:53 -08:00
2021-08-26 22:28:02 +02:00
2021-10-18 12:28:53 -07:00
2021-11-09 10:02:48 -08:00
2021-11-24 10:15:47 -08:00
2021-10-19 12:51:02 +02:00
2021-08-30 23:36:50 -04:00
2021-08-18 22:08:24 +02:00
2021-11-03 09:23:25 -07:00
2021-10-18 09:43:37 +02:00
2021-12-17 19:19:45 -06:00
2021-11-10 16:45:54 -08:00
2021-06-29 10:53:48 -07:00
2021-12-07 15:47:09 +00:00
2021-11-27 10:33:55 -08:00
2021-10-04 22:02:17 +01:00
2021-12-18 17:11:06 -05:00
2021-11-09 10:11:53 -08:00
2021-10-27 12:53:45 +02:00
2021-11-27 14:34:41 -08:00
2021-11-02 12:25:03 -07:00
2021-11-10 16:15:54 -08:00
2021-06-29 10:53:48 -07:00
2021-11-09 10:34:06 -08:00
2021-11-09 10:51:12 -08:00
2021-11-20 10:35:55 -08:00
2021-11-21 09:44:19 -08:00
2021-09-21 08:36:48 -07:00
2021-11-06 16:40:48 -07:00
2021-11-09 10:11:53 -08:00
2021-11-06 16:40:48 -07:00
2021-12-07 22:38:03 -06:00
2021-11-08 16:55:21 -08:00
2021-10-05 16:35:05 +02:00
2021-11-09 10:02:52 -08:00
2021-12-08 08:06:40 -05:00
2021-09-20 19:32:33 -07:00
2021-11-09 12:53:58 +01:00
2021-08-19 09:02:55 +09:00
2021-05-02 00:43:35 +09:00
2021-09-27 11:26:21 -07:00
2021-09-22 10:56:34 -07:00
2021-12-07 10:17:29 -08:00
2021-12-17 16:56:35 +09:00
2021-12-09 10:52:55 -08:00
2021-09-19 22:35:37 -04:00
2021-11-17 09:26:09 +01:00
2021-08-18 22:08:24 +02:00
2021-09-05 10:15:05 -07:00
2021-10-08 12:06:02 -05:00
2021-11-09 10:11:53 -08:00
2021-06-29 10:53:50 -07:00
2021-10-18 14:43:22 -06:00
2021-10-08 12:06:02 -05:00
2021-11-06 13:30:32 -07:00
2021-08-31 11:13:35 -07:00
2021-04-15 22:36:45 -04:00
2021-10-25 10:36:24 -06:00
2021-09-03 09:58:10 -07:00
2021-09-06 07:20:56 -04:00
2021-09-09 13:25:49 -07:00
2021-11-10 16:15:54 -08:00
2021-09-03 10:08:28 -07:00
2021-04-07 13:56:43 -04:00
2021-12-13 10:55:30 -08:00
2021-08-23 01:25:40 -04:00
2021-09-03 09:58:12 -07:00
2021-09-07 16:07:47 -04:00
2021-11-01 17:29:10 -07:00
2021-11-17 10:36:35 -05:00
2021-11-09 10:11:53 -08:00
2021-12-22 20:34:32 -07:00
2021-12-13 09:04:01 -07:00
2021-10-19 05:49:54 -06:00
2021-08-31 11:06:32 -07:00
2021-09-12 10:10:21 -07:00
2021-07-25 22:33:03 -07:00
2021-10-18 20:22:03 -10:00
2021-11-03 15:43:08 +01:00
2021-10-19 14:11:39 -04:00
2021-09-12 10:10:21 -07:00
2021-11-01 09:06:53 -07:00
2021-12-30 15:12:13 -08:00
2021-11-06 14:08:17 -07:00
2021-09-07 11:03:45 -07:00
2021-11-06 13:30:32 -07:00
2021-10-26 12:20:50 -04:00
2021-04-17 11:39:49 -07:00
2021-08-23 06:15:36 -04:00
2021-09-07 11:26:23 -07:00
2021-11-09 10:02:52 -08:00
2021-12-09 10:49:56 -08:00
2021-08-17 11:47:43 +02:00
2021-11-06 13:30:34 -07:00
2021-10-22 08:36:55 -06:00
2021-08-10 17:57:22 +02:00
2021-10-18 20:22:02 -10:00
2021-03-23 11:20:26 +01:00