summaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorMing Lei <ming.lei@canonical.com>2016-03-30 08:46:31 +0800
committerJens Axboe <axboe@fb.com>2016-03-29 19:18:14 -0600
commitb30a337ca27c4f40439e4bfb290cba5f88d73bb7 (patch)
tree07da263067ec36686177990a48000beb0ceb2eae /block
parent1993b176a8224e371e0732ffada7ab9eb3b0912b (diff)
downloadlinux-stable-b30a337ca27c4f40439e4bfb290cba5f88d73bb7.tar.gz
linux-stable-b30a337ca27c4f40439e4bfb290cba5f88d73bb7.tar.bz2
linux-stable-b30a337ca27c4f40439e4bfb290cba5f88d73bb7.zip
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: Naveen Kaje <nkaje@codeaurora.org> Tested-by: Naveen Kaje <nkaje@codeaurora.org> Fixes: 6c71013ecb7e2(block: partition: convert percpu ref) Cc: <stable@vger.kernel.org> # v4.3+ Signed-off-by: Ming Lei <ming.lei@canonical.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block')
-rw-r--r--block/partition-generic.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/block/partition-generic.c b/block/partition-generic.c
index 5d8701941054..84c53f04777a 100644
--- a/block/partition-generic.c
+++ b/block/partition-generic.c
@@ -361,15 +361,20 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
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 */
rcu_assign_pointer(ptbl->part[partno], p);
/* suppress uevent if the disk suppresses it */
if (!dev_get_uevent_suppress(ddev))
kobject_uevent(&pdev->kobj, KOBJ_ADD);
-
- if (!hd_ref_init(p))
- return p;
+ return p;
out_free_info:
free_part_info(p);
@@ -378,6 +383,8 @@ out_free_stats:
out_free:
kfree(p);
return ERR_PTR(err);
+out_remove_file:
+ device_remove_file(pdev, &dev_attr_whole_disk);
out_del:
kobject_put(p->holder_dir);
device_del(pdev);