Skip to content

Commit 82aa37c

Browse files
committed
acpi, nfit: validate ars_status output buffer size
If an ARS Status command returns truncated output, do not process partial records or otherwise consume non-status fields. Cc: <[email protected]> Fixes: 0caeef6 ("libnvdimm: Add a poison list and export badblocks") Signed-off-by: Dan Williams <[email protected]>
1 parent efda1b5 commit 82aa37c

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

drivers/acpi/nfit/core.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ static int xlat_status(void *buf, unsigned int cmd, u32 status)
146146
* then just continue with the returned results.
147147
*/
148148
if (status == NFIT_ARS_STATUS_INTR) {
149-
if (ars_status->flags & NFIT_ARS_F_OVERFLOW)
149+
if (ars_status->out_length >= 40 && (ars_status->flags
150+
& NFIT_ARS_F_OVERFLOW))
150151
return -ENOSPC;
151152
return 0;
152153
}
@@ -2002,19 +2003,32 @@ static int ars_get_status(struct acpi_nfit_desc *acpi_desc)
20022003
return cmd_rc;
20032004
}
20042005

2005-
static int ars_status_process_records(struct nvdimm_bus *nvdimm_bus,
2006+
static int ars_status_process_records(struct acpi_nfit_desc *acpi_desc,
20062007
struct nd_cmd_ars_status *ars_status)
20072008
{
2009+
struct nvdimm_bus *nvdimm_bus = acpi_desc->nvdimm_bus;
20082010
int rc;
20092011
u32 i;
20102012

2013+
/*
2014+
* First record starts at 44 byte offset from the start of the
2015+
* payload.
2016+
*/
2017+
if (ars_status->out_length < 44)
2018+
return 0;
20112019
for (i = 0; i < ars_status->num_records; i++) {
2020+
/* only process full records */
2021+
if (ars_status->out_length
2022+
< 44 + sizeof(struct nd_ars_record) * (i + 1))
2023+
break;
20122024
rc = nvdimm_bus_add_poison(nvdimm_bus,
20132025
ars_status->records[i].err_address,
20142026
ars_status->records[i].length);
20152027
if (rc)
20162028
return rc;
20172029
}
2030+
if (i < ars_status->num_records)
2031+
dev_warn(acpi_desc->dev, "detected truncated ars results\n");
20182032

20192033
return 0;
20202034
}
@@ -2267,8 +2281,7 @@ static int acpi_nfit_query_poison(struct acpi_nfit_desc *acpi_desc,
22672281
if (rc < 0 && rc != -ENOSPC)
22682282
return rc;
22692283

2270-
if (ars_status_process_records(acpi_desc->nvdimm_bus,
2271-
acpi_desc->ars_status))
2284+
if (ars_status_process_records(acpi_desc, acpi_desc->ars_status))
22722285
return -ENOMEM;
22732286

22742287
return 0;

0 commit comments

Comments
 (0)