]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ubi: block: fix null-pointer-dereference in ubiblock_create()
authorLi Nan <linan122@huawei.com>
Wed, 22 May 2024 17:10:35 +0000 (01:10 +0800)
committerRichard Weinberger <richard@nod.at>
Fri, 12 Jul 2024 19:56:23 +0000 (21:56 +0200)
Similar to commit adbf4c4954e3 ("ubi: block: fix memleak in
ubiblock_create()"), 'dev->gd' is not assigned but dereferenced if
blk_mq_alloc_tag_set() fails, and leading to a null-pointer-dereference.
Fix it by using pr_err() and variable 'dev' to print error log.

Additionally, the log in the error handle path of idr_alloc() has
been improved by using pr_err(), too. Before initializing device
name, using dev_err() will print error log with 'null' instead of
the actual device name, like this:
  block (null): ...
        ~~~~~~
It is unclear. Using pr_err() can print more details of the device.
The improved log is:
  ubiblock0_0: ...

Fixes: 77567b25ab9f ("ubi: use blk_mq_alloc_disk and blk_cleanup_disk")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Li Nan <linan122@huawei.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Reviewed-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: Richard Weinberger <richard@nod.at>
drivers/mtd/ubi/block.c

index f82e3423acb9fb92c3d46bc92a1a1f6d31e66e83..bf7308e8ec2fee4b1ee5febfec0096143a5b7463 100644 (file)
@@ -390,7 +390,8 @@ 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");
+               pr_err("ubiblock%d_%d: blk_mq_alloc_tag_set failed\n",
+                       dev->ubi_num, dev->vol_id);
                goto out_free_dev;
        }
 
@@ -407,8 +408,8 @@ int ubiblock_create(struct ubi_volume_info *vi)
        gd->minors = 1;
        gd->first_minor = idr_alloc(&ubiblock_minor_idr, dev, 0, 0, GFP_KERNEL);
        if (gd->first_minor < 0) {
-               dev_err(disk_to_dev(gd),
-                       "block: dynamic minor allocation failed");
+               pr_err("ubiblock%d_%d: block: dynamic minor allocation failed\n",
+                       dev->ubi_num, dev->vol_id);
                ret = -ENODEV;
                goto out_cleanup_disk;
        }