Blame SOURCES/0171-libcxl-fix-a-segfault-when-memdev-pmem-is-absent.patch

26ccd9
From 50e7a021314aa0365c9c85a359a31f26313fe93b Mon Sep 17 00:00:00 2001
26ccd9
From: Vishal Verma <vishal.l.verma@intel.com>
26ccd9
Date: Thu, 2 Jun 2022 09:44:27 -0600
26ccd9
Subject: [PATCH 171/217] libcxl: fix a segfault when memdev->pmem is absent
26ccd9
26ccd9
A CXL memdev may not have any persistent capacity, and in this case it
26ccd9
is possible that a 'pmem' object never gets instantiated. Such a
26ccd9
scenario would cause free_pmem () to dereference a NULL pointer and
26ccd9
segfault.
26ccd9
26ccd9
Fix this by only proceeding in free_pmem() if 'pmem' was valid.
26ccd9
26ccd9
Link: https://lore.kernel.org/r/20220602154427.462852-1-vishal.l.verma@intel.com
26ccd9
Fixes: cd1aed6cefe8 ("libcxl: add representation for an nvdimm bridge object")
26ccd9
Cc: Dan Williams <dan.j.williams@intel.com>
26ccd9
Reported-by: Steven Garcia <steven.garcia@intel.com>
26ccd9
Tested-by: Steven Garcia <steven.garcia@intel.com>
26ccd9
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
26ccd9
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
26ccd9
---
26ccd9
 cxl/lib/libcxl.c | 8 +++++---
26ccd9
 1 file changed, 5 insertions(+), 3 deletions(-)
26ccd9
26ccd9
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
26ccd9
index 374b0f1..c988ce2 100644
26ccd9
--- a/cxl/lib/libcxl.c
26ccd9
+++ b/cxl/lib/libcxl.c
26ccd9
@@ -49,9 +49,11 @@ struct cxl_ctx {
26ccd9
 
26ccd9
 static void free_pmem(struct cxl_pmem *pmem)
26ccd9
 {
26ccd9
-	free(pmem->dev_buf);
26ccd9
-	free(pmem->dev_path);
26ccd9
-	free(pmem);
26ccd9
+	if (pmem) {
26ccd9
+		free(pmem->dev_buf);
26ccd9
+		free(pmem->dev_path);
26ccd9
+		free(pmem);
26ccd9
+	}
26ccd9
 }
26ccd9
 
26ccd9
 static void free_memdev(struct cxl_memdev *memdev, struct list_head *head)
26ccd9
-- 
26ccd9
2.27.0
26ccd9