Yu Kuai
78acc7dbd8
blktrace: fix use after free for struct blk_trace
commit 30939293262eb433c960c4532a0d59c4073b2b84 upstream.
When tracing the whole disk, 'dropped' and 'msg' will be created
under 'q->debugfs_dir' and 'bt->dir' is NULL, thus blk_trace_free()
won't remove those files. What's worse, the following UAF can be
triggered because of accessing stale 'dropped' and 'msg':
==================================================================
BUG: KASAN: use-after-free in blk_dropped_read+0x89/0x100
Read of size 4 at addr ffff88816912f3d8 by task blktrace/1188
CPU: 27 PID: 1188 Comm: blktrace Not tainted 5.17.0-rc4-next-20220217+ #469
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20190727_073836-4
Call Trace:
<TASK>
dump_stack_lvl+0x34/0x44
print_address_description.constprop.0.cold+0xab/0x381
? blk_dropped_read+0x89/0x100
? blk_dropped_read+0x89/0x100
kasan_report.cold+0x83/0xdf
? blk_dropped_read+0x89/0x100
kasan_check_range+0x140/0x1b0
blk_dropped_read+0x89/0x100
? blk_create_buf_file_callback+0x20/0x20
? kmem_cache_free+0xa1/0x500
? do_sys_openat2+0x258/0x460
full_proxy_read+0x8f/0xc0
vfs_read+0xc6/0x260
ksys_read+0xb9/0x150
? vfs_write+0x3d0/0x3d0
? fpregs_assert_state_consistent+0x55/0x60
? exit_to_user_mode_prepare+0x39/0x1e0
do_syscall_64+0x35/0x80
entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x7fbc080d92fd
Code: ce 20 00 00 75 10 b8 00 00 00 00 0f 05 48 3d 01 f0 ff ff 73 31 c3 48 83 1
RSP: 002b:00007fbb95ff9cb0 EFLAGS: 00000293 ORIG_RAX: 0000000000000000
RAX: ffffffffffffffda RBX: 00007fbb95ff9dc0 RCX: 00007fbc080d92fd
RDX: 0000000000000100 RSI: 00007fbb95ff9cc0 RDI: 0000000000000045
RBP: 0000000000000045 R08: 0000000000406299 R09: 00000000fffffffd
R10: 000000000153afa0 R11: 0000000000000293 R12: 00007fbb780008c0
R13: 00007fbb78000938 R14: 0000000000608b30 R15: 00007fbb780029c8
</TASK>
Allocated by task 1050:
kasan_save_stack+0x1e/0x40
__kasan_kmalloc+0x81/0xa0
do_blk_trace_setup+0xcb/0x410
__blk_trace_setup+0xac/0x130
blk_trace_ioctl+0xe9/0x1c0
blkdev_ioctl+0xf1/0x390
__x64_sys_ioctl+0xa5/0xe0
do_syscall_64+0x35/0x80
entry_SYSCALL_64_after_hwframe+0x44/0xae
Freed by task 1050:
kasan_save_stack+0x1e/0x40
kasan_set_track+0x21/0x30
kasan_set_free_info+0x20/0x30
__kasan_slab_free+0x103/0x180
kfree+0x9a/0x4c0
__blk_trace_remove+0x53/0x70
blk_trace_ioctl+0x199/0x1c0
blkdev_common_ioctl+0x5e9/0xb30
blkdev_ioctl+0x1a5/0x390
__x64_sys_ioctl+0xa5/0xe0
do_syscall_64+0x35/0x80
entry_SYSCALL_64_after_hwframe+0x44/0xae
The buggy address belongs to the object at ffff88816912f380
which belongs to the cache kmalloc-96 of size 96
The buggy address is located 88 bytes inside of
96-byte region [ffff88816912f380, ffff88816912f3e0)
The buggy address belongs to the page:
page:000000009a1b4e7c refcount:1 mapcount:0 mapping:0000000000000000 index:0x0f
flags: 0x17ffffc0000200(slab|node=0|zone=2|lastcpupid=0x1fffff)
raw: 0017ffffc0000200 ffffea00044f1100 dead000000000002 ffff88810004c780
raw: 0000000000000000 0000000000200020 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff88816912f280: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
ffff88816912f300: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
>ffff88816912f380: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
^
ffff88816912f400: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
ffff88816912f480: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
==================================================================
Fixes: c0ea57608b ("blktrace: remove debugfs file dentries from struct blk_trace")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20220228034354.4047385-1-yukuai3@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-03-08 19:12:43 +01:00
..
2022-03-08 19:12:40 +01:00
2022-03-02 11:47:47 +01:00
2021-05-07 00:26:34 -07:00
2021-11-18 19:17:06 +01:00
2022-01-27 11:03:00 +01:00
2021-11-25 09:49:07 +01:00
2022-02-16 12:56:41 +01:00
2021-06-22 11:07:18 -07:00
2021-11-18 19:17:14 +01:00
2021-09-02 13:00:15 -07:00
2021-08-19 12:00:24 +02:00
2022-02-23 12:03:22 +01:00
2022-02-16 12:56:19 +01:00
2021-11-25 09:48:45 +01:00
2022-01-29 10:58:25 +01:00
2022-03-08 19:12:32 +01:00
2022-01-27 11:04:08 +01:00
2022-03-08 19:12:43 +01:00
2021-05-02 00:43:35 +09:00
2021-09-08 11:50:26 -07:00
2022-02-23 12:03:07 +01:00
2021-08-24 18:52:36 -04:00
2022-02-08 18:34:03 +01:00
2021-07-19 22:38:24 -04:00
2021-03-22 15:23:32 -04:00
2021-10-18 18:27:47 -04:00
2021-08-11 13:11:12 -07:00
2021-09-08 15:32:35 -07:00
2021-08-16 18:55:32 +02:00
2021-12-01 09:04:54 +01:00
2021-12-29 12:28:49 +01:00
2022-02-23 12:03:20 +01:00
2021-05-12 11:43:25 +02:00
2021-08-23 13:10:37 -06:00
2022-02-23 12:03:21 +01:00
2021-06-18 11:43:08 +02:00
2021-09-03 23:00:22 +02:00
2021-05-27 04:01:50 +09:00
2021-07-02 12:08:10 -07:00
2021-06-10 10:00:08 +02:00
2021-07-05 10:46:20 +02:00
2021-07-08 11:48:22 -07:00
2021-08-17 17:50:51 +02:00
2021-06-28 22:43:05 +02:00
2021-08-30 16:36:10 +02:00
2021-05-07 00:26:32 -07:00
2021-09-08 15:32:34 -07:00
2021-05-07 00:26:33 -07:00
2021-12-08 09:04:41 +01:00
2021-06-29 17:29:11 -07:00
2021-05-02 00:43:35 +09:00
2022-02-23 12:03:07 +01:00
2021-08-16 18:55:32 +02:00
2021-09-03 09:58:12 -07:00
2021-08-27 16:30:18 +08:00
2021-08-30 16:36:10 +02:00
2021-08-16 14:42:22 +02:00
2021-09-03 09:58:12 -07:00
2021-08-10 12:53:07 +02:00
2021-09-08 11:50:26 -07:00
2021-06-18 11:43:09 +02:00
2021-06-21 13:08:36 +01:00
2021-05-14 19:41:32 -07:00
2021-09-22 10:24:01 -04:00
2021-07-27 11:39:30 -07:00
2021-11-18 19:16:29 +01:00
2022-02-16 12:56:38 +01:00
2022-03-08 19:12:34 +01:00
2021-08-11 14:47:16 +02:00
2021-08-10 14:57:42 +02:00
2021-08-10 22:50:07 +02:00
2022-02-23 12:03:07 +01:00
2021-07-05 10:46:33 +02:00
2021-03-23 16:01:58 +01:00
2021-09-08 15:32:35 -07:00
2022-02-23 12:03:20 +01:00
2021-06-23 16:41:24 -06:00
2021-09-03 10:08:28 -07:00
2021-04-30 11:20:42 -07:00
2021-08-10 10:48:07 -07:00
2021-08-16 11:39:51 -04:00
2022-01-27 11:05:35 +01:00
2022-02-23 12:03:20 +01:00
2021-05-07 00:26:34 -07:00
2021-05-09 13:07:03 -07:00
2022-03-08 19:12:42 +01:00
2021-09-08 11:50:27 -07:00
2021-07-03 11:41:14 -07:00
2021-06-29 10:53:46 -07:00
2021-08-17 07:49:10 -10:00
2022-01-16 09:12:41 +01:00