bdi: fix use-after-free for the bdi device
hulk inclusion
category: bugfix
bugzilla: 30109
CVE: NA
---------------------------
We reported kernel crash:
[201962.639350] Call trace:
[201962.644403] string+0x28/0xa0
[201962.650501] vsnprintf+0x5f0/0x748
[201962.657472] seq_vprintf+0x70/0x98
[201962.664442] seq_printf+0x7c/0xa0
[201962.671238] __blkg_prfill_rwstat+0x84/0x128
[201962.679949] blkg_prfill_rwstat_field+0x94/0xc0
[201962.689182] blkcg_print_blkgs+0xcc/0x140
[201962.697370] blkg_print_stat_bytes+0x4c/0x60
[201962.706083] cgroup_seqfile_show+0x58/0xc0
[201962.714446] kernfs_seq_show+0x44/0x50
[201962.722112] seq_read+0xd4/0x4a8
[201962.728732] kernfs_fop_read+0x16c/0x218
[201962.736748] __vfs_read+0x60/0x188
[201962.743717] vfs_read+0x94/0x150
[201962.750338] ksys_read+0x6c/0xd8
[201962.756958] __arm64_sys_read+0x24/0x30
[201962.764800] el0_svc_common+0x78/0x130
[201962.772466] el0_svc_handler+0x38/0x78
[201962.780131] el0_svc+0x8/0xc
__blkg_prfill_rwstat() tried to get the device name by
'bdi->dev', while the 'dev' have been freed by bdi_release().
The race as following:
blkg_print_stat_bytes __scsi_remove_device
del_gendisk
bdi_unregister
put_device(bdi->dev)
kfree(bdi->dev)
__blkg_prfill_rwstat
blkg_dev_name
//use the freed bdi->dev
dev_name(blkg->q->backing_dev_info->dev)
bdi->dev = NULL
Since blkg_dev_name() have been coverd by rcu_read_lock/unlock(),
we wait all rcu reader before free 'bdi->dev' to avoid use-after-free.
Link: https://lore.kernel.org/linux-block/20200211140038.146629-1-yuyufen@huawei.com/Signed-off-by: NYufen Yu <yuyufen@huawei.com>
Reviewed-by: NJason Yan <yanaijie@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Showing
想要评论请 注册 或 登录