Browse Source

nvdimm: Sanity check labeloff

This patch adds validation for the labeloff field in the indexes.

Reviewed-by: Toshi Kani <toshi.kani@hpe.com>
Signed-off-by: Alexander Duyck <alexander.h.duyck@linux.intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Alexander Duyck 6 years ago
parent
commit
d86d4d63d8
1 changed files with 7 additions and 0 deletions
  1. 7 0
      drivers/nvdimm/label.c

+ 7 - 0
drivers/nvdimm/label.c

@@ -183,6 +183,13 @@ static int __nd_label_validate(struct nvdimm_drvdata *ndd)
 					__le64_to_cpu(nsindex[i]->otheroff));
 					__le64_to_cpu(nsindex[i]->otheroff));
 			continue;
 			continue;
 		}
 		}
+		if (__le64_to_cpu(nsindex[i]->labeloff)
+				!= 2 * sizeof_namespace_index(ndd)) {
+			dev_dbg(dev, "nsindex%d labeloff: %#llx invalid\n",
+					i, (unsigned long long)
+					__le64_to_cpu(nsindex[i]->labeloff));
+			continue;
+		}
 
 
 		size = __le64_to_cpu(nsindex[i]->mysize);
 		size = __le64_to_cpu(nsindex[i]->mysize);
 		if (size > sizeof_namespace_index(ndd)
 		if (size > sizeof_namespace_index(ndd)