1 /* 2 * QTest fuzzer-generated testcase for megasas device 3 * 4 * Copyright (c) 2020 Li Qiang <liq3ea@gmail.com> 5 * 6 * This work is licensed under the terms of the GNU GPL, version 2 or later. 7 * See the COPYING file in the top-level directory. 8 */ 9 10 #include "qemu/osdep.h" 11 12 #include "libqtest.h" 13 14 /* 15 * This used to trigger the assert in scsi_dma_complete 16 * https://bugs.launchpad.net/qemu/+bug/1878263 17 */ 18 static void test_lp1878263_megasas_zero_iov_cnt(void) 19 { 20 QTestState *s; 21 22 s = qtest_init("-nographic -monitor none -serial none " 23 "-M q35 -device megasas -device scsi-cd,drive=null0 " 24 "-blockdev driver=null-co,read-zeroes=on,node-name=null0"); 25 qtest_outl(s, 0xcf8, 0x80001818); 26 qtest_outl(s, 0xcfc, 0xc101); 27 qtest_outl(s, 0xcf8, 0x8000181c); 28 qtest_outl(s, 0xcf8, 0x80001804); 29 qtest_outw(s, 0xcfc, 0x7); 30 qtest_outl(s, 0xcf8, 0x8000186a); 31 qtest_writeb(s, 0x14, 0xfe); 32 qtest_writeb(s, 0x0, 0x02); 33 qtest_outb(s, 0xc1c0, 0x17); 34 qtest_quit(s); 35 } 36 37 /* 38 * Overflow SGL buffer. 39 * https://gitlab.com/qemu-project/qemu/-/issues/521 40 */ 41 static void test_gitlab_issue521_megasas_sgl_ovf(void) 42 { 43 QTestState *s = qtest_init("-display none -m 32M -machine q35 " 44 "-nodefaults -device megasas " 45 "-device scsi-cd,drive=null0 " 46 "-blockdev " 47 "driver=null-co,read-zeroes=on,node-name=null0"); 48 qtest_outl(s, 0xcf8, 0x80000818); 49 qtest_outl(s, 0xcfc, 0xc000); 50 qtest_outl(s, 0xcf8, 0x80000804); 51 qtest_outw(s, 0xcfc, 0x05); 52 qtest_bufwrite(s, 0x0, "\x01", 0x1); 53 qtest_bufwrite(s, 0x7, "\x01", 0x1); 54 qtest_bufwrite(s, 0x10, "\x02", 0x1); 55 qtest_bufwrite(s, 0x16, "\x01", 0x1); 56 qtest_bufwrite(s, 0x28, "\x01", 0x1); 57 qtest_bufwrite(s, 0x33, "\x01", 0x1); 58 qtest_outb(s, 0xc040, 0x0); 59 qtest_outb(s, 0xc040, 0x20); 60 qtest_outl(s, 0xc040, 0x20000000); 61 qtest_outb(s, 0xc040, 0x20); 62 qtest_quit(s); 63 } 64 65 int main(int argc, char **argv) 66 { 67 g_test_init(&argc, &argv, NULL); 68 69 qtest_add_func("fuzz/test_lp1878263_megasas_zero_iov_cnt", 70 test_lp1878263_megasas_zero_iov_cnt); 71 qtest_add_func("fuzz/gitlab_issue521_megasas_sgl_ovf", 72 test_gitlab_issue521_megasas_sgl_ovf); 73 74 return g_test_run(); 75 } 76