mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-10 02:54:58 -06:00
hw/scsi/lsi53c895a: Fix reentrancy issues in the LSI controller (CVE-2023-0330)
We cannot use the generic reentrancy guard in the LSI code, so we have to manually prevent endless reentrancy here. The problematic lsi_execute_script() function has already a way to detect whether too many instructions have been executed - we just have to slightly change the logic here that it also takes into account if the function has been called too often in a reentrant way. The code in fuzz-lsi53c895a-test.c has been taken from an earlier patch by Mauro Matteo Cascella. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1563 Message-Id: <20230522091011.1082574-1-thuth@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Alexander Bulekov <alxndr@bu.edu> Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
parent
d139fe9ad8
commit
b987718bbb
2 changed files with 50 additions and 6 deletions
|
@ -8,6 +8,36 @@
|
|||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
/*
|
||||
* This used to trigger a DMA reentrancy issue
|
||||
* leading to memory corruption bugs like stack
|
||||
* overflow or use-after-free
|
||||
* https://gitlab.com/qemu-project/qemu/-/issues/1563
|
||||
*/
|
||||
static void test_lsi_dma_reentrancy(void)
|
||||
{
|
||||
QTestState *s;
|
||||
|
||||
s = qtest_init("-M q35 -m 512M -nodefaults "
|
||||
"-blockdev driver=null-co,node-name=null0 "
|
||||
"-device lsi53c810 -device scsi-cd,drive=null0");
|
||||
|
||||
qtest_outl(s, 0xcf8, 0x80000804); /* PCI Command Register */
|
||||
qtest_outw(s, 0xcfc, 0x7); /* Enables accesses */
|
||||
qtest_outl(s, 0xcf8, 0x80000814); /* Memory Bar 1 */
|
||||
qtest_outl(s, 0xcfc, 0xff100000); /* Set MMIO Address*/
|
||||
qtest_outl(s, 0xcf8, 0x80000818); /* Memory Bar 2 */
|
||||
qtest_outl(s, 0xcfc, 0xff000000); /* Set RAM Address*/
|
||||
qtest_writel(s, 0xff000000, 0xc0000024);
|
||||
qtest_writel(s, 0xff000114, 0x00000080);
|
||||
qtest_writel(s, 0xff00012c, 0xff000000);
|
||||
qtest_writel(s, 0xff000004, 0xff000114);
|
||||
qtest_writel(s, 0xff000008, 0xff100014);
|
||||
qtest_writel(s, 0xff10002f, 0x000000ff);
|
||||
|
||||
qtest_quit(s);
|
||||
}
|
||||
|
||||
/*
|
||||
* This used to trigger a UAF in lsi_do_msgout()
|
||||
* https://gitlab.com/qemu-project/qemu/-/issues/972
|
||||
|
@ -124,5 +154,8 @@ int main(int argc, char **argv)
|
|||
qtest_add_func("fuzz/lsi53c895a/lsi_do_msgout_cancel_req",
|
||||
test_lsi_do_msgout_cancel_req);
|
||||
|
||||
qtest_add_func("fuzz/lsi53c895a/lsi_dma_reentrancy",
|
||||
test_lsi_dma_reentrancy);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue