All of lore.kernel.org
 help / color / mirror / Atom feed
* [ndctl PATCH] libcxl: fix a segfault when memdev->pmem is absent
@ 2022-06-02 15:44 Vishal Verma
  2022-06-15 21:46 ` Alison Schofield
  2022-06-16 17:19 ` [PATCH] " Davidlohr Bueso
  0 siblings, 2 replies; 3+ messages in thread
From: Vishal Verma @ 2022-06-02 15:44 UTC (permalink / raw)
  To: linux-cxl; +Cc: nvdimm, Dan Williams, Vishal Verma, Steven Garcia

A CXL memdev may not have any persistent capacity, and in this case it
is possible that a 'pmem' object never gets instantiated. Such a
scenario would cause free_pmem () to dereference a NULL pointer and
segfault.

Fix this by only proceeding in free_pmem() if 'pmem' was valid.

Fixes: cd1aed6cefe8 ("libcxl: add representation for an nvdimm bridge object")
Reported-by: Steven Garcia <steven.garcia@intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 cxl/lib/libcxl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index 1ad4a0b..2578a43 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -50,9 +50,11 @@ struct cxl_ctx {
 
 static void free_pmem(struct cxl_pmem *pmem)
 {
-	free(pmem->dev_buf);
-	free(pmem->dev_path);
-	free(pmem);
+	if (pmem) {
+		free(pmem->dev_buf);
+		free(pmem->dev_path);
+		free(pmem);
+	}
 }
 
 static void free_memdev(struct cxl_memdev *memdev, struct list_head *head)

base-commit: 4229f2694e8887a47c636a54130cff0d65f2e995
-- 
2.36.1


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

* Re: [ndctl PATCH] libcxl: fix a segfault when memdev->pmem is absent
  2022-06-02 15:44 [ndctl PATCH] libcxl: fix a segfault when memdev->pmem is absent Vishal Verma
@ 2022-06-15 21:46 ` Alison Schofield
  2022-06-16 17:19 ` [PATCH] " Davidlohr Bueso
  1 sibling, 0 replies; 3+ messages in thread
From: Alison Schofield @ 2022-06-15 21:46 UTC (permalink / raw)
  To: Vishal Verma; +Cc: linux-cxl, nvdimm, Dan Williams, Steven Garcia

On Thu, Jun 02, 2022 at 09:44:27AM -0600, Vishal Verma wrote:
> A CXL memdev may not have any persistent capacity, and in this case it
> is possible that a 'pmem' object never gets instantiated. Such a
> scenario would cause free_pmem () to dereference a NULL pointer and
> segfault.
> 
> Fix this by only proceeding in free_pmem() if 'pmem' was valid.
> 
> Fixes: cd1aed6cefe8 ("libcxl: add representation for an nvdimm bridge object")
> Reported-by: Steven Garcia <steven.garcia@intel.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
> ---

Reviewed-by: Alison Schofield <alison.schofield@intel.com>

>  cxl/lib/libcxl.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
> index 1ad4a0b..2578a43 100644
> --- a/cxl/lib/libcxl.c
> +++ b/cxl/lib/libcxl.c
> @@ -50,9 +50,11 @@ struct cxl_ctx {
>  
>  static void free_pmem(struct cxl_pmem *pmem)
>  {
> -	free(pmem->dev_buf);
> -	free(pmem->dev_path);
> -	free(pmem);
> +	if (pmem) {
> +		free(pmem->dev_buf);
> +		free(pmem->dev_path);
> +		free(pmem);
> +	}
>  }
>  
>  static void free_memdev(struct cxl_memdev *memdev, struct list_head *head)
> 
> base-commit: 4229f2694e8887a47c636a54130cff0d65f2e995
> -- 
> 2.36.1
> 
> 

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

* Re: [PATCH] libcxl: fix a segfault when memdev->pmem is absent
  2022-06-02 15:44 [ndctl PATCH] libcxl: fix a segfault when memdev->pmem is absent Vishal Verma
  2022-06-15 21:46 ` Alison Schofield
@ 2022-06-16 17:19 ` Davidlohr Bueso
  1 sibling, 0 replies; 3+ messages in thread
From: Davidlohr Bueso @ 2022-06-16 17:19 UTC (permalink / raw)
  To: Vishal Verma; +Cc: linux-cxl, nvdimm, Dan Williams, Steven Garcia

On Thu, 02 Jun 2022, Vishal Verma wrote:

>A CXL memdev may not have any persistent capacity, and in this case it
>is possible that a 'pmem' object never gets instantiated. Such a
>scenario would cause free_pmem () to dereference a NULL pointer and
>segfault.
>
>Fix this by only proceeding in free_pmem() if 'pmem' was valid.
>
>Fixes: cd1aed6cefe8 ("libcxl: add representation for an nvdimm bridge object")
>Reported-by: Steven Garcia <steven.garcia@intel.com>
>Cc: Dan Williams <dan.j.williams@intel.com>
>Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
>Reviewed-by: Alison Schofield <alison.schofield@intel.com>

Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>

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

end of thread, other threads:[~2022-06-16 17:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-02 15:44 [ndctl PATCH] libcxl: fix a segfault when memdev->pmem is absent Vishal Verma
2022-06-15 21:46 ` Alison Schofield
2022-06-16 17:19 ` [PATCH] " Davidlohr Bueso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.