Skip to content

Commit 92fe2aa

Browse files
djbwstellarhopper
authored andcommitted
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. Fixes: 31eca76 ("nfit, libnvdimm: limited/whitelisted dimm command marshaling mechanism") Cc: Vishal Verma <[email protected]> Cc: Dave Jiang <[email protected]> Cc: Ira Weiny <[email protected]> Cc: "Rafael J. Wysocki" <[email protected]> Cc: Len Brown <[email protected]> Cc: <[email protected]> Signed-off-by: Dan Williams <[email protected]> Signed-off-by: Vishal Verma <[email protected]>
1 parent 4877846 commit 92fe2aa

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

drivers/acpi/nfit/core.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,7 @@ static void populate_shutdown_status(struct nfit_mem *nfit_mem)
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,
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,
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,14 +2158,16 @@ static void acpi_nfit_init_dsms(struct acpi_nfit_desc *acpi_desc)
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;
21592167

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,9 +1037,25 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm,
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ struct nvdimm_bus_descriptor {
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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ struct nd_cmd_pkg {
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)

0 commit comments

Comments
 (0)