* [PATCH] block: partition: initialize percpuref before sending out KOBJ_ADD
@ 2016-03-30 0:46 Ming Lei
2016-03-30 17:43 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Ming Lei @ 2016-03-30 0:46 UTC (permalink / raw)
To: Jens Axboe, linux-kernel
Cc: linux-block, Christoph Hellwig, Naveen Kaje, Ming Lei, stable
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>
---
block/partition-generic.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/block/partition-generic.c b/block/partition-generic.c
index 5d87019..84c53f0 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);
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] block: partition: initialize percpuref before sending out KOBJ_ADD
2016-03-30 0:46 [PATCH] block: partition: initialize percpuref before sending out KOBJ_ADD Ming Lei
@ 2016-03-30 17:43 ` Christoph Hellwig
2016-03-31 2:22 ` Ming Lei
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2016-03-30 17:43 UTC (permalink / raw)
To: Ming Lei
Cc: Jens Axboe, linux-kernel, linux-block, Christoph Hellwig,
Naveen Kaje, stable
> + if (err) {
> + if (flags & ADDPART_FLAG_WHOLEDISK)
> + goto out_remove_file;
> + goto out_del;
> + }
I'd rather have that if around the actual device_remove_file at the
label, and jump to out_remove_file unconditionally.
Otherwise this looks fine to me.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] block: partition: initialize percpuref before sending out KOBJ_ADD
2016-03-30 17:43 ` Christoph Hellwig
@ 2016-03-31 2:22 ` Ming Lei
0 siblings, 0 replies; 3+ messages in thread
From: Ming Lei @ 2016-03-31 2:22 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Jens Axboe, Linux Kernel Mailing List, linux-block, Naveen Kaje,
stable
On Thu, Mar 31, 2016 at 1:43 AM, Christoph Hellwig <hch@infradead.org> wrote:
>> + if (err) {
>> + if (flags & ADDPART_FLAG_WHOLEDISK)
>> + goto out_remove_file;
>> + goto out_del;
>> + }
>
> I'd rather have that if around the actual device_remove_file at the
> label, and jump to out_remove_file unconditionally.
OK, looks better.
>
> Otherwise this looks fine to me.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-block" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-03-31 2:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-30 0:46 [PATCH] block: partition: initialize percpuref before sending out KOBJ_ADD Ming Lei
2016-03-30 17:43 ` Christoph Hellwig
2016-03-31 2:22 ` Ming Lei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox