Skip to contentSkip to conversation

acpi: fix assert failure caused by commit 35c5a52d

PATCH In review Haozhong Zhang 3 participants 3 messages Oct 19, 2016 – Oct 24, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 acpi: fix assert failure caused by commit 35c5a52d

Commit 35c5a52d "acpi: do not use TARGET_PAGE_SIZE" changed struct NvdimmDsmIn from a variable-size structure to a fixed-size structure of 4096 bytes. It forgot to adjust an assert in nvdimm_dsm_set_label_data(..., NvdimmDsmIn *in, ...):

    assert(sizeof(*in) + sizeof(*set_label_data) + set_label_data->length <=
           4096);

which could crash QEMU when guest writes NVDIMM labels.

Fix it by replacing sizeof(*in) by offsetof(NvdimmDsmIn, arg3).

---
 hw/acpi/nvdimm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/acpi/nvdimm.c +2 -2
index e486128..9fdc56a 100644
@@ -643,8 +643,8 @@ static void nvdimm_dsm_set_label_data(NVDIMMDevice *nvdimm, NvdimmDsmIn *in,
         return;
     }
 
-    assert(sizeof(*in) + sizeof(*set_label_data) + set_label_data->length <=
-           4096);
+    assert(offsetof(NvdimmDsmIn, arg3) +
+           sizeof(*set_label_data) + set_label_data->length <= 4096);
 
     nvc->write_label_data(nvdimm, set_label_data->in_buf,
                           set_label_data->length, set_label_data->offset);
Signature · 1 line
2.10.1
Tested-by on v1 1/1
#1 lore raw
Quoted 4 lines · Haozhong Zhang

Commit 35c5a52d "acpi: do not use TARGET_PAGE_SIZE" changed struct NvdimmDsmIn from a variable-size structure to a fixed-size structure of 4096 bytes. It forgot to adjust an assert in nvdimm_dsm_set_label_data(..., NvdimmDsmIn *in, ...):

Quoted 8 lines
    assert(sizeof(*in) + sizeof(*set_label_data) + set_label_data->length <=
           4096);

which could crash QEMU when guest writes NVDIMM labels.

Fix it by replacing sizeof(*in) by offsetof(NvdimmDsmIn, arg3).

Thanks!

Reviewed-by on v1 1/1
#2 lore raw
In reply to Haozhong Zhang
Quoted 9 lines · Haozhong Zhang

Commit 35c5a52d "acpi: do not use TARGET_PAGE_SIZE" changed struct NvdimmDsmIn from a variable-size structure to a fixed-size structure of 4096 bytes. It forgot to adjust an assert in nvdimm_dsm_set_label_data(..., NvdimmDsmIn *in, ...):

    assert(sizeof(*in) + sizeof(*set_label_data) + set_label_data->length <=
           4096);

which could crash QEMU when guest writes NVDIMM labels.

Fix it by replacing sizeof(*in) by offsetof(NvdimmDsmIn, arg3).

Thanks for your fix.