Skip to content

Commit b30a337

Browse files
Ming Leiaxboe
authored andcommitted
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: 6c71013(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>
1 parent 1993b17 commit b30a337

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

block/partition-generic.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,20 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
361361
goto out_del;
362362
}
363363

364+
err = hd_ref_init(p);
365+
if (err) {
366+
if (flags & ADDPART_FLAG_WHOLEDISK)
367+
goto out_remove_file;
368+
goto out_del;
369+
}
370+
364371
/* everything is up and running, commence */
365372
rcu_assign_pointer(ptbl->part[partno], p);
366373

367374
/* suppress uevent if the disk suppresses it */
368375
if (!dev_get_uevent_suppress(ddev))
369376
kobject_uevent(&pdev->kobj, KOBJ_ADD);
370-
371-
if (!hd_ref_init(p))
372-
return p;
377+
return p;
373378

374379
out_free_info:
375380
free_part_info(p);
@@ -378,6 +383,8 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
378383
out_free:
379384
kfree(p);
380385
return ERR_PTR(err);
386+
out_remove_file:
387+
device_remove_file(pdev, &dev_attr_whole_disk);
381388
out_del:
382389
kobject_put(p->holder_dir);
383390
device_del(pdev);

0 commit comments

Comments
 (0)