[PATCH] ubi: block: KASAN null-ptr-deref in ubiblock_create()

Zhihao Cheng chengzhihao1 at huawei.com
Fri Oct 21 06:06:35 PDT 2022


在 2022/10/21 15:57, Li Zetao 写道:
Hi,
> There is a null-ptr-deref when testing the ubiblock tools:
>
>    KASAN: null-ptr-deref in range [0x0000000000000040-0x0000000000000047]
>    CPU: 1 PID: 2299 Comm: ubiblock Not tainted
>    6.1.0-rc1-00002-gebb24af8c872-dirty #12
>    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
>    BIOS 1.14.0-1.fc33 04/01/2014
>    RIP: 0010:ubiblock_create.cold+0x175/0x1b5 [ubi]
>    ...
>    Call Trace:
>     vol_cdev_ioctl+0x6ce/0x870 [ubi]
>     __x64_sys_ioctl+0x11d/0x170
>     do_syscall_64+0x35/0x80
>     entry_SYSCALL_64_after_hwframe+0x46/0xb0
>    RIP: 0033:0x7fd9141230ab
>
> when blk_mq_alloc_tag_set() returns an error, the dev->gd is
> uninitialized, that causing null-ptr-deref fault.
>
> Fix it by replacing the disk_to_dev(dev->gd) with NULL, that
> will printk "(NULL device *): ..." message if blk_mq_alloc_tag_set()
> returns an error.
>
> Fixes: 77567b25ab9f ("ubi: use blk_mq_alloc_disk and blk_cleanup_disk")
> Signed-off-by: Li Zetao <lizetao1 at huawei.com>
> ---
>   drivers/mtd/ubi/block.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
> index 75eaecc8639f..9625dc2f45e2 100644
> --- a/drivers/mtd/ubi/block.c
> +++ b/drivers/mtd/ubi/block.c
> @@ -408,7 +408,7 @@ int ubiblock_create(struct ubi_volume_info *vi)
>   
>   	ret = blk_mq_alloc_tag_set(&dev->tag_set);
>   	if (ret) {
> -		dev_err(disk_to_dev(dev->gd), "blk_mq_alloc_tag_set failed");
> +		dev_err(NULL, "blk_mq_alloc_tag_set failed");

'dev_err(NULL, ...' looks wierd. Since dev is NULL, there is no useful 
information from the device, I prefer to replace 'dev_err' with 'pr_err'.


>   		goto out_free_dev;
>   	}
>   





More information about the linux-mtd mailing list