anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone

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

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