Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1367765 > unrolled thread

[PATCH v1] block: partition: initialize percpuref before new partition is visiable

Started byMing Lei <ming.lei@canonical.com>
First post2016-03-31 04:50 +0200
Last post2016-03-31 10:20 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v1] block: partition: initialize percpuref before new partition is visiable Ming Lei <ming.lei@canonical.com> - 2016-03-31 04:50 +0200
    Re: [PATCH v1] block: partition: initialize percpuref before new  partition is visiable Christoph Hellwig <hch@infradead.org> - 2016-03-31 09:50 +0200
    Re: [PATCH v1] block: partition: initialize percpuref before new  partition is visiable Johannes Thumshirn <jthumshirn@suse.de> - 2016-03-31 10:20 +0200

#1367765 — [PATCH v1] block: partition: initialize percpuref before new partition is visiable

FromMing Lei <ming.lei@canonical.com>
Date2016-03-31 04:50 +0200
Subject[PATCH v1] block: partition: initialize percpuref before new partition is visiable
Message-ID<riAQh-6yy-7@gated-at.bofh.it>
The initialization of partition's percpu_ref should have been done before
the new partition is updated to partition table via
rcu_assign_pointer(), otherwise 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>
---
V1:
	- put 'if' around the actual device_remove_file at the label
	as suggested by Christoph
	- make commit log more accurate

 block/partition-generic.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/block/partition-generic.c b/block/partition-generic.c
index 5d87019..54d4be8 100644
--- a/block/partition-generic.c
+++ b/block/partition-generic.c
@@ -361,15 +361,17 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
 			goto out_del;
 	}
 
+	err = hd_ref_init(p);
+	if (err)
+		goto out_remove_file;
+
 	/* 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 +380,9 @@ out_free_stats:
 out_free:
 	kfree(p);
 	return ERR_PTR(err);
+out_remove_file:
+	if (flags & ADDPART_FLAG_WHOLEDISK)
+		device_remove_file(pdev, &dev_attr_whole_disk);
 out_del:
 	kobject_put(p->holder_dir);
 	device_del(pdev);
-- 
1.9.1

[toc] | [next] | [standalone]


#1367920 — Re: [PATCH v1] block: partition: initialize percpuref before new partition is visiable

FromChristoph Hellwig <hch@infradead.org>
Date2016-03-31 09:50 +0200
SubjectRe: [PATCH v1] block: partition: initialize percpuref before new partition is visiable
Message-ID<riFwC-1Bm-17@gated-at.bofh.it>
In reply to#1367765
Looks fine,

Reviewed-by: Christoph Hellwig <hch@lst.de>

[toc] | [prev] | [next] | [standalone]


#1367953 — Re: [PATCH v1] block: partition: initialize percpuref before new partition is visiable

FromJohannes Thumshirn <jthumshirn@suse.de>
Date2016-03-31 10:20 +0200
SubjectRe: [PATCH v1] block: partition: initialize percpuref before new partition is visiable
Message-ID<riFZE-24w-21@gated-at.bofh.it>
In reply to#1367765
On 2016-03-31 04:40, Ming Lei wrote:
> The initialization of partition's percpu_ref should have been done 
> before
> the new partition is updated to partition table via
> rcu_assign_pointer(), otherwise 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>
> ---
> V1:
> 	- put 'if' around the actual device_remove_file at the label
> 	as suggested by Christoph
> 	- make commit log more accurate
> 
>  block/partition-generic.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/block/partition-generic.c b/block/partition-generic.c
> index 5d87019..54d4be8 100644
> --- a/block/partition-generic.c
> +++ b/block/partition-generic.c
> @@ -361,15 +361,17 @@ struct hd_struct *add_partition(struct gendisk
> *disk, int partno,
>  			goto out_del;
>  	}
> 
> +	err = hd_ref_init(p);
> +	if (err)
> +		goto out_remove_file;
> +
>  	/* 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 +380,9 @@ out_free_stats:
>  out_free:
>  	kfree(p);
>  	return ERR_PTR(err);
> +out_remove_file:
> +	if (flags & ADDPART_FLAG_WHOLEDISK)
> +		device_remove_file(pdev, &dev_attr_whole_disk);
>  out_del:
>  	kobject_put(p->holder_dir);
>  	device_del(pdev);

Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web