lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <148912029.181750165204802.JavaMail.epsvc@epcpadp1new>
Date: Tue, 17 Jun 2025 18:09:32 +0530
From: Neeraj Kumar <s.neeraj@...sung.com>
To: dan.j.williams@...el.com, dave@...olabs.net,
	jonathan.cameron@...wei.com, dave.jiang@...el.com,
	alison.schofield@...el.com, vishal.l.verma@...el.com, ira.weiny@...el.com
Cc: a.manzanares@...sung.com, nifan.cxl@...il.com, anisa.su@...sung.com,
	vishak.g@...sung.com, krish.reddy@...sung.com, arun.george@...sung.com,
	alok.rathore@...sung.com, s.neeraj@...sung.com, neeraj.kernel@...il.com,
	linux-kernel@...r.kernel.org, linux-cxl@...r.kernel.org,
	nvdimm@...ts.linux.dev, gost.dev@...sung.com, cpgs@...sung.com
Subject: [RFC PATCH 08/20] nvdimm/label: Include region label in slot
 validation

slot validation routine validates label slot by calculating label
checksum. It was only validating namespace label. This changeset also
validates region label if present.

Also validate and calculate lsa v2.1 namespace label checksum

Signed-off-by: Neeraj Kumar <s.neeraj@...sung.com>
---
 drivers/nvdimm/label.c | 52 ++++++++++++++++++++++++++++++++++--------
 drivers/nvdimm/nd.h    | 21 +++++++++++++++++
 2 files changed, 63 insertions(+), 10 deletions(-)

diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c
index 108100c4bf44..22e13db1ca20 100644
--- a/drivers/nvdimm/label.c
+++ b/drivers/nvdimm/label.c
@@ -359,7 +359,7 @@ static bool nsl_validate_checksum(struct nvdimm_drvdata *ndd,
 {
 	u64 sum, sum_save;
 
-	if (!ndd->cxl && !efi_namespace_label_has(ndd, checksum))
+	if (!efi_namespace_label_has(ndd, checksum))
 		return true;
 
 	sum_save = nsl_get_checksum(ndd, nd_label);
@@ -374,13 +374,25 @@ static void nsl_calculate_checksum(struct nvdimm_drvdata *ndd,
 {
 	u64 sum;
 
-	if (!ndd->cxl && !efi_namespace_label_has(ndd, checksum))
+	if (!efi_namespace_label_has(ndd, checksum))
 		return;
 	nsl_set_checksum(ndd, nd_label, 0);
 	sum = nd_fletcher64(nd_label, sizeof_namespace_label(ndd), 1);
 	nsl_set_checksum(ndd, nd_label, sum);
 }
 
+static bool rgl_validate_checksum(struct nvdimm_drvdata *ndd,
+				  struct cxl_region_label *rg_label)
+{
+	u64 sum, sum_save;
+
+	sum_save = rgl_get_checksum(rg_label);
+	rgl_set_checksum(rg_label, 0);
+	sum = nd_fletcher64(rg_label, sizeof_namespace_label(ndd), 1);
+	rgl_set_checksum(rg_label, sum_save);
+	return sum == sum_save;
+}
+
 static void rgl_calculate_checksum(struct nvdimm_drvdata *ndd,
 				   struct cxl_region_label *rg_label)
 {
@@ -395,13 +407,25 @@ static bool slot_valid(struct nvdimm_drvdata *ndd,
 		struct nd_lsa_label *nd_label, u32 slot)
 {
 	bool valid;
+	char *label_name;
 
 	/* check that we are written where we expect to be written */
-	if (slot != nsl_get_slot(ndd, &nd_label->ns_label))
-		return false;
-	valid = nsl_validate_checksum(ndd, &nd_label->ns_label);
+	if (is_region_label(ndd, nd_label)) {
+		label_name = "rg";
+		if (slot != rgl_get_slot(&nd_label->rg_label))
+			return false;
+		valid = rgl_validate_checksum(ndd, &nd_label->rg_label);
+	} else {
+		label_name = "ns";
+		if (slot != nsl_get_slot(ndd, &nd_label->ns_label))
+			return false;
+		valid = nsl_validate_checksum(ndd, &nd_label->ns_label);
+	}
+
 	if (!valid)
-		dev_dbg(ndd->dev, "fail checksum. slot: %d\n", slot);
+		dev_dbg(ndd->dev, "%s label checksum fail. slot: %d\n",
+			label_name, slot);
+
 	return valid;
 }
 
@@ -577,17 +601,25 @@ int nd_label_active_count(struct nvdimm_drvdata *ndd)
 
 	for_each_clear_bit_le(slot, free, nslot) {
 		struct nd_lsa_label *nd_label;
+		u32 lslot;
+		u64 size, dpa;
 
 		nd_label = to_label(ndd, slot);
 
 		if (!slot_valid(ndd, nd_label, slot)) {
-			u32 label_slot = nsl_get_slot(ndd, &nd_label->ns_label);
-			u64 size = nsl_get_rawsize(ndd, &nd_label->ns_label);
-			u64 dpa = nsl_get_dpa(ndd, &nd_label->ns_label);
+			if (is_region_label(ndd, nd_label)) {
+				lslot = __le32_to_cpu(nd_label->rg_label.slot);
+				size = __le64_to_cpu(nd_label->rg_label.rawsize);
+				dpa = __cpu_to_le64(nd_label->rg_label.dpa);
+			} else {
+				lslot = nsl_get_slot(ndd, &nd_label->ns_label);
+				size = nsl_get_rawsize(ndd, &nd_label->ns_label);
+				dpa = nsl_get_dpa(ndd, &nd_label->ns_label);
+			}
 
 			dev_dbg(ndd->dev,
 				"slot%d invalid slot: %d dpa: %llx size: %llx\n",
-					slot, label_slot, dpa, size);
+					slot, lslot, dpa, size);
 			continue;
 		}
 		count++;
diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h
index 1e5a68013735..ca8256b31472 100644
--- a/drivers/nvdimm/nd.h
+++ b/drivers/nvdimm/nd.h
@@ -331,6 +331,22 @@ static inline bool nsl_region_uuid_equal(struct nd_namespace_label *ns_label,
 	return uuid_equal(&tmp, uuid);
 }
 
+static inline bool is_region_label(struct nvdimm_drvdata *ndd,
+				   struct nd_lsa_label *nd_label)
+{
+	uuid_t ns_type, region_type;
+
+	if (ndd->cxl) {
+		uuid_parse(CXL_REGION_UUID, &region_type);
+		import_uuid(&ns_type, nd_label->ns_label.cxl.type);
+		if (uuid_equal(&region_type, &ns_type))
+			return true;
+		else
+			return false;
+	} else
+		return false;
+}
+
 static inline bool rgl_uuid_equal(struct cxl_region_label *rg_label,
 				  const uuid_t *uuid)
 {
@@ -340,6 +356,11 @@ static inline bool rgl_uuid_equal(struct cxl_region_label *rg_label,
 	return uuid_equal(&tmp, uuid);
 }
 
+static inline u32 rgl_get_slot(struct cxl_region_label *rg_label)
+{
+	return __le32_to_cpu(rg_label->slot);
+}
+
 static inline u64 rgl_get_checksum(struct cxl_region_label *rg_label)
 {
 	return __le64_to_cpu(rg_label->checksum);
-- 
2.34.1



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