OSDN Git Service

nvdimm: Sanity check labeloff
authorAlexander Duyck <alexander.h.duyck@linux.intel.com>
Wed, 10 Oct 2018 23:38:41 +0000 (16:38 -0700)
committerDan Williams <dan.j.williams@intel.com>
Fri, 12 Oct 2018 15:38:53 +0000 (08:38 -0700)
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>
drivers/nvdimm/label.c

index 1d28cd6..1f58425 100644 (file)
@@ -183,6 +183,13 @@ static int __nd_label_validate(struct nvdimm_drvdata *ndd)
                                        __le64_to_cpu(nsindex[i]->otheroff));
                        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);
                if (size > sizeof_namespace_index(ndd)