nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] libnvdimm/pmem: Fix blk_cleanup_disk() usage
@ 2021-06-07 23:31 Dan Williams
  2021-06-07 23:52 ` [PATCH v2] " Dan Williams
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Williams @ 2021-06-07 23:31 UTC (permalink / raw)
  To: axboe
  Cc: Sachin Sant, Christoph Hellwig, Ulf Hansson, nvdimm, linux-block,
	linuxppc-dev

The queue_to_disk() helper can not be used after del_gendisk()
communicate @disk via the pgmap->owner.

Reported-by: Sachin Sant <sachinp@linux.vnet.ibm.com>
Fixes: 87eb73b2ca7c ("nvdimm-pmem: convert to blk_alloc_disk/blk_cleanup_disk")
Cc: Christoph Hellwig <hch@lst.de>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
Jens,

Please take or fold this into your tree after Sachin has a chance
to test it out. It's passing my tests.

 drivers/nvdimm/pmem.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 31f3c4bd6f72..fc6b78dd2d24 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -337,8 +337,9 @@ static void pmem_pagemap_cleanup(struct dev_pagemap *pgmap)
 {
 	struct request_queue *q =
 		container_of(pgmap->ref, struct request_queue, q_usage_counter);
+	struct pmem_device *pmem = pgmap->owner;
 
-	blk_cleanup_disk(queue_to_disk(q));
+	blk_cleanup_disk(pmem->disk);
 }
 
 static void pmem_release_queue(void *pgmap)
@@ -427,6 +428,7 @@ static int pmem_attach_disk(struct device *dev,
 	q = disk->queue;
 
 	pmem->disk = disk;
+	pmem->pgmap.owner = pmem;
 	pmem->pfn_flags = PFN_DEV;
 	pmem->pgmap.ref = &q->q_usage_counter;
 	if (is_nd_pfn(dev)) {


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2] libnvdimm/pmem: Fix blk_cleanup_disk() usage
  2021-06-07 23:31 [PATCH] libnvdimm/pmem: Fix blk_cleanup_disk() usage Dan Williams
@ 2021-06-07 23:52 ` Dan Williams
  2021-06-08  5:36   ` Christoph Hellwig
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Dan Williams @ 2021-06-07 23:52 UTC (permalink / raw)
  To: axboe
  Cc: Sachin Sant, Christoph Hellwig, Ulf Hansson, nvdimm, linux-block,
	linuxppc-dev

The queue_to_disk() helper can not be used after del_gendisk()
communicate @disk via the pgmap->owner.

Otherwise, queue_to_disk() returns NULL resulting in the splat below.

 Kernel attempted to read user page (330) - exploit attempt? (uid: 0)
 BUG: Kernel NULL pointer dereference on read at 0x00000330
 Faulting instruction address: 0xc000000000906344
 Oops: Kernel access of bad area, sig: 11 [#1]
 [..]
 NIP [c000000000906344] pmem_pagemap_cleanup+0x24/0x40
 LR [c0000000004701d4] memunmap_pages+0x1b4/0x4b0
 Call Trace:
 [c000000022cbb9c0] [c0000000009063c8] pmem_pagemap_kill+0x28/0x40 (unreliable)
 [c000000022cbb9e0] [c0000000004701d4] memunmap_pages+0x1b4/0x4b0
 [c000000022cbba90] [c0000000008b28a0] devm_action_release+0x30/0x50
 [c000000022cbbab0] [c0000000008b39c8] release_nodes+0x2f8/0x3e0
 [c000000022cbbb60] [c0000000008ac440] device_release_driver_internal+0x190/0x2b0
 [c000000022cbbba0] [c0000000008a8450] unbind_store+0x130/0x170

Reported-by: Sachin Sant <sachinp@linux.vnet.ibm.com>
Fixes: 87eb73b2ca7c ("nvdimm-pmem: convert to blk_alloc_disk/blk_cleanup_disk")
Link: http://lore.kernel.org/r/DFB75BA8-603F-4A35-880B-C5B23EF8FA7D@linux.vnet.ibm.com
Cc: Christoph Hellwig <hch@lst.de>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
Changes in v2 Improve the changelog.

 drivers/nvdimm/pmem.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 31f3c4bd6f72..fc6b78dd2d24 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -337,8 +337,9 @@ static void pmem_pagemap_cleanup(struct dev_pagemap *pgmap)
 {
 	struct request_queue *q =
 		container_of(pgmap->ref, struct request_queue, q_usage_counter);
+	struct pmem_device *pmem = pgmap->owner;
 
-	blk_cleanup_disk(queue_to_disk(q));
+	blk_cleanup_disk(pmem->disk);
 }
 
 static void pmem_release_queue(void *pgmap)
@@ -427,6 +428,7 @@ static int pmem_attach_disk(struct device *dev,
 	q = disk->queue;
 
 	pmem->disk = disk;
+	pmem->pgmap.owner = pmem;
 	pmem->pfn_flags = PFN_DEV;
 	pmem->pgmap.ref = &q->q_usage_counter;
 	if (is_nd_pfn(dev)) {


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] libnvdimm/pmem: Fix blk_cleanup_disk() usage
  2021-06-07 23:52 ` [PATCH v2] " Dan Williams
