Zhihao Cheng
dacfd5e4d1
blktrace: Fix uaf in blk_trace access after removing by sysfs
...
[ Upstream commit 5afedf670caf30a2b5a52da96eb7eac7dee6a9c9 ]
There is an use-after-free problem triggered by following process:
P1(sda) P2(sdb)
echo 0 > /sys/block/sdb/trace/enable
blk_trace_remove_queue
synchronize_rcu
blk_trace_free
relay_close
rcu_read_lock
__blk_add_trace
trace_note_tsk
(Iterate running_trace_list)
relay_close_buf
relay_destroy_buf
kfree(buf)
trace_note(sdb's bt)
relay_reserve
buf->offset <- nullptr deference (use-after-free) !!!
rcu_read_unlock
[ 502.714379] BUG: kernel NULL pointer dereference, address:
0000000000000010
[ 502.715260] #PF: supervisor read access in kernel mode
[ 502.715903] #PF: error_code(0x0000) - not-present page
[ 502.716546] PGD 103984067 P4D 103984067 PUD 17592b067 PMD 0
[ 502.717252] Oops: 0000 [#1 ] SMP
[ 502.720308] RIP: 0010:trace_note.isra.0+0x86/0x360
[ 502.732872] Call Trace:
[ 502.733193] __blk_add_trace.cold+0x137/0x1a3
[ 502.733734] blk_add_trace_rq+0x7b/0xd0
[ 502.734207] blk_add_trace_rq_issue+0x54/0xa0
[ 502.734755] blk_mq_start_request+0xde/0x1b0
[ 502.735287] scsi_queue_rq+0x528/0x1140
...
[ 502.742704] sg_new_write.isra.0+0x16e/0x3e0
[ 502.747501] sg_ioctl+0x466/0x1100
Reproduce method:
ioctl(/dev/sda, BLKTRACESETUP, blk_user_trace_setup[buf_size=127])
ioctl(/dev/sda, BLKTRACESTART)
ioctl(/dev/sdb, BLKTRACESETUP, blk_user_trace_setup[buf_size=127])
ioctl(/dev/sdb, BLKTRACESTART)
echo 0 > /sys/block/sdb/trace/enable &
// Add delay(mdelay/msleep) before kernel enters blk_trace_free()
ioctl$SG_IO(/dev/sda, SG_IO, ...)
// Enters trace_note_tsk() after blk_trace_free() returned
// Use mdelay in rcu region rather than msleep(which may schedule out)
Remove blk_trace from running_list before calling blk_trace_free() by
sysfs if blk_trace is at Blktrace_running state.
Fixes: c71a896154119f ("blktrace: add ftrace plugin")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Link: https://lore.kernel.org/r/20210923134921.109194-1-chengzhihao1@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-10-06 10:23:40 +02:00
..
2021-10-06 10:23:40 +02:00
2018-12-17 09:38:33 +01:00
2021-06-16 11:36:36 +02:00
2020-05-20 08:15:37 +02:00
2016-10-12 10:23:41 -07:00
2016-04-02 01:09:12 +02:00
2021-07-28 09:14:28 +02:00
2021-06-30 08:49:17 -04:00
2020-10-01 20:40:05 +02:00
2016-05-17 16:26:30 -07:00
2018-05-16 10:08:43 +02:00
2021-07-20 16:21:11 +02:00
2020-06-30 15:38:45 -04:00
2021-02-23 13:59:15 +01:00
2018-07-11 16:26:43 +02:00
2016-06-20 09:54:19 -04:00
2020-08-26 10:29:03 +02:00
2016-03-18 16:39:11 -04:00
2019-07-10 09:55:28 +02:00
2018-08-03 07:55:12 +02:00
2016-06-20 09:54:22 -04:00
2016-03-08 11:23:57 -05:00
2016-09-02 12:47:55 -04:00
2016-06-20 09:46:12 -04:00
2018-03-28 18:39:23 +02:00
2018-03-28 18:39:23 +02:00
2020-01-14 20:04:26 +01:00
2020-11-10 10:24:02 +01:00
2020-01-14 20:04:26 +01:00
2020-02-28 15:42:21 +01:00
2016-09-29 10:25:23 +02:00
2019-02-20 10:18:32 +01:00
2021-06-30 08:49:18 -04:00
2020-12-11 13:38:01 +01:00
2020-01-12 11:24:14 +01:00
2016-04-19 12:16:06 -04:00