History

libnvdimm: Validate command family indices

The ND_CMD_CALL format allows for a general passthrough of passlisted commands targeting a given command set. However there is no validation of the family index relative to what the bus supports. - Update the NFIT bus implementation (the only one that supports ND_CMD_CALL passthrough) to also passlist the valid set of command family indices. - Update the generic __nd_ioctl() path to validate that field on behalf of all implementations.

Dan Williams committed 6 years ago

Commit 92fe2aa1 parent 48778465 files · +31 −3Browse files

Unified · Split

5 files
  1. drivers/acpi/nfit/core.c +9 −2
  2. drivers/acpi/nfit/nfit.h +0 −1
  3. drivers/nvdimm/bus.c +16 −0
  4. include/linux/libnvdimm.h +2 −0
  5. include/uapi/linux/ndctl.h +4 −0
drivers/acpi/nfit/core.c+9−2
@@ -1823,6 +1823,7 @@ static void populate_shutdown_status(struct nfit_mem *nfit_mem) · 1822 unmodified lines
18231823 static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc,
18241824 struct nfit_mem *nfit_mem, u32 device_handle)
18251825 {
1826+ struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
18261827 struct acpi_device *adev, *adev_dimm;
18271828 struct device *dev = acpi_desc->dev;
18281829 unsigned long dsm_mask, label_mask;
@@ -1834,6 +1835,7 @@ static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc, · 5 unmodified lines
18341835 /* nfit test assumes 1:1 relationship between commands and dsms */
18351836 nfit_mem->dsm_mask = acpi_desc->dimm_cmd_force_en;
18361837 nfit_mem->family = NVDIMM_FAMILY_INTEL;
1838+ set_bit(NVDIMM_FAMILY_INTEL, &nd_desc->dimm_family_mask);
18371839
18381840 if (dcr->valid_fields & ACPI_NFIT_CONTROL_MFG_INFO_VALID)
18391841 sprintf(nfit_mem->id, "%04x-%02x-%04x-%08x",
@@ -1886,10 +1888,13 @@ static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc, · 46 unmodified lines
18861888 * Note, that checking for function0 (bit0) tells us if any commands
18871889 * are reachable through this GUID.
18881890 */
1891+ clear_bit(NVDIMM_FAMILY_INTEL, &nd_desc->dimm_family_mask);
18891892 for (i = 0; i <= NVDIMM_FAMILY_MAX; i++)
1890− if (acpi_check_dsm(adev_dimm->handle, to_nfit_uuid(i), 1, 1))
1893+ if (acpi_check_dsm(adev_dimm->handle, to_nfit_uuid(i), 1, 1)) {
1894+ set_bit(i, &nd_desc->dimm_family_mask);
18911895 if (family < 0 || i == default_dsm_family)
18921896 family = i;
1897+ }
18931898
18941899 /* limit the supported commands to those that are publicly documented */
18951900 nfit_mem->family = family;
@@ -2153,6 +2158,9 @@ static void acpi_nfit_init_dsms(struct acpi_nfit_desc *acpi_desc) · 257 unmodified lines
21532158
21542159 nd_desc->cmd_mask = acpi_desc->bus_cmd_force_en;
21552160 nd_desc->bus_dsm_mask = acpi_desc->bus_nfit_cmd_force_en;
2161+ set_bit(ND_CMD_CALL, &nd_desc->cmd_mask);
2162+ set_bit(NVDIMM_BUS_FAMILY_NFIT, &nd_desc->bus_family_mask);
2163+
21562164 adev = to_acpi_dev(acpi_desc);
21572165 if (!adev)
21582166 return;
@@ -2160,7 +2168,6 @@ static void acpi_nfit_init_dsms(struct acpi_nfit_desc *acpi_desc) · 1 unmodified line
21602168 for (i = ND_CMD_ARS_CAP; i <= ND_CMD_CLEAR_ERROR; i++)
21612169 if (acpi_check_dsm(adev->handle, guid, 1, 1ULL << i))
21622170 set_bit(i, &nd_desc->cmd_mask);
2163− set_bit(ND_CMD_CALL, &nd_desc->cmd_mask);
21642171
21652172 dsm_mask =
21662173 (1 << ND_CMD_ARS_CAP) |
drivers/acpi/nfit/nfit.h+0−1
@@ -33,7 +33,6 @@ · 32 unmodified lines
3333 | ACPI_NFIT_MEM_RESTORE_FAILED | ACPI_NFIT_MEM_FLUSH_FAILED \
3434 | ACPI_NFIT_MEM_NOT_ARMED | ACPI_NFIT_MEM_MAP_FAILED)
3535
36−#define NVDIMM_FAMILY_MAX NVDIMM_FAMILY_HYPERV
3736 #define NVDIMM_CMD_MAX 31
3837
3938 #define NVDIMM_STANDARD_CMDMASK \
drivers/nvdimm/bus.c+16−0
@@ -1037,9 +1037,25 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm, · 1036 unmodified lines
10371037 dimm_name = "bus";
10381038 }
10391039
1040+ /* Validate command family support against bus declared support */
10401041 if (cmd == ND_CMD_CALL) {
1042+ unsigned long *mask;
1043+
10411044 if (copy_from_user(&pkg, p, sizeof(pkg)))
10421045 return -EFAULT;
1046+
1047+ if (nvdimm) {
1048+ if (pkg.nd_family > NVDIMM_FAMILY_MAX)
1049+ return -EINVAL;
1050+ mask = &nd_desc->dimm_family_mask;
1051+ } else {
1052+ if (pkg.nd_family > NVDIMM_BUS_FAMILY_MAX)
1053+ return -EINVAL;
1054+ mask = &nd_desc->bus_family_mask;
1055+ }
1056+
1057+ if (!test_bit(pkg.nd_family, mask))
1058+ return -EINVAL;
10431059 }
10441060
10451061 if (!desc ||
include/linux/libnvdimm.h+2−0
@@ -78,6 +78,8 @@ struct nvdimm_bus_descriptor { · 77 unmodified lines
7878 const struct attribute_group **attr_groups;
7979 unsigned long bus_dsm_mask;
8080 unsigned long cmd_mask;
81+ unsigned long dimm_family_mask;
82+ unsigned long bus_family_mask;
8183 struct module *module;
8284 char *provider_name;
8385 struct device_node *of_node;
include/uapi/linux/ndctl.h+4−0
@@ -245,6 +245,10 @@ struct nd_cmd_pkg { · 244 unmodified lines
245245 #define NVDIMM_FAMILY_MSFT 3
246246 #define NVDIMM_FAMILY_HYPERV 4
247247 #define NVDIMM_FAMILY_PAPR 5
248+#define NVDIMM_FAMILY_MAX NVDIMM_FAMILY_PAPR
249+
250+#define NVDIMM_BUS_FAMILY_NFIT 0
251+#define NVDIMM_BUS_FAMILY_MAX NVDIMM_BUS_FAMILY_NFIT
248252
249253 #define ND_IOCTL_CALL _IOWR(ND_IOCTL, ND_CMD_CALL,\
250254 struct nd_cmd_pkg)