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

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