Commit b30a337c authored by Ming Lei's avatar Ming Lei Committed by Jens Axboe

block: partition: initialize percpuref before sending out KOBJ_ADD

The initialization of partition's percpu_ref should have been done before
sending out KOBJ_ADD uevent, which may cause userspace to read partition
table. So the uninitialized percpu_ref may be accessed in data path.

This patch fixes this issue reported by Naveen.
Reported-by: default avatarNaveen Kaje <nkaje@codeaurora.org>
Tested-by: default avatarNaveen Kaje <nkaje@codeaurora.org>
Fixes: 6c71013e(block: partition: convert percpu ref)
Cc: <stable@vger.kernel.org> # v4.3+
Signed-off-by: default avatarMing Lei <ming.lei@canonical.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 1993b176
...@@ -361,15 +361,20 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno, ...@@ -361,15 +361,20 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
goto out_del; goto out_del;
} }
err = hd_ref_init(p);
if (err) {
if (flags & ADDPART_FLAG_WHOLEDISK)
goto out_remove_file;
goto out_del;
}
/* everything is up and running, commence */ /* everything is up and running, commence */
rcu_assign_pointer(ptbl->part[partno], p); rcu_assign_pointer(ptbl->part[partno], p);
/* suppress uevent if the disk suppresses it */ /* suppress uevent if the disk suppresses it */
if (!dev_get_uevent_suppress(ddev)) if (!dev_get_uevent_suppress(ddev))
kobject_uevent(&pdev->kobj, KOBJ_ADD); kobject_uevent(&pdev->kobj, KOBJ_ADD);
return p;
if (!hd_ref_init(p))
return p;
out_free_info: out_free_info:
free_part_info(p); free_part_info(p);
...@@ -378,6 +383,8 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno, ...@@ -378,6 +383,8 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
out_free: out_free:
kfree(p); kfree(p);
return ERR_PTR(err); return ERR_PTR(err);
out_remove_file:
device_remove_file(pdev, &dev_attr_whole_disk);
out_del: out_del:
kobject_put(p->holder_dir); kobject_put(p->holder_dir);
device_del(pdev); device_del(pdev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment