cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

fuzz-sdcard-test.c (3289B)


      1/*
      2 * QTest fuzzer-generated testcase for sdcard device
      3 *
      4 * Copyright (c) 2021 Philippe Mathieu-Daudé <f4bug@amsat.org>
      5 *
      6 * SPDX-License-Identifier: GPL-2.0-or-later
      7 */
      8
      9#include "qemu/osdep.h"
     10#include "libqos/libqtest.h"
     11
     12/*
     13 * https://gitlab.com/qemu-project/qemu/-/issues/450
     14 * Used to trigger:
     15 *  Assertion `wpnum < sd->wpgrps_size' failed.
     16 */
     17static void oss_fuzz_29225(void)
     18{
     19    QTestState *s;
     20
     21    s = qtest_init(" -display none -m 512m -nodefaults -nographic"
     22                   " -device sdhci-pci,sd-spec-version=3"
     23                   " -device sd-card,drive=d0"
     24                   " -drive if=none,index=0,file=null-co://,format=raw,id=d0");
     25
     26    qtest_outl(s, 0xcf8, 0x80001010);
     27    qtest_outl(s, 0xcfc, 0xd0690);
     28    qtest_outl(s, 0xcf8, 0x80001003);
     29    qtest_outl(s, 0xcf8, 0x80001013);
     30    qtest_outl(s, 0xcfc, 0xffffffff);
     31    qtest_outl(s, 0xcf8, 0x80001003);
     32    qtest_outl(s, 0xcfc, 0x3effe00);
     33
     34    qtest_bufwrite(s, 0xff0d062c, "\xff", 0x1);
     35    qtest_bufwrite(s, 0xff0d060f, "\xb7", 0x1);
     36    qtest_bufwrite(s, 0xff0d060a, "\xc9", 0x1);
     37    qtest_bufwrite(s, 0xff0d060f, "\x29", 0x1);
     38    qtest_bufwrite(s, 0xff0d060f, "\xc2", 0x1);
     39    qtest_bufwrite(s, 0xff0d0628, "\xf7", 0x1);
     40    qtest_bufwrite(s, 0x0, "\xe3", 0x1);
     41    qtest_bufwrite(s, 0x7, "\x13", 0x1);
     42    qtest_bufwrite(s, 0x8, "\xe3", 0x1);
     43    qtest_bufwrite(s, 0xf, "\xe3", 0x1);
     44    qtest_bufwrite(s, 0xff0d060f, "\x03", 0x1);
     45    qtest_bufwrite(s, 0xff0d0605, "\x01", 0x1);
     46    qtest_bufwrite(s, 0xff0d060b, "\xff", 0x1);
     47    qtest_bufwrite(s, 0xff0d060c, "\xff", 0x1);
     48    qtest_bufwrite(s, 0xff0d060e, "\xff", 0x1);
     49    qtest_bufwrite(s, 0xff0d060f, "\x06", 0x1);
     50    qtest_bufwrite(s, 0xff0d060f, "\x9e", 0x1);
     51
     52    qtest_quit(s);
     53}
     54
     55/*
     56 * https://gitlab.com/qemu-project/qemu/-/issues/495
     57 * Used to trigger:
     58 *  Assertion `wpnum < sd->wpgrps_size' failed.
     59 */
     60static void oss_fuzz_36217(void)
     61{
     62    QTestState *s;
     63
     64    s = qtest_init(" -display none -m 32 -nodefaults -nographic"
     65                   " -device sdhci-pci,sd-spec-version=3 "
     66                   "-device sd-card,drive=d0 "
     67                   "-drive if=none,index=0,file=null-co://,format=raw,id=d0");
     68
     69    qtest_outl(s, 0xcf8, 0x80001010);
     70    qtest_outl(s, 0xcfc, 0xe0000000);
     71    qtest_outl(s, 0xcf8, 0x80001004);
     72    qtest_outw(s, 0xcfc, 0x02);
     73    qtest_bufwrite(s, 0xe000002c, "\x05", 0x1);
     74    qtest_bufwrite(s, 0xe000000f, "\x37", 0x1);
     75    qtest_bufwrite(s, 0xe000000a, "\x01", 0x1);
     76    qtest_bufwrite(s, 0xe000000f, "\x29", 0x1);
     77    qtest_bufwrite(s, 0xe000000f, "\x02", 0x1);
     78    qtest_bufwrite(s, 0xe000000f, "\x03", 0x1);
     79    qtest_bufwrite(s, 0xe0000005, "\x01", 0x1);
     80    qtest_bufwrite(s, 0xe000000f, "\x06", 0x1);
     81    qtest_bufwrite(s, 0xe000000c, "\x05", 0x1);
     82    qtest_bufwrite(s, 0xe000000e, "\x20", 0x1);
     83    qtest_bufwrite(s, 0xe000000f, "\x08", 0x1);
     84    qtest_bufwrite(s, 0xe000000b, "\x3d", 0x1);
     85    qtest_bufwrite(s, 0xe000000f, "\x1e", 0x1);
     86
     87    qtest_quit(s);
     88}
     89
     90int main(int argc, char **argv)
     91{
     92    const char *arch = qtest_get_arch();
     93
     94    g_test_init(&argc, &argv, NULL);
     95
     96   if (strcmp(arch, "i386") == 0) {
     97        qtest_add_func("fuzz/sdcard/oss_fuzz_29225", oss_fuzz_29225);
     98        qtest_add_func("fuzz/sdcard/oss_fuzz_36217", oss_fuzz_36217);
     99   }
    100
    101   return g_test_run();
    102}