Skip to content

Commit 01091c4

Browse files
Dan Carpenterdjbw
authored andcommitted
acpi/nfit: improve bounds checking for 'func'
The 'func' variable can come from the user in the __nd_ioctl(). If it's too high then the (1 << func) shift in acpi_nfit_clear_to_send() is undefined. In acpi_nfit_ctl() we pass 'func' to test_bit(func, &dsm_mask) which could result in an out of bounds access. To fix these issues, I introduced the NVDIMM_CMD_MAX (31) define and updated nfit_dsm_revid() to use that define as well instead of magic numbers. Fixes: 11189c1 ("acpi/nfit: Fix command-supported detection") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Dan Williams <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent c0e71d6 commit 01091c4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

drivers/acpi/nfit/core.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static union acpi_object *acpi_label_info(acpi_handle handle)
360360

361361
static u8 nfit_dsm_revid(unsigned family, unsigned func)
362362
{
363-
static const u8 revid_table[NVDIMM_FAMILY_MAX+1][32] = {
363+
static const u8 revid_table[NVDIMM_FAMILY_MAX+1][NVDIMM_CMD_MAX+1] = {
364364
[NVDIMM_FAMILY_INTEL] = {
365365
[NVDIMM_INTEL_GET_MODES] = 2,
366366
[NVDIMM_INTEL_GET_FWINFO] = 2,
@@ -386,7 +386,7 @@ static u8 nfit_dsm_revid(unsigned family, unsigned func)
386386

387387
if (family > NVDIMM_FAMILY_MAX)
388388
return 0;
389-
if (func > 31)
389+
if (func > NVDIMM_CMD_MAX)
390390
return 0;
391391
id = revid_table[family][func];
392392
if (id == 0)
@@ -492,7 +492,8 @@ int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
492492
* Check for a valid command. For ND_CMD_CALL, we also have to
493493
* make sure that the DSM function is supported.
494494
*/
495-
if (cmd == ND_CMD_CALL && !test_bit(func, &dsm_mask))
495+
if (cmd == ND_CMD_CALL &&
496+
(func > NVDIMM_CMD_MAX || !test_bit(func, &dsm_mask)))
496497
return -ENOTTY;
497498
else if (!test_bit(cmd, &cmd_mask))
498499
return -ENOTTY;
@@ -3492,7 +3493,8 @@ static int acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc,
34923493
if (nvdimm && cmd == ND_CMD_CALL &&
34933494
call_pkg->nd_family == NVDIMM_FAMILY_INTEL) {
34943495
func = call_pkg->nd_command;
3495-
if ((1 << func) & NVDIMM_INTEL_SECURITY_CMDMASK)
3496+
if (func > NVDIMM_CMD_MAX ||
3497+
(1 << func) & NVDIMM_INTEL_SECURITY_CMDMASK)
34963498
return -EOPNOTSUPP;
34973499
}
34983500

drivers/acpi/nfit/nfit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
| ACPI_NFIT_MEM_NOT_ARMED | ACPI_NFIT_MEM_MAP_FAILED)
3535

3636
#define NVDIMM_FAMILY_MAX NVDIMM_FAMILY_HYPERV
37+
#define NVDIMM_CMD_MAX 31
3738

3839
#define NVDIMM_STANDARD_CMDMASK \
3940
(1 << ND_CMD_SMART | 1 << ND_CMD_SMART_THRESHOLD | 1 << ND_CMD_DIMM_FLAGS \

0 commit comments

Comments
 (0)