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

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