Skip to content

Commit

Permalink
block: partition: initialize percpuref before sending out KOBJ_ADD
Browse files Browse the repository at this point in the history
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 <[email protected]>
Tested-by: Naveen Kaje <[email protected]>
Fixes: 6c71013(block: partition: convert percpu ref)
Cc: <[email protected]> # v4.3+
Signed-off-by: Ming Lei <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Ming Lei authored and axboe committed Mar 30, 2016
1 parent 1993b17 commit b30a337
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions block/partition-generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -378,6 +383,8 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
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);
Expand Down

0 comments on commit b30a337

Please sign in to comment.