omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / om / tls / test / fuzz / oss-fuzz / omexec_fuzzer.c
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // HOST TOOLING, not part of the Omega library: a libFuzzer entry point that runs one compiled |
| 3 | // om/tls fuzz target (aarch64, under qemu-aarch64-static on the amd64 OSS-Fuzz/ClusterFuzzLite |
| 4 | // builders) on the input and aborts when the target exits >= 100 (an Omega trap), so the |
| 5 | // infrastructure records it as a crash. libFuzzer sees coverage of this driver only, not of the |
| 6 | // .om code: under this driver the campaign is black-box (stated in NOTES and the PR). |
| 7 | // Driver $OUT/fz_X runs $OUT/fz_X.om.bin with argument $OUT/fz_X.arg's content (if present). |
| 8 | #include <fcntl.h> |
| 9 | #include <stdint.h> |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | #include <sys/wait.h> |
| 14 | #include <unistd.h> |
| 15 | |
| 16 | static char tgt[4096], arg[4096]; |
| 17 | |
| 18 | int LLVMFuzzerInitialize(int *argc, char ***argv) { |
| 19 | snprintf(tgt, sizeof tgt, "%s.om.bin", (*argv)[0]); |
| 20 | char af[4096]; |
| 21 | snprintf(af, sizeof af, "%s.arg", (*argv)[0]); |
| 22 | FILE *f = fopen(af, "r"); |
| 23 | if (f) { |
| 24 | if (fgets(arg, sizeof arg, f)) arg[strcspn(arg, "\n")] = 0; |
| 25 | fclose(f); |
| 26 | } |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 31 | int p[2]; |
| 32 | if (pipe(p)) abort(); |
| 33 | pid_t pid = fork(); |
| 34 | if (pid == 0) { |
| 35 | dup2(p[0], 0); close(p[0]); close(p[1]); |
| 36 | int n = open("/dev/null", O_WRONLY); dup2(n, 1); dup2(n, 2); |
| 37 | if (arg[0]) execl("/usr/bin/qemu-aarch64-static", "qemu-aarch64-static", tgt, arg, (char *)0); |
| 38 | else execl("/usr/bin/qemu-aarch64-static", "qemu-aarch64-static", tgt, (char *)0); |
| 39 | _exit(127); |
| 40 | } |
| 41 | close(p[0]); |
| 42 | for (size_t o = 0; o < size;) { ssize_t w = write(p[1], data + o, size - o); if (w <= 0) break; o += (size_t)w; } |
| 43 | close(p[1]); |
| 44 | int st = 0; |
| 45 | waitpid(pid, &st, 0); |
| 46 | if (WIFSIGNALED(st) || (WIFEXITED(st) && WEXITSTATUS(st) >= 100 && WEXITSTATUS(st) != 127)) abort(); |
| 47 | return 0; |
| 48 | } |