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
1823static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc,1823static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc,
1824 struct nfit_mem *nfit_mem, u32 device_handle)1824 struct nfit_mem *nfit_mem, u32 device_handle)
1825{1825{
1826 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
1826 struct acpi_device *adev, *adev_dimm;1827 struct acpi_device *adev, *adev_dimm;
1827 struct device *dev = acpi_desc->dev;1828 struct device *dev = acpi_desc->dev;
1828 unsigned long dsm_mask, label_mask;1829 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
1834 /* nfit test assumes 1:1 relationship between commands and dsms */1835 /* nfit test assumes 1:1 relationship between commands and dsms */
1835 nfit_mem->dsm_mask = acpi_desc->dimm_cmd_force_en;1836 nfit_mem->dsm_mask = acpi_desc->dimm_cmd_force_en;
1836 nfit_mem->family = NVDIMM_FAMILY_INTEL;1837 nfit_mem->family = NVDIMM_FAMILY_INTEL;
1838 set_bit(NVDIMM_FAMILY_INTEL, &nd_desc->dimm_family_mask);
1837 1839
1838 if (dcr->valid_fields & ACPI_NFIT_CONTROL_MFG_INFO_VALID)1840 if (dcr->valid_fields & ACPI_NFIT_CONTROL_MFG_INFO_VALID)
1839 sprintf(nfit_mem->id, "%04x-%02x-%04x-%08x",1841 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
1886 * Note, that checking for function0 (bit0) tells us if any commands1888 * Note, that checking for function0 (bit0) tells us if any commands
1887 * are reachable through this GUID.1889 * are reachable through this GUID.
1888 */1890 */
1891 clear_bit(NVDIMM_FAMILY_INTEL, &nd_desc->dimm_family_mask);
1889 for (i = 0; i <= NVDIMM_FAMILY_MAX; i++)1892 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);
1891 if (family < 0 || i == default_dsm_family)1895 if (family < 0 || i == default_dsm_family)
1892 family = i;1896 family = i;
1897 }
1893 1898
1894 /* limit the supported commands to those that are publicly documented */1899 /* limit the supported commands to those that are publicly documented */
1895 nfit_mem->family = family;1900 nfit_mem->family = family;
@@ -2153,6 +2158,9 @@ static void acpi_nfit_init_dsms(struct acpi_nfit_desc *acpi_desc) · 257 unmodified lines
2153 2158
2154 nd_desc->cmd_mask = acpi_desc->bus_cmd_force_en;2159 nd_desc->cmd_mask = acpi_desc->bus_cmd_force_en;
2155 nd_desc->bus_dsm_mask = acpi_desc->bus_nfit_cmd_force_en;2160 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
2156 adev = to_acpi_dev(acpi_desc);2164 adev = to_acpi_dev(acpi_desc);
2157 if (!adev)2165 if (!adev)
2158 return;2166 return;
@@ -2160,7 +2168,6 @@ static void acpi_nfit_init_dsms(struct acpi_nfit_desc *acpi_desc) · 1 unmodified line
2160 for (i = ND_CMD_ARS_CAP; i <= ND_CMD_CLEAR_ERROR; i++)2168 for (i = ND_CMD_ARS_CAP; i <= ND_CMD_CLEAR_ERROR; i++)
2161 if (acpi_check_dsm(adev->handle, guid, 1, 1ULL << i))2169 if (acpi_check_dsm(adev->handle, guid, 1, 1ULL << i))
2162 set_bit(i, &nd_desc->cmd_mask);2170 set_bit(i, &nd_desc->cmd_mask);
2163 set_bit(ND_CMD_CALL, &nd_desc->cmd_mask);
2164 2171
2165 dsm_mask =2172 dsm_mask =
2166 (1 << ND_CMD_ARS_CAP) |2173 (1 << ND_CMD_ARS_CAP) |
drivers/acpi/nfit/nfit.h+0−1
@@ -33,7 +33,6 @@ · 32 unmodified lines
33 | ACPI_NFIT_MEM_RESTORE_FAILED | ACPI_NFIT_MEM_FLUSH_FAILED \33 | ACPI_NFIT_MEM_RESTORE_FAILED | ACPI_NFIT_MEM_FLUSH_FAILED \
34 | ACPI_NFIT_MEM_NOT_ARMED | ACPI_NFIT_MEM_MAP_FAILED)34 | ACPI_NFIT_MEM_NOT_ARMED | ACPI_NFIT_MEM_MAP_FAILED)
35 35
36#define NVDIMM_FAMILY_MAX NVDIMM_FAMILY_HYPERV
37#define NVDIMM_CMD_MAX 3136#define NVDIMM_CMD_MAX 31
38 37
39#define NVDIMM_STANDARD_CMDMASK \38#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
1037 dimm_name = "bus";1037 dimm_name = "bus";
1038 }1038 }
1039 1039
1040 /* Validate command family support against bus declared support */
1040 if (cmd == ND_CMD_CALL) {1041 if (cmd == ND_CMD_CALL) {
1042 unsigned long *mask;
1043
1041 if (copy_from_user(&pkg, p, sizeof(pkg)))1044 if (copy_from_user(&pkg, p, sizeof(pkg)))
1042 return -EFAULT;1045 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;
1043 }1059 }
1044 1060
1045 if (!desc ||1061 if (!desc ||
include/linux/libnvdimm.h+2−0
@@ -78,6 +78,8 @@ struct nvdimm_bus_descriptor { · 77 unmodified lines
78 const struct attribute_group **attr_groups;78 const struct attribute_group **attr_groups;
79 unsigned long bus_dsm_mask;79 unsigned long bus_dsm_mask;
80 unsigned long cmd_mask;80 unsigned long cmd_mask;
81 unsigned long dimm_family_mask;
82 unsigned long bus_family_mask;
81 struct module *module;83 struct module *module;
82 char *provider_name;84 char *provider_name;
83 struct device_node *of_node;85 struct device_node *of_node;
include/uapi/linux/ndctl.h+4−0
@@ -245,6 +245,10 @@ struct nd_cmd_pkg { · 244 unmodified lines
245#define NVDIMM_FAMILY_MSFT 3245#define NVDIMM_FAMILY_MSFT 3
246#define NVDIMM_FAMILY_HYPERV 4246#define NVDIMM_FAMILY_HYPERV 4
247#define NVDIMM_FAMILY_PAPR 5247#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
248 252
249#define ND_IOCTL_CALL _IOWR(ND_IOCTL, ND_CMD_CALL,\253#define ND_IOCTL_CALL _IOWR(ND_IOCTL, ND_CMD_CALL,\
250 struct nd_cmd_pkg)254 struct nd_cmd_pkg)