|
32 | 32 | /* TODO actually test the results and get rid of this */
|
33 | 33 | #define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__))
|
34 | 34 |
|
| 35 | +#define DRIVE_FLOPPY_BLANK \ |
| 36 | + "-drive if=floppy,file=null-co://,file.read-zeroes=on,format=raw,size=1440k" |
| 37 | + |
35 | 38 | #define TEST_IMAGE_SIZE 1440 * 1024
|
36 | 39 |
|
37 | 40 | #define FLOPPY_BASE 0x3f0
|
@@ -546,6 +549,40 @@ static void fuzz_registers(void)
|
546 | 549 | }
|
547 | 550 | }
|
548 | 551 |
|
| 552 | +static bool qtest_check_clang_sanitizer(void) |
| 553 | +{ |
| 554 | +#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer) |
| 555 | + return true; |
| 556 | +#else |
| 557 | + g_test_skip("QEMU not configured using --enable-sanitizers"); |
| 558 | + return false; |
| 559 | +#endif |
| 560 | +} |
| 561 | +static void test_cve_2021_20196(void) |
| 562 | +{ |
| 563 | + QTestState *s; |
| 564 | + |
| 565 | + if (!qtest_check_clang_sanitizer()) { |
| 566 | + return; |
| 567 | + } |
| 568 | + |
| 569 | + s = qtest_initf("-nographic -m 32M -nodefaults " DRIVE_FLOPPY_BLANK); |
| 570 | + |
| 571 | + qtest_outw(s, 0x3f4, 0x0500); |
| 572 | + qtest_outb(s, 0x3f5, 0x00); |
| 573 | + qtest_outb(s, 0x3f5, 0x00); |
| 574 | + qtest_outw(s, 0x3f4, 0x0000); |
| 575 | + qtest_outb(s, 0x3f5, 0x00); |
| 576 | + qtest_outw(s, 0x3f1, 0x0400); |
| 577 | + qtest_outw(s, 0x3f4, 0x0000); |
| 578 | + qtest_outw(s, 0x3f4, 0x0000); |
| 579 | + qtest_outb(s, 0x3f5, 0x00); |
| 580 | + qtest_outb(s, 0x3f5, 0x01); |
| 581 | + qtest_outw(s, 0x3f1, 0x0500); |
| 582 | + qtest_outb(s, 0x3f5, 0x00); |
| 583 | + qtest_quit(s); |
| 584 | +} |
| 585 | + |
549 | 586 | int main(int argc, char **argv)
|
550 | 587 | {
|
551 | 588 | int fd;
|
@@ -576,6 +613,7 @@ int main(int argc, char **argv)
|
576 | 613 | qtest_add_func("/fdc/read_no_dma_18", test_read_no_dma_18);
|
577 | 614 | qtest_add_func("/fdc/read_no_dma_19", test_read_no_dma_19);
|
578 | 615 | qtest_add_func("/fdc/fuzz-registers", fuzz_registers);
|
| 616 | + qtest_add_func("/fdc/fuzz/cve_2021_20196", test_cve_2021_20196); |
579 | 617 |
|
580 | 618 | ret = g_test_run();
|
581 | 619 |
|
|
0 commit comments