Add ptrace(2) backend for NetBSD
Model this code after existing Linux backend and try to keep differences
to minimum.
Features and design choices, compared to the Linux code:
- capstone dependency as a disassembler
- no bfd support
- -D_KERNTYPES for register_t type
- no clone() support
- no disable ASLR switch (personality)
- no libunwind support, there is no port of HP libunwind version
- no hardware assisted profiling aid support
- traditional PT_ATTACH in place of 'seize' operation
- poll(2) detecting of signals, instead of sigtimedwait(2) which
didn't work for unknown reasons
- no cross-ABI support (i386 on amd64 host)
- currently only amd64 and i386 support
Missing or incomplete features are subject for improvement.
Tested with NetBSD/amd64 8.99.23
diff --git a/cmdline.c b/cmdline.c
index 3864242..30abc88 100644
--- a/cmdline.c
+++ b/cmdline.c
@@ -384,6 +384,21 @@
.kernelOnly = false,
.useClone = true,
},
+ /* NetBSD code */
+ .netbsd =
+ {
+ .ignoreAddr = NULL,
+ .numMajorFrames = 7,
+ .pid = 0,
+ .pidFile = NULL,
+ .pidCmd = {},
+ .symsBlFile = NULL,
+ .symsBlCnt = 0,
+ .symsBl = NULL,
+ .symsWlFile = NULL,
+ .symsWlCnt = 0,
+ .symsWl = NULL,
+ },
};
TAILQ_INIT(&hfuzz->io.dynfileq);
@@ -452,6 +467,14 @@
{ { "linux_ns_pid", no_argument, NULL, 0x0531 }, "Use Linux PID namespace isolation" },
{ { "linux_ns_ipc", no_argument, NULL, 0x0532 }, "Use Linux IPC namespace isolation" },
#endif // defined(_HF_ARCH_LINUX)
+
+#if defined(_HF_ARCH_NETBSD)
+ { { "netbsd_symbols_bl", required_argument, NULL, 0x504 }, "Symbols blacklist filter file (one entry per line)" },
+ { { "netbsd_symbols_wl", required_argument, NULL, 0x505 }, "Symbols whitelist filter file (one entry per line)" },
+ { { "netbsd_pid", required_argument, NULL, 'p' }, "Attach to a pid (and its thread group)" },
+ { { "netbsd_file_pid", required_argument, NULL, 0x502 }, "Attach to pid (and its thread group) read from file" },
+ { { "netbsd_addr_low_limit", required_argument, NULL, 0x500 }, "Address limit (from si.si_addr) below which crashes are not reported, (default: 0)" },
+#endif // defined(_HF_ARCH_NETBSD)
{ { 0, 0, 0, 0 }, NULL },
};
// clang-format on
@@ -671,6 +694,17 @@
hfuzz->linux.cloneFlags |= (CLONE_NEWUSER | CLONE_NEWIPC);
break;
#endif /* defined(_HF_ARCH_LINUX) */
+#if defined(_HF_ARCH_NETBSD)
+ case 0x500:
+ hfuzz->netbsd.ignoreAddr = (void*)strtoul(optarg, NULL, 0);
+ break;
+ case 0x504:
+ hfuzz->netbsd.symsBlFile = optarg;
+ break;
+ case 0x505:
+ hfuzz->netbsd.symsWlFile = optarg;
+ break;
+#endif /* defined(_HF_ARCH_NETBSD) */
default:
cmdlineUsage(argv[0], custom_opts);
return false;