linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ubi: block: KASAN null-ptr-deref in ubiblock_create()
@ 2022-10-21  7:57 Li Zetao
  2022-10-21 13:06 ` Zhihao Cheng
  0 siblings, 1 reply; 2+ messages in thread
From: Li Zetao @ 2022-10-21  7:57 UTC (permalink / raw)
  To: richard, miquel.raynal, vigneshr, axboe, chaitanya.kulkarni
  Cc: lizetao1, hch, linux-mtd, linux-kernel

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@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");
 		goto out_free_dev;
 	}
 
-- 
2.31.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ubi: block: KASAN null-ptr-deref in ubiblock_create()
  2022-10-21  7:57 [PATCH] ubi: block: KASAN null-ptr-deref in ubiblock_create() Li Zetao
@ 2022-10-21 13:06 ` Zhihao Cheng
  0 siblings, 0 replies; 2+ messages in thread
From: Zhihao Cheng @ 2022-10-21 13:06 UTC (permalink / raw)
  To: linux-mtd

在 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@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;
>   	}
>   



______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-21 13:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-21  7:57 [PATCH] ubi: block: KASAN null-ptr-deref in ubiblock_create() Li Zetao
2022-10-21 13:06 ` Zhihao Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).