Commit d0ed1153 authored by Li Nan's avatar Li Nan Committed by Zhihao Cheng
Browse files

ubi: block: fix null-pointer-dereference in ubiblock_create()

mainline inclusion
from mainline-v6.11-rc1
commit 4f9d406c8c90dc17470cf63342c16f66ec2d978e
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAWXV9
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4f9d406c8c90dc17470cf63342c16f66ec2d978e



--------------------------------

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: 77567b25 ("ubi: use blk_mq_alloc_disk and blk_cleanup_disk")
Reported-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: default avatarLi Nan <linan122@huawei.com>
Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
Reviewed-by: default avatarDaniel Golle <daniel@makrotopia.org>
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
parent 363822c8
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -404,7 +404,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;
	}

@@ -421,8 +422,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;
	}