Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1602477

[PATCH 4.4 33/35] nfit, libnvdimm: fix interleave set cookie calculation

From Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Newsgroups linux.kernel
Subject [PATCH 4.4 33/35] nfit, libnvdimm: fix interleave set cookie calculation
Date 2017-03-16 16:10 +0100
Message-ID <tlFco-97-63@gated-at.bofh.it> (permalink)
References <tlEJj-84L-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Dan Williams <dan.j.williams@intel.com>

commit 86ef58a4e35e8fa66afb5898cf6dec6a3bb29f67 upstream.

The interleave-set cookie is a sum that sanity checks the composition of
an interleave set has not changed from when the namespace was initially
created.  The checksum is calculated by sorting the DIMMs by their
location in the interleave-set. The comparison for the sort must be
64-bit wide, not byte-by-byte as performed by memcmp() in the broken
case.

Fix the implementation to accept correct cookie values in addition to
the Linux "memcmp" order cookies, but only allow correct cookies to be
generated going forward. It does mean that namespaces created by
third-party-tooling, or created by newer kernels with this fix, will not
validate on older kernels. However, there are a couple mitigating
conditions:

    1/ platforms with namespace-label capable NVDIMMs are not widely
       available.

    2/ interleave-sets with a single-dimm are by definition not affected
       (nothing to sort). This covers the QEMU-KVM NVDIMM emulation case.

The cookie stored in the namespace label will be fixed by any write the
namespace label, the most straightforward way to achieve this is to
write to the "alt_name" attribute of a namespace in sysfs.

Fixes: eaf961536e16 ("libnvdimm, nfit: add interleave-set state-tracking infrastructure")
Reported-by: Nicholas Moulin <nicholas.w.moulin@linux.intel.com>
Tested-by: Nicholas Moulin <nicholas.w.moulin@linux.intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/acpi/nfit.c             |   16 +++++++++++++++-
 drivers/nvdimm/namespace_devs.c |   28 +++++++++++++++++++++-------
 drivers/nvdimm/nd.h             |    1 +
 drivers/nvdimm/region_devs.c    |    9 +++++++++
 include/linux/libnvdimm.h       |    2 ++
 5 files changed, 48 insertions(+), 8 deletions(-)

--- a/drivers/acpi/nfit.c
+++ b/drivers/acpi/nfit.c
@@ -965,7 +965,7 @@ static size_t sizeof_nfit_set_info(int n
 		+ num_mappings * sizeof(struct nfit_set_info_map);
 }
 
-static int cmp_map(const void *m0, const void *m1)
+static int cmp_map_compat(const void *m0, const void *m1)
 {
 	const struct nfit_set_info_map *map0 = m0;
 	const struct nfit_set_info_map *map1 = m1;
@@ -974,6 +974,14 @@ static int cmp_map(const void *m0, const
 			sizeof(u64));
 }
 
+static int cmp_map(const void *m0, const void *m1)
+{
+	const struct nfit_set_info_map *map0 = m0;
+	const struct nfit_set_info_map *map1 = m1;
+
+	return map0->region_offset - map1->region_offset;
+}
+
 /* Retrieve the nth entry referencing this spa */
 static struct acpi_nfit_memory_map *memdev_from_spa(
 		struct acpi_nfit_desc *acpi_desc, u16 range_index, int n)
@@ -1029,6 +1037,12 @@ static int acpi_nfit_init_interleave_set
 	sort(&info->mapping[0], nr, sizeof(struct nfit_set_info_map),
 			cmp_map, NULL);
 	nd_set->cookie = nd_fletcher64(info, sizeof_nfit_set_info(nr), 0);