@ 2021-06-08  5:36   ` Christoph Hellwig
  2021-06-08  5:43   ` Sachin Sant
  2021-06-08 21:26   ` Jens Axboe
  2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2021-06-08  5:36 UTC (permalink / raw)
  To: Dan Williams
  Cc: axboe, Sachin Sant, Christoph Hellwig, Ulf Hansson, nvdimm,
	linux-block, linuxppc-dev

Thanks Dan, this looks good to me:

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

Jens, can you quickly pick this up?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] libnvdimm/pmem: Fix blk_cleanup_disk() usage
  2021-06-07 23:52 ` [PATCH v2] " Dan Williams
  2021-06-08  5:36   ` Christoph Hellwig
@ 2021-06-08  5:43   ` Sachin Sant
  2021-06-08 21:26   ` Jens Axboe
  2 siblings, 0 replies; 5+ messages in thread
From: Sachin Sant @ 2021-06-08  5:43 UTC (permalink / raw)
  To: Dan Williams
  Cc: axboe, nvdimm, Ulf Hansson, linux-block, linuxppc-dev, Christoph Hellwig


> Reported-by: Sachin Sant <sachinp@linux.vnet.ibm.com>
> Fixes: 87eb73b2ca7c ("nvdimm-pmem: convert to blk_alloc_disk/blk_cleanup_disk")
> Link: http://lore.kernel.org/r/DFB75BA8-603F-4A35-880B-C5B23EF8FA7D@linux.vnet.ibm.com
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Jens Axboe <axboe@kernel.dk>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---

Thanks Dan. This patch fixes the reported crash for me.

Tested-by: Sachin Sant <sachinp@linux.vnet.ibm.com>
> 
> Changes in v2 Improve the changelog.
> 
> drivers/nvdimm/pmem.c |    4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
> index 31f3c4bd6f72..fc6b78dd2d24 100644
> --- a/drivers/nvdimm/pmem.c
> +++ b/drivers/nvdimm/pmem.c
> @@ -337,8 +337,9 @@ static void pmem_pagemap_cleanup(struct dev_pagemap *pgmap)
> {
> 	struct request_queue *q =
> 		container_of(pgmap->ref, struct request_queue, q_usage_counter);

With this change variable ‘q' is no longer needed and can be removed.

drivers/nvdimm/pmem.c: In function 'pmem_pagemap_cleanup':
drivers/nvdimm/pmem.c:338:24: warning: unused variable 'q' [-Wunused-variable]
  struct request_queue *q =  
                                      ^
> +	struct pmem_device *pmem = pgmap->owner;
> 
> -	blk_cleanup_disk(queue_to_disk(q));
> +	blk_cleanup_disk(pmem->disk);
> }
> 
> static void pmem_release_queue(void *pgmap)
> @@ -427,6 +428,7 @@ static int pmem_attach_disk(struct device *dev,
> 	q = disk->queue;
> 
> 	pmem->disk = disk;
> +	pmem->pgmap.owner = pmem;
> 	pmem->pfn_flags = PFN_DEV;
> 	pmem->pgmap.ref = &q->q_usage_counter;
> 	if (is_nd_pfn(dev)) {
> 

Thanks
-Sachin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] libnvdimm/pmem: Fix blk_cleanup_disk() usage
  2021-06-07 23:52 ` [PATCH v2] " Dan Williams
  2021-06-08  5:36   ` Christoph Hellwig
  2021-06-08  5:43   ` Sachin Sant
@ 2021-06-08 21:26   ` Jens Axboe
  2 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2021-06-08 21:26 UTC (permalink / raw)
  To: Dan Williams
  Cc: Sachin Sant, Christoph Hellwig, Ulf Hansson, nvdimm, linux-block,
	linuxppc-dev

On 6/7/21 5:52 PM, Dan Williams wrote:
> The queue_to_disk() helper can not be used after del_gendisk()
> communicate @disk via the pgmap->owner.
> 
> Otherwise, queue_to_disk() returns NULL resulting in the splat below.
> 
>  Kernel attempted to read user page (330) - exploit attempt? (uid: 0)
>  BUG: Kernel NULL pointer dereference on read at 0x00000330
>  Faulting instruction address: 0xc000000000906344
>  Oops: Kernel access of bad area, sig: 11 [#1]
>  [..]
>  NIP [c000000000906344] pmem_pagemap_cleanup+0x24/0x40
>  LR [c0000000004701d4] memunmap_pages+0x1b4/0x4b0
>  Call Trace:
>  [c000000022cbb9c0] [c0000000009063c8] pmem_pagemap_kill+0x28/0x40 (unreliable)
>  [c000000022cbb9e0] [c0000000004701d4] memunmap_pages+0x1b4/0x4b0
>  [c000000022cbba90] [c0000000008b28a0] devm_action_release+0x30/0x50
>  [c000000022cbbab0] [c0000000008b39c8] release_nodes+0x2f8/0x3e0
>  [c000000022cbbb60] [c0000000008ac440] device_release_driver_internal+0x190/0x2b0
>  [c000000022cbbba0] [c0000000008a8450] unbind_store+0x130/0x170

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-08 21:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-07 23:31 [PATCH] libnvdimm/pmem: Fix blk_cleanup_disk() usage Dan Williams
2021-06-07 23:52 ` [PATCH v2] " Dan Williams
2021-06-08  5:36   ` Christoph Hellwig
2021-06-08  5:43   ` Sachin Sant
2021-06-08 21:26   ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).