aboutsummaryrefslogtreecommitdiff
path: root/tests/megasas-test.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2017-06-01 17:26:14 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2017-06-15 11:04:05 +0200
commit87e459a810d7b1ec1638085b5a80ea3d9b43119a (patch)
tree6c258c88d4560ca42b7a95efdac9de814138382c /tests/megasas-test.c
parentb356807fcdfc45583c437f761fc579ab2a8eab11 (diff)
megasas: always store SCSIRequest* into MegasasCmd
This ensures that the request is unref'ed properly, and avoids a segmentation fault in the new qtest testcase that is added. This is CVE-2017-9503. Reported-by: Zhangyanyu <zyy4013@stu.ouc.edu.cn> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tests/megasas-test.c')
-rw-r--r--tests/megasas-test.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/megasas-test.c b/tests/megasas-test.c
index a9e56a2389..ce960e7f81 100644
--- a/tests/megasas-test.c
+++ b/tests/megasas-test.c
@@ -42,10 +42,45 @@ static void pci_nop(void)
qmegasas_stop(qs);
}
+/* This used to cause a NULL pointer dereference. */
+static void megasas_pd_get_info_fuzz(void)
+{
+ QPCIDevice *dev;
+ QOSState *qs;
+ QPCIBar bar;
+ uint32_t context[256];
+ uint64_t context_pa;
+ int i;
+
+ qs = qmegasas_start(NULL);
+ dev = qpci_device_find(qs->pcibus, QPCI_DEVFN(4,0));
+ g_assert(dev != NULL);
+
+ qpci_device_enable(dev);
+ bar = qpci_iomap(dev, 0, NULL);
+
+ memset(context, 0, sizeof(context));
+ context[0] = cpu_to_le32(0x05050505);
+ context[1] = cpu_to_le32(0x01010101);
+ for (i = 2; i < ARRAY_SIZE(context); i++) {
+ context[i] = cpu_to_le32(0x41414141);
+ }
+ context[6] = cpu_to_le32(0x02020000);
+ context[7] = cpu_to_le32(0);
+
+ context_pa = qmalloc(qs, sizeof(context));
+ memwrite(context_pa, context, sizeof(context));
+ qpci_io_writel(dev, bar, 0x40, context_pa);
+
+ g_free(dev);
+ qmegasas_stop(qs);
+}
+
int main(int argc, char **argv)
{
g_test_init(&argc, &argv, NULL);
qtest_add_func("/megasas/pci/nop", pci_nop);
+ qtest_add_func("/megasas/dcmd/pd-get-info/fuzz", megasas_pd_get_info_fuzz);
return g_test_run();
}