+
+	/* support namespaces created with the wrong sort order */
+	sort(&info->mapping[0], nr, sizeof(struct nfit_set_info_map),
+			cmp_map_compat, NULL);
+	nd_set->altcookie = nd_fletcher64(info, sizeof_nfit_set_info(nr), 0);
+
 	ndr_desc->nd_set = nd_set;
 	devm_kfree(dev, info);
 
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -1534,6 +1534,7 @@ static int select_pmem_id(struct nd_regi
 static int find_pmem_label_set(struct nd_region *nd_region,
 		struct nd_namespace_pmem *nspm)
 {
+	u64 altcookie = nd_region_interleave_set_altcookie(nd_region);
 	u64 cookie = nd_region_interleave_set_cookie(nd_region);
 	struct nd_namespace_label *nd_label;
 	u8 select_id[NSLABEL_UUID_LEN];
@@ -1542,8 +1543,10 @@ static int find_pmem_label_set(struct nd
 	int rc = -ENODEV, l;
 	u16 i;
 
-	if (cookie == 0)
+	if (cookie == 0) {
+		dev_dbg(&nd_region->dev, "invalid interleave-set-cookie\n");
 		return -ENXIO;
+	}
 
 	/*
 	 * Find a complete set of labels by uuid.  By definition we can start
@@ -1552,13 +1555,24 @@ static int find_pmem_label_set(struct nd
 	for_each_label(l, nd_label, nd_region->mapping[0].labels) {
 		u64 isetcookie = __le64_to_cpu(nd_label->isetcookie);
 
-		if (isetcookie != cookie)
-			continue;
+		if (isetcookie != cookie) {
+			dev_dbg(&nd_region->dev, "invalid cookie in label: %pUb\n",
+					nd_label->uuid);
+			if (isetcookie != altcookie)
+				continue;
+
+			dev_dbg(&nd_region->dev, "valid altcookie in label: %pUb\n",
+					nd_label->uuid);
+		}
+
+		for (i = 0; nd_region->ndr_mappings; i++) {
+			if (has_uuid_at_pos(nd_region, nd_label->uuid, cookie, i))
+				continue;
+			if (has_uuid_at_pos(nd_region, nd_label->uuid, altcookie, i))
+				continue;
+			break;
+		}
 
-		for (i = 0; nd_region->ndr_mappings; i++)
-			if (!has_uuid_at_pos(nd_region, nd_label->uuid,
-						cookie, i))
-				break;
 		if (i < nd_region->ndr_mappings) {
 			/*
 			 * Give up if we don't find an instance of a
--- a/drivers/nvdimm/nd.h
+++ b/drivers/nvdimm/nd.h
@@ -245,6 +245,7 @@ struct nd_region *to_nd_region(struct de
 int nd_region_to_nstype(struct nd_region *nd_region);
 int nd_region_register_namespaces(struct nd_region *nd_region, int *err);
 u64 nd_region_interleave_set_cookie(struct nd_region *nd_region);
+u64 nd_region_interleave_set_altcookie(struct nd_region *nd_region);
 void nvdimm_bus_lock(struct device *dev);
 void nvdimm_bus_unlock(struct device *dev);
 bool is_nvdimm_bus_locked(struct device *dev);
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -379,6 +379,15 @@ u64 nd_region_interleave_set_cookie(stru
 	return 0;
 }
 
+u64 nd_region_interleave_set_altcookie(struct nd_region *nd_region)
+{
+	struct nd_interleave_set *nd_set = nd_region->nd_set;
+
+	if (nd_set)
+		return nd_set->altcookie;
+	return 0;
+}
+
 /*
  * Upon successful probe/remove, take/release a reference on the
  * associated interleave set (if present), and plant new btt + namespace
--- a/include/linux/libnvdimm.h
+++ b/include/linux/libnvdimm.h
@@ -83,6 +83,8 @@ struct nd_cmd_desc {
 
 struct nd_interleave_set {
 	u64 cookie;
+	/* compatibility with initial buggy Linux implementation */
+	u64 altcookie;
 };
 
 struct nd_region_desc {

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 4.4 00/35] 4.4.55-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:10 +0100
  [PATCH 4.4 26/35] USB: iowarrior: fix NULL-deref in write Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:10 +0100
  [PATCH 4.4 18/35] usb: gadget: dummy_hcd: clear usb_gadget region before registration Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:10 +0100
  [PATCH 4.4 35/35] ext4: dont BUG when truncating encrypted inodes on the orphan list Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:10 +0100
  [PATCH 4.4 04/35] MIPS: Update defconfigs for NF_CT_PROTO_DCCP/UDPLITE change Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:10 +0100
    Re: [PATCH 4.4 04/35] MIPS: Update defconfigs for  NF_CT_PROTO_DCCP/UDPLITE change Ben Hutchings <ben@decadent.org.uk> - 2017-03-19 18:20 +0100
      Re: [PATCH 4.4 04/35] MIPS: Update defconfigs for  NF_CT_PROTO_DCCP/UDPLITE change Ralf Baechle <ralf@linux-mips.org> - 2017-03-20 11:10 +0100
      Re: [PATCH 4.4 04/35] MIPS: Update defconfigs for  NF_CT_PROTO_DCCP/UDPLITE change Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-20 11:40 +0100
        Re: [PATCH 4.4 04/35] MIPS: Update defconfigs for NF_CT_PROTO_DCCP/UDPLITE  change Arnd Bergmann <arnd@arndb.de> - 2017-03-20 11:50 +0100
          Re: [PATCH 4.4 04/35] MIPS: Update defconfigs for  NF_CT_PROTO_DCCP/UDPLITE change Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-20 17:40 +0100
            Re: [PATCH 4.4 04/35] MIPS: Update defconfigs for  NF_CT_PROTO_DCCP/UDPLITE change Ralf Baechle <ralf@linux-mips.org> - 2017-03-20 17:50 +0100
  [PATCH 4.4 34/35] dm: flush queued bios when process blocks to avoid deadlock Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:10 +0100
  [PATCH 4.4 32/35] s390/kdump: Use "LINUX" ELF note name instead of "CORE" Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:10 +0100
  [PATCH 4.4 33/35] nfit, libnvdimm: fix interleave set cookie calculation Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:10 +0100
    Re: [PATCH 4.4 33/35] nfit, libnvdimm: fix interleave set cookie  calculation Ben Hutchings <ben@decadent.org.uk> - 2017-03-19 18:20 +0100
      Re: [PATCH 4.4 33/35] nfit, libnvdimm: fix interleave set cookie calculation Dan Williams <dan.j.williams@intel.com> - 2017-03-20 19:30 +0100
  [PATCH 4.4 09/35] mtd: pmcmsp: use kstrndup instead of kmalloc+strncpy Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:10 +0100
  [PATCH 4.4 27/35] USB: serial: io_ti: fix NULL-deref in interrupt callback Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:10 +0100
  [PATCH 4.4 07/35] MIPS: ip22: Fix ip28 build for modern gcc Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:10 +0100
  [PATCH 4.4 03/35] crypto: improve gcc optimization flags for serpent and wp512 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:10 +0100
  [PATCH 4.4 08/35] MIPS: Update lemote2f_defconfig for CPU_FREQ_STAT change Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:10 +0100
    Re: [PATCH 4.4 08/35] MIPS: Update lemote2f_defconfig for  CPU_FREQ_STAT change Ben Hutchings <ben@decadent.org.uk> - 2017-03-19 17:10 +0100
      Re: [PATCH 4.4 08/35] MIPS: Update lemote2f_defconfig for  CPU_FREQ_STAT change Ralf Baechle <ralf@linux-mips.org> - 2017-03-20 11:20 +0100
        Re: [PATCH 4.4 08/35] MIPS: Update lemote2f_defconfig for  CPU_FREQ_STAT change Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-20 17:40 +0100
          Re: [PATCH 4.4 08/35] MIPS: Update lemote2f_defconfig for  CPU_FREQ_STAT change Ralf Baechle <ralf@linux-mips.org> - 2017-03-20 18:00 +0100
            Re: [PATCH 4.4 08/35] MIPS: Update lemote2f_defconfig for  CPU_FREQ_STAT change Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-20 18:40 +0100
      Re: [PATCH 4.4 08/35] MIPS: Update lemote2f_defconfig for  CPU_FREQ_STAT change Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-20 11:40 +0100
  [PATCH 4.4 24/35] USB: serial: omninet: fix reference leaks at open Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:10 +0100
  [PATCH 4.4 20/35] usb: gadget: function: f_fs: pass companion descriptor along Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:20 +0100
  [PATCH 4.4 19/35] usb: dwc3: gadget: make Set Endpoint Configuration macros safe Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:20 +0100
  [PATCH 4.4 15/35] MIPS: Netlogic: Fix CP0_EBASE redefinition warnings Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:20 +0100
  [PATCH 4.4 23/35] USB: serial: safe_serial: fix information leak in completion handler Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:20 +0100
  [PATCH 4.4 16/35] tracing: Add #undef to fix compile error Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-03-16 16:20 +0100
  Re: [PATCH 4.4 00/35] 4.4.55-stable review Shuah Khan <shuahkh@osg.samsung.com> - 2017-03-16 20:30 +0100
  Re: [PATCH 4.4 00/35] 4.4.55-stable review Guenter Roeck <linux@roeck-us.net> - 2017-03-16 23:40 +0100

csiph-web