[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
//===- FuzzerUtilFuchsia.cpp - Misc utils for Fuchsia. --------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Misc utils implementation using Fuchsia/Zircon APIs.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-07-15 05:02:32 +08:00
|
|
|
#include "FuzzerPlatform.h"
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
|
|
|
|
#if LIBFUZZER_FUCHSIA
|
|
|
|
|
|
|
|
#include "FuzzerInternal.h"
|
|
|
|
#include "FuzzerUtil.h"
|
2019-05-23 00:36:35 +08:00
|
|
|
#include <cassert>
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
#include <cerrno>
|
|
|
|
#include <cinttypes>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <fcntl.h>
|
2019-10-30 06:38:51 +08:00
|
|
|
#include <lib/fdio/fdio.h>
|
2018-06-08 02:41:35 +08:00
|
|
|
#include <lib/fdio/spawn.h>
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
#include <string>
|
2018-04-20 08:41:06 +08:00
|
|
|
#include <sys/select.h>
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
#include <thread>
|
2018-02-07 16:22:58 +08:00
|
|
|
#include <unistd.h>
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
#include <zircon/errors.h>
|
2018-02-07 16:22:58 +08:00
|
|
|
#include <zircon/process.h>
|
2018-07-19 03:20:47 +08:00
|
|
|
#include <zircon/sanitizer.h>
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
#include <zircon/status.h>
|
|
|
|
#include <zircon/syscalls.h>
|
2018-07-19 03:20:47 +08:00
|
|
|
#include <zircon/syscalls/debug.h>
|
|
|
|
#include <zircon/syscalls/exception.h>
|
2019-06-28 05:13:06 +08:00
|
|
|
#include <zircon/syscalls/object.h>
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
#include <zircon/types.h>
|
|
|
|
|
2020-01-17 09:20:20 +08:00
|
|
|
#include <vector>
|
|
|
|
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
namespace fuzzer {
|
|
|
|
|
2018-07-19 03:20:47 +08:00
|
|
|
// Given that Fuchsia doesn't have the POSIX signals that libFuzzer was written
|
|
|
|
// around, the general approach is to spin up dedicated threads to watch for
|
|
|
|
// each requested condition (alarm, interrupt, crash). Of these, the crash
|
|
|
|
// handler is the most involved, as it requires resuming the crashed thread in
|
|
|
|
// order to invoke the sanitizers to get the needed state.
|
|
|
|
|
|
|
|
// Forward declaration of assembly trampoline needed to resume crashed threads.
|
|
|
|
// This appears to have external linkage to C++, which is why it's not in the
|
|
|
|
// anonymous namespace. The assembly definition inside MakeTrampoline()
|
|
|
|
// actually defines the symbol with internal linkage only.
|
|
|
|
void CrashTrampolineAsm() __asm__("CrashTrampolineAsm");
|
|
|
|
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
namespace {
|
|
|
|
|
[fuzzer][fuchsia] Close exception channel before exiting.
On Fuchsia, killing or exiting a process that has a thread listening to its own process's debugger exception channel can hang. Zircon may kill all the threads, send a synthetic exceptions to debugger, and wait for the debugger to have received them. This means the thread listening to the debug exception channel may be killed even as Zircon is waiting for that thread to drain the exception channel, and the process can become stuck in a half-dead state.
This situation is "weird" as it only arises when a process is trying to debug itself. Unfortunately, this is exactly the scenario for libFuzzer on Fuchsia: FuzzerUtilFuchsia spawns a crash-handling thread that acts like a debugger in order to be able to rewrite the crashed threads stack and resume them into libFuzzer's usual POSIX signal handlers. In practice, approximately 25% of fuzzers appear to hang on exit, after generating output and artifacts. These processes hang around until the platform is torn done, which is typically a ClusterFuzz VM. Thus, real-world impact has been somewhat mitigated. The issue should still be resolved for local users, though.
This change improves the behavior of exit() in libFuzzer by adding an atexit handler which closes an event shared with the crash handling thread. This signals to the crash handler that it should close the exception channel and be joined before the process actually exits.
Reviewed By: charco
Differential Revision: https://reviews.llvm.org/D109258
2021-09-17 02:52:23 +08:00
|
|
|
// The signal handler thread uses Zircon exceptions to resume crashed threads
|
|
|
|
// into libFuzzer's POSIX signal handlers. The associated event is used to
|
|
|
|
// signal when the thread is running, and when it should stop.
|
|
|
|
std::thread SignalHandler;
|
|
|
|
zx_handle_t SignalHandlerEvent = ZX_HANDLE_INVALID;
|
|
|
|
|
2018-07-19 03:20:47 +08:00
|
|
|
// Helper function to handle Zircon syscall failures.
|
|
|
|
void ExitOnErr(zx_status_t Status, const char *Syscall) {
|
|
|
|
if (Status != ZX_OK) {
|
|
|
|
Printf("libFuzzer: %s failed: %s\n", Syscall,
|
|
|
|
_zx_status_get_string(Status));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
void AlarmHandler(int Seconds) {
|
|
|
|
while (true) {
|
|
|
|
SleepSeconds(Seconds);
|
|
|
|
Fuzzer::StaticAlarmCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-19 03:20:47 +08:00
|
|
|
// For the crash handler, we need to call Fuzzer::StaticCrashSignalCallback
|
|
|
|
// without POSIX signal handlers. To achieve this, we use an assembly function
|
|
|
|
// to add the necessary CFI unwinding information and a C function to bridge
|
|
|
|
// from that back into C++.
|
|
|
|
|
|
|
|
// FIXME: This works as a short-term solution, but this code really shouldn't be
|
|
|
|
// architecture dependent. A better long term solution is to implement remote
|
|
|
|
// unwinding and expose the necessary APIs through sanitizer_common and/or ASAN
|
|
|
|
// to allow the exception handling thread to gather the crash state directly.
|
|
|
|
//
|
|
|
|
// Alternatively, Fuchsia may in future actually implement basic signal
|
|
|
|
// handling for the machine trap signals.
|
|
|
|
#if defined(__x86_64__)
|
|
|
|
#define FOREACH_REGISTER(OP_REG, OP_NUM) \
|
|
|
|
OP_REG(rax) \
|
|
|
|
OP_REG(rbx) \
|
|
|
|
OP_REG(rcx) \
|
|
|
|
OP_REG(rdx) \
|
|
|
|
OP_REG(rsi) \
|
|
|
|
OP_REG(rdi) \
|
|
|
|
OP_REG(rbp) \
|
|
|
|
OP_REG(rsp) \
|
|
|
|
OP_REG(r8) \
|
|
|
|
OP_REG(r9) \
|
|
|
|
OP_REG(r10) \
|
|
|
|
OP_REG(r11) \
|
|
|
|
OP_REG(r12) \
|
|
|
|
OP_REG(r13) \
|
|
|
|
OP_REG(r14) \
|
|
|
|
OP_REG(r15) \
|
|
|
|
OP_REG(rip)
|
|
|
|
|
|
|
|
#elif defined(__aarch64__)
|
|
|
|
#define FOREACH_REGISTER(OP_REG, OP_NUM) \
|
|
|
|
OP_NUM(0) \
|
|
|
|
OP_NUM(1) \
|
|
|
|
OP_NUM(2) \
|
|
|
|
OP_NUM(3) \
|
|
|
|
OP_NUM(4) \
|
|
|
|
OP_NUM(5) \
|
|
|
|
OP_NUM(6) \
|
|
|
|
OP_NUM(7) \
|
|
|
|
OP_NUM(8) \
|
|
|
|
OP_NUM(9) \
|
|
|
|
OP_NUM(10) \
|
|
|
|
OP_NUM(11) \
|
|
|
|
OP_NUM(12) \
|
|
|
|
OP_NUM(13) \
|
|
|
|
OP_NUM(14) \
|
|
|
|
OP_NUM(15) \
|
|
|
|
OP_NUM(16) \
|
|
|
|
OP_NUM(17) \
|
|
|
|
OP_NUM(18) \
|
|
|
|
OP_NUM(19) \
|
|
|
|
OP_NUM(20) \
|
|
|
|
OP_NUM(21) \
|
|
|
|
OP_NUM(22) \
|
|
|
|
OP_NUM(23) \
|
|
|
|
OP_NUM(24) \
|
|
|
|
OP_NUM(25) \
|
|
|
|
OP_NUM(26) \
|
|
|
|
OP_NUM(27) \
|
|
|
|
OP_NUM(28) \
|
|
|
|
OP_NUM(29) \
|
|
|
|
OP_REG(sp)
|
|
|
|
|
|
|
|
#else
|
|
|
|
#error "Unsupported architecture for fuzzing on Fuchsia"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Produces a CFI directive for the named or numbered register.
|
[libFuzzer] Fix unwinding for Fuchsia
Summary:
This commit fixes part of the issues with stack unwinding in fuchsia for
arm64 and x86_64. It consists of multiple fixes:
(1) The cfa_offset calculation was wrong, instead of pointing to the
previous stack pointer, it was pointing to the current one. It worked in
most of the cases because the crashing functions already had a
prologue and had their cfa information relative to another register. The
fix consists on adding a constant that can be used to calculate the
crashing function's stack pointer, and base all the cfi information
relative to that offset.
(2) (arm64) Due to errors with the syntax for the dwarf information, most
of the `OP_NUM` macros were not working. The problem was that they were
referred to as `r##NUM` (like `r14`), when it should have been `x##num`
(like `x14`), or even without the x.
(3) (arm64) The link register was being considered a part of the main
registers (`r30`), when in the real struct it has its own field. Given
that the link register is in the same spot in the struct as r[30] would be,
and that C++ doesn't care about anything, the calculation was still correct.
(4) (x86_64) The stack doesn't need to be aligned to 16 bytes when we
jump to the trampoline function, but it needs to be before performing
call instructions. Encoding that logic in cfi information was tricky, so
we decided to make the cfa information relative to `rbp` and align `rsp`.
Note that this could have been done using another register directly,
but it seems cleaner to make a new fake stack frame.
There are some other minor changes like adding a `brk 1` instruction in
arm64 to make sure that we never return to the crash trampoline (similar to
what we do in x86_64).
Sadly this commit does not fix unwinding for all use cases for arm64.
Crashing functions that do not add information related to the return column in
their cfi information will fail to unwind due to a bug in libunwinder.
Reviewers: mcgrathr, jakehehrlich, phosek, kcc, aarongreen
Subscribers: aprantl, kristof.beyls, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D69579
2019-10-29 23:48:46 +08:00
|
|
|
// The value used refers to an assembler immediate operand with the same name
|
|
|
|
// as the register (see ASM_OPERAND_REG).
|
2018-07-19 03:20:47 +08:00
|
|
|
#define CFI_OFFSET_REG(reg) ".cfi_offset " #reg ", %c[" #reg "]\n"
|
[libFuzzer] Fix unwinding for Fuchsia
Summary:
This commit fixes part of the issues with stack unwinding in fuchsia for
arm64 and x86_64. It consists of multiple fixes:
(1) The cfa_offset calculation was wrong, instead of pointing to the
previous stack pointer, it was pointing to the current one. It worked in
most of the cases because the crashing functions already had a
prologue and had their cfa information relative to another register. The
fix consists on adding a constant that can be used to calculate the
crashing function's stack pointer, and base all the cfi information
relative to that offset.
(2) (arm64) Due to errors with the syntax for the dwarf information, most
of the `OP_NUM` macros were not working. The problem was that they were
referred to as `r##NUM` (like `r14`), when it should have been `x##num`
(like `x14`), or even without the x.
(3) (arm64) The link register was being considered a part of the main
registers (`r30`), when in the real struct it has its own field. Given
that the link register is in the same spot in the struct as r[30] would be,
and that C++ doesn't care about anything, the calculation was still correct.
(4) (x86_64) The stack doesn't need to be aligned to 16 bytes when we
jump to the trampoline function, but it needs to be before performing
call instructions. Encoding that logic in cfi information was tricky, so
we decided to make the cfa information relative to `rbp` and align `rsp`.
Note that this could have been done using another register directly,
but it seems cleaner to make a new fake stack frame.
There are some other minor changes like adding a `brk 1` instruction in
arm64 to make sure that we never return to the crash trampoline (similar to
what we do in x86_64).
Sadly this commit does not fix unwinding for all use cases for arm64.
Crashing functions that do not add information related to the return column in
their cfi information will fail to unwind due to a bug in libunwinder.
Reviewers: mcgrathr, jakehehrlich, phosek, kcc, aarongreen
Subscribers: aprantl, kristof.beyls, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D69579
2019-10-29 23:48:46 +08:00
|
|
|
#define CFI_OFFSET_NUM(num) CFI_OFFSET_REG(x##num)
|
2018-07-19 03:20:47 +08:00
|
|
|
|
[libFuzzer] Fix unwinding for Fuchsia
Summary:
This commit fixes part of the issues with stack unwinding in fuchsia for
arm64 and x86_64. It consists of multiple fixes:
(1) The cfa_offset calculation was wrong, instead of pointing to the
previous stack pointer, it was pointing to the current one. It worked in
most of the cases because the crashing functions already had a
prologue and had their cfa information relative to another register. The
fix consists on adding a constant that can be used to calculate the
crashing function's stack pointer, and base all the cfi information
relative to that offset.
(2) (arm64) Due to errors with the syntax for the dwarf information, most
of the `OP_NUM` macros were not working. The problem was that they were
referred to as `r##NUM` (like `r14`), when it should have been `x##num`
(like `x14`), or even without the x.
(3) (arm64) The link register was being considered a part of the main
registers (`r30`), when in the real struct it has its own field. Given
that the link register is in the same spot in the struct as r[30] would be,
and that C++ doesn't care about anything, the calculation was still correct.
(4) (x86_64) The stack doesn't need to be aligned to 16 bytes when we
jump to the trampoline function, but it needs to be before performing
call instructions. Encoding that logic in cfi information was tricky, so
we decided to make the cfa information relative to `rbp` and align `rsp`.
Note that this could have been done using another register directly,
but it seems cleaner to make a new fake stack frame.
There are some other minor changes like adding a `brk 1` instruction in
arm64 to make sure that we never return to the crash trampoline (similar to
what we do in x86_64).
Sadly this commit does not fix unwinding for all use cases for arm64.
Crashing functions that do not add information related to the return column in
their cfi information will fail to unwind due to a bug in libunwinder.
Reviewers: mcgrathr, jakehehrlich, phosek, kcc, aarongreen
Subscribers: aprantl, kristof.beyls, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D69579
2019-10-29 23:48:46 +08:00
|
|
|
// Produces an assembler immediate operand for the named or numbered register.
|
|
|
|
// This operand contains the offset of the register relative to the CFA.
|
2021-07-24 06:54:24 +08:00
|
|
|
#define ASM_OPERAND_REG(reg) \
|
|
|
|
[reg] "i"(offsetof(zx_thread_state_general_regs_t, reg)),
|
|
|
|
#define ASM_OPERAND_NUM(num) \
|
|
|
|
[x##num] "i"(offsetof(zx_thread_state_general_regs_t, r[num])),
|
2018-07-19 03:20:47 +08:00
|
|
|
|
|
|
|
// Trampoline to bridge from the assembly below to the static C++ crash
|
|
|
|
// callback.
|
|
|
|
__attribute__((noreturn))
|
|
|
|
static void StaticCrashHandler() {
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
Fuzzer::StaticCrashSignalCallback();
|
2018-07-19 03:20:47 +08:00
|
|
|
for (;;) {
|
|
|
|
_Exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-24 06:54:24 +08:00
|
|
|
// This trampoline function has the necessary CFI information to unwind
|
|
|
|
// and get a backtrace:
|
|
|
|
// * The stack contains a copy of all the registers at the point of crash,
|
|
|
|
// the code has CFI directives specifying how to restore them.
|
|
|
|
// * A call to StaticCrashHandler, which will print the stacktrace and exit
|
|
|
|
// the fuzzer, generating a crash artifact.
|
[libFuzzer] Fix unwinding for Fuchsia
Summary:
This commit fixes part of the issues with stack unwinding in fuchsia for
arm64 and x86_64. It consists of multiple fixes:
(1) The cfa_offset calculation was wrong, instead of pointing to the
previous stack pointer, it was pointing to the current one. It worked in
most of the cases because the crashing functions already had a
prologue and had their cfa information relative to another register. The
fix consists on adding a constant that can be used to calculate the
crashing function's stack pointer, and base all the cfi information
relative to that offset.
(2) (arm64) Due to errors with the syntax for the dwarf information, most
of the `OP_NUM` macros were not working. The problem was that they were
referred to as `r##NUM` (like `r14`), when it should have been `x##num`
(like `x14`), or even without the x.
(3) (arm64) The link register was being considered a part of the main
registers (`r30`), when in the real struct it has its own field. Given
that the link register is in the same spot in the struct as r[30] would be,
and that C++ doesn't care about anything, the calculation was still correct.
(4) (x86_64) The stack doesn't need to be aligned to 16 bytes when we
jump to the trampoline function, but it needs to be before performing
call instructions. Encoding that logic in cfi information was tricky, so
we decided to make the cfa information relative to `rbp` and align `rsp`.
Note that this could have been done using another register directly,
but it seems cleaner to make a new fake stack frame.
There are some other minor changes like adding a `brk 1` instruction in
arm64 to make sure that we never return to the crash trampoline (similar to
what we do in x86_64).
Sadly this commit does not fix unwinding for all use cases for arm64.
Crashing functions that do not add information related to the return column in
their cfi information will fail to unwind due to a bug in libunwinder.
Reviewers: mcgrathr, jakehehrlich, phosek, kcc, aarongreen
Subscribers: aprantl, kristof.beyls, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D69579
2019-10-29 23:48:46 +08:00
|
|
|
//
|
|
|
|
// The __attribute__((used)) is necessary because the function
|
2018-07-19 03:20:47 +08:00
|
|
|
// is never called; it's just a container around the assembly to allow it to
|
|
|
|
// use operands for compile-time computed constants.
|
|
|
|
__attribute__((used))
|
|
|
|
void MakeTrampoline() {
|
2021-07-24 06:54:24 +08:00
|
|
|
__asm__(
|
|
|
|
".cfi_endproc\n"
|
|
|
|
".pushsection .text.CrashTrampolineAsm\n"
|
|
|
|
".type CrashTrampolineAsm,STT_FUNC\n"
|
|
|
|
"CrashTrampolineAsm:\n"
|
|
|
|
".cfi_startproc simple\n"
|
|
|
|
".cfi_signal_frame\n"
|
2018-07-19 03:20:47 +08:00
|
|
|
#if defined(__x86_64__)
|
2021-07-24 06:54:24 +08:00
|
|
|
".cfi_return_column rip\n"
|
|
|
|
".cfi_def_cfa rsp, 0\n"
|
|
|
|
FOREACH_REGISTER(CFI_OFFSET_REG, CFI_OFFSET_NUM)
|
|
|
|
"call %c[StaticCrashHandler]\n"
|
|
|
|
"ud2\n"
|
2018-07-19 03:20:47 +08:00
|
|
|
#elif defined(__aarch64__)
|
2021-07-24 06:54:24 +08:00
|
|
|
".cfi_return_column 33\n"
|
|
|
|
".cfi_def_cfa sp, 0\n"
|
|
|
|
FOREACH_REGISTER(CFI_OFFSET_REG, CFI_OFFSET_NUM)
|
|
|
|
".cfi_offset 33, %c[pc]\n"
|
|
|
|
".cfi_offset 30, %c[lr]\n"
|
|
|
|
"bl %c[StaticCrashHandler]\n"
|
|
|
|
"brk 1\n"
|
2018-07-19 03:20:47 +08:00
|
|
|
#else
|
|
|
|
#error "Unsupported architecture for fuzzing on Fuchsia"
|
|
|
|
#endif
|
2021-07-24 06:54:24 +08:00
|
|
|
".cfi_endproc\n"
|
|
|
|
".size CrashTrampolineAsm, . - CrashTrampolineAsm\n"
|
|
|
|
".popsection\n"
|
|
|
|
".cfi_startproc\n"
|
|
|
|
: // No outputs
|
|
|
|
: FOREACH_REGISTER(ASM_OPERAND_REG, ASM_OPERAND_NUM)
|
2018-07-19 03:20:47 +08:00
|
|
|
#if defined(__aarch64__)
|
2021-07-24 06:54:24 +08:00
|
|
|
ASM_OPERAND_REG(pc) ASM_OPERAND_REG(lr)
|
2018-07-19 03:20:47 +08:00
|
|
|
#endif
|
2021-07-24 06:54:24 +08:00
|
|
|
[StaticCrashHandler] "i"(StaticCrashHandler));
|
2018-07-19 03:20:47 +08:00
|
|
|
}
|
|
|
|
|
[fuzzer][fuchsia] Close exception channel before exiting.
On Fuchsia, killing or exiting a process that has a thread listening to its own process's debugger exception channel can hang. Zircon may kill all the threads, send a synthetic exceptions to debugger, and wait for the debugger to have received them. This means the thread listening to the debug exception channel may be killed even as Zircon is waiting for that thread to drain the exception channel, and the process can become stuck in a half-dead state.
This situation is "weird" as it only arises when a process is trying to debug itself. Unfortunately, this is exactly the scenario for libFuzzer on Fuchsia: FuzzerUtilFuchsia spawns a crash-handling thread that acts like a debugger in order to be able to rewrite the crashed threads stack and resume them into libFuzzer's usual POSIX signal handlers. In practice, approximately 25% of fuzzers appear to hang on exit, after generating output and artifacts. These processes hang around until the platform is torn done, which is typically a ClusterFuzz VM. Thus, real-world impact has been somewhat mitigated. The issue should still be resolved for local users, though.
This change improves the behavior of exit() in libFuzzer by adding an atexit handler which closes an event shared with the crash handling thread. This signals to the crash handler that it should close the exception channel and be joined before the process actually exits.
Reviewed By: charco
Differential Revision: https://reviews.llvm.org/D109258
2021-09-17 02:52:23 +08:00
|
|
|
void CrashHandler() {
|
|
|
|
assert(SignalHandlerEvent != ZX_HANDLE_INVALID);
|
|
|
|
|
2018-07-19 03:20:47 +08:00
|
|
|
// This structure is used to ensure we close handles to objects we create in
|
|
|
|
// this handler.
|
|
|
|
struct ScopedHandle {
|
|
|
|
~ScopedHandle() { _zx_handle_close(Handle); }
|
|
|
|
zx_handle_t Handle = ZX_HANDLE_INVALID;
|
|
|
|
};
|
|
|
|
|
2019-06-28 05:13:06 +08:00
|
|
|
// Create the exception channel. We need to claim to be a "debugger" so the
|
|
|
|
// kernel will allow us to modify and resume dying threads (see below). Once
|
|
|
|
// the channel is set, we can signal the main thread to continue and wait
|
2018-07-19 03:20:47 +08:00
|
|
|
// for the exception to arrive.
|
2019-06-28 05:13:06 +08:00
|
|
|
ScopedHandle Channel;
|
2018-07-19 03:20:47 +08:00
|
|
|
zx_handle_t Self = _zx_process_self();
|
2019-06-28 05:13:06 +08:00
|
|
|
ExitOnErr(_zx_task_create_exception_channel(
|
|
|
|
Self, ZX_EXCEPTION_CHANNEL_DEBUGGER, &Channel.Handle),
|
|
|
|
"_zx_task_create_exception_channel");
|
2018-07-19 03:20:47 +08:00
|
|
|
|
[fuzzer][fuchsia] Close exception channel before exiting.
On Fuchsia, killing or exiting a process that has a thread listening to its own process's debugger exception channel can hang. Zircon may kill all the threads, send a synthetic exceptions to debugger, and wait for the debugger to have received them. This means the thread listening to the debug exception channel may be killed even as Zircon is waiting for that thread to drain the exception channel, and the process can become stuck in a half-dead state.
This situation is "weird" as it only arises when a process is trying to debug itself. Unfortunately, this is exactly the scenario for libFuzzer on Fuchsia: FuzzerUtilFuchsia spawns a crash-handling thread that acts like a debugger in order to be able to rewrite the crashed threads stack and resume them into libFuzzer's usual POSIX signal handlers. In practice, approximately 25% of fuzzers appear to hang on exit, after generating output and artifacts. These processes hang around until the platform is torn done, which is typically a ClusterFuzz VM. Thus, real-world impact has been somewhat mitigated. The issue should still be resolved for local users, though.
This change improves the behavior of exit() in libFuzzer by adding an atexit handler which closes an event shared with the crash handling thread. This signals to the crash handler that it should close the exception channel and be joined before the process actually exits.
Reviewed By: charco
Differential Revision: https://reviews.llvm.org/D109258
2021-09-17 02:52:23 +08:00
|
|
|
ExitOnErr(_zx_object_signal(SignalHandlerEvent, 0, ZX_USER_SIGNAL_0),
|
2018-07-19 03:20:47 +08:00
|
|
|
"_zx_object_signal");
|
|
|
|
|
2019-05-23 00:36:35 +08:00
|
|
|
// This thread lives as long as the process in order to keep handling
|
|
|
|
// crashes. In practice, the first crashed thread to reach the end of the
|
|
|
|
// StaticCrashHandler will end the process.
|
|
|
|
while (true) {
|
[fuzzer][fuchsia] Close exception channel before exiting.
On Fuchsia, killing or exiting a process that has a thread listening to its own process's debugger exception channel can hang. Zircon may kill all the threads, send a synthetic exceptions to debugger, and wait for the debugger to have received them. This means the thread listening to the debug exception channel may be killed even as Zircon is waiting for that thread to drain the exception channel, and the process can become stuck in a half-dead state.
This situation is "weird" as it only arises when a process is trying to debug itself. Unfortunately, this is exactly the scenario for libFuzzer on Fuchsia: FuzzerUtilFuchsia spawns a crash-handling thread that acts like a debugger in order to be able to rewrite the crashed threads stack and resume them into libFuzzer's usual POSIX signal handlers. In practice, approximately 25% of fuzzers appear to hang on exit, after generating output and artifacts. These processes hang around until the platform is torn done, which is typically a ClusterFuzz VM. Thus, real-world impact has been somewhat mitigated. The issue should still be resolved for local users, though.
This change improves the behavior of exit() in libFuzzer by adding an atexit handler which closes an event shared with the crash handling thread. This signals to the crash handler that it should close the exception channel and be joined before the process actually exits.
Reviewed By: charco
Differential Revision: https://reviews.llvm.org/D109258
2021-09-17 02:52:23 +08:00
|
|
|
zx_wait_item_t WaitItems[] = {
|
|
|
|
{
|
|
|
|
.handle = SignalHandlerEvent,
|
|
|
|
.waitfor = ZX_SIGNAL_HANDLE_CLOSED,
|
|
|
|
.pending = 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.handle = Channel.Handle,
|
|
|
|
.waitfor = ZX_CHANNEL_READABLE | ZX_CHANNEL_PEER_CLOSED,
|
|
|
|
.pending = 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
auto Status = _zx_object_wait_many(
|
|
|
|
WaitItems, sizeof(WaitItems) / sizeof(WaitItems[0]), ZX_TIME_INFINITE);
|
|
|
|
if (Status != ZX_OK || (WaitItems[1].pending & ZX_CHANNEL_READABLE) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2019-06-28 05:13:06 +08:00
|
|
|
|
|
|
|
zx_exception_info_t ExceptionInfo;
|
|
|
|
ScopedHandle Exception;
|
|
|
|
ExitOnErr(_zx_channel_read(Channel.Handle, 0, &ExceptionInfo,
|
|
|
|
&Exception.Handle, sizeof(ExceptionInfo), 1,
|
|
|
|
nullptr, nullptr),
|
|
|
|
"_zx_channel_read");
|
2019-05-23 00:36:35 +08:00
|
|
|
|
|
|
|
// Ignore informational synthetic exceptions.
|
2019-06-28 05:13:06 +08:00
|
|
|
if (ZX_EXCP_THREAD_STARTING == ExceptionInfo.type ||
|
|
|
|
ZX_EXCP_THREAD_EXITING == ExceptionInfo.type ||
|
|
|
|
ZX_EXCP_PROCESS_STARTING == ExceptionInfo.type) {
|
2019-05-23 00:36:35 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At this point, we want to get the state of the crashing thread, but
|
|
|
|
// libFuzzer and the sanitizers assume this will happen from that same
|
|
|
|
// thread via a POSIX signal handler. "Resurrecting" the thread in the
|
|
|
|
// middle of the appropriate callback is as simple as forcibly setting the
|
|
|
|
// instruction pointer/program counter, provided we NEVER EVER return from
|
|
|
|
// that function (since otherwise our stack will not be valid).
|
|
|
|
ScopedHandle Thread;
|
2019-06-28 05:13:06 +08:00
|
|
|
ExitOnErr(_zx_exception_get_thread(Exception.Handle, &Thread.Handle),
|
|
|
|
"_zx_exception_get_thread");
|
2019-05-23 00:36:35 +08:00
|
|
|
|
|
|
|
zx_thread_state_general_regs_t GeneralRegisters;
|
|
|
|
ExitOnErr(_zx_thread_read_state(Thread.Handle, ZX_THREAD_STATE_GENERAL_REGS,
|
|
|
|
&GeneralRegisters,
|
|
|
|
sizeof(GeneralRegisters)),
|
|
|
|
"_zx_thread_read_state");
|
|
|
|
|
|
|
|
// To unwind properly, we need to push the crashing thread's register state
|
|
|
|
// onto the stack and jump into a trampoline with CFI instructions on how
|
|
|
|
// to restore it.
|
2018-07-19 03:20:47 +08:00
|
|
|
#if defined(__x86_64__)
|
2021-07-24 06:54:24 +08:00
|
|
|
uintptr_t StackPtr =
|
|
|
|
(GeneralRegisters.rsp - (128 + sizeof(GeneralRegisters))) &
|
|
|
|
-(uintptr_t)16;
|
2019-05-23 00:36:35 +08:00
|
|
|
__unsanitized_memcpy(reinterpret_cast<void *>(StackPtr), &GeneralRegisters,
|
|
|
|
sizeof(GeneralRegisters));
|
|
|
|
GeneralRegisters.rsp = StackPtr;
|
|
|
|
GeneralRegisters.rip = reinterpret_cast<zx_vaddr_t>(CrashTrampolineAsm);
|
2018-07-19 03:20:47 +08:00
|
|
|
|
|
|
|
#elif defined(__aarch64__)
|
2021-07-24 06:54:24 +08:00
|
|
|
uintptr_t StackPtr =
|
|
|
|
(GeneralRegisters.sp - sizeof(GeneralRegisters)) & -(uintptr_t)16;
|
2019-05-23 00:36:35 +08:00
|
|
|
__unsanitized_memcpy(reinterpret_cast<void *>(StackPtr), &GeneralRegisters,
|
|
|
|
sizeof(GeneralRegisters));
|
|
|
|
GeneralRegisters.sp = StackPtr;
|
|
|
|
GeneralRegisters.pc = reinterpret_cast<zx_vaddr_t>(CrashTrampolineAsm);
|
2018-07-19 03:20:47 +08:00
|
|
|
|
|
|
|
#else
|
|
|
|
#error "Unsupported architecture for fuzzing on Fuchsia"
|
|
|
|
#endif
|
|
|
|
|
2019-05-23 00:36:35 +08:00
|
|
|
// Now force the crashing thread's state.
|
|
|
|
ExitOnErr(
|
|
|
|
_zx_thread_write_state(Thread.Handle, ZX_THREAD_STATE_GENERAL_REGS,
|
|
|
|
&GeneralRegisters, sizeof(GeneralRegisters)),
|
|
|
|
"_zx_thread_write_state");
|
2018-07-19 03:20:47 +08:00
|
|
|
|
2019-06-28 05:13:06 +08:00
|
|
|
// Set the exception to HANDLED so it resumes the thread on close.
|
|
|
|
uint32_t ExceptionState = ZX_EXCEPTION_STATE_HANDLED;
|
|
|
|
ExitOnErr(_zx_object_set_property(Exception.Handle, ZX_PROP_EXCEPTION_STATE,
|
|
|
|
&ExceptionState, sizeof(ExceptionState)),
|
|
|
|
"zx_object_set_property");
|
2019-05-23 00:36:35 +08:00
|
|
|
}
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
}
|
|
|
|
|
[fuzzer][fuchsia] Close exception channel before exiting.
On Fuchsia, killing or exiting a process that has a thread listening to its own process's debugger exception channel can hang. Zircon may kill all the threads, send a synthetic exceptions to debugger, and wait for the debugger to have received them. This means the thread listening to the debug exception channel may be killed even as Zircon is waiting for that thread to drain the exception channel, and the process can become stuck in a half-dead state.
This situation is "weird" as it only arises when a process is trying to debug itself. Unfortunately, this is exactly the scenario for libFuzzer on Fuchsia: FuzzerUtilFuchsia spawns a crash-handling thread that acts like a debugger in order to be able to rewrite the crashed threads stack and resume them into libFuzzer's usual POSIX signal handlers. In practice, approximately 25% of fuzzers appear to hang on exit, after generating output and artifacts. These processes hang around until the platform is torn done, which is typically a ClusterFuzz VM. Thus, real-world impact has been somewhat mitigated. The issue should still be resolved for local users, though.
This change improves the behavior of exit() in libFuzzer by adding an atexit handler which closes an event shared with the crash handling thread. This signals to the crash handler that it should close the exception channel and be joined before the process actually exits.
Reviewed By: charco
Differential Revision: https://reviews.llvm.org/D109258
2021-09-17 02:52:23 +08:00
|
|
|
void StopSignalHandler() {
|
|
|
|
_zx_handle_close(SignalHandlerEvent);
|
|
|
|
if (SignalHandler.joinable()) {
|
|
|
|
SignalHandler.join();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Platform specific functions.
|
|
|
|
void SetSignalHandler(const FuzzingOptions &Options) {
|
2019-09-17 08:34:41 +08:00
|
|
|
// Make sure information from libFuzzer and the sanitizers are easy to
|
|
|
|
// reassemble. `__sanitizer_log_write` has the added benefit of ensuring the
|
|
|
|
// DSO map is always available for the symbolizer.
|
|
|
|
// A uint64_t fits in 20 chars, so 64 is plenty.
|
|
|
|
char Buf[64];
|
|
|
|
memset(Buf, 0, sizeof(Buf));
|
|
|
|
snprintf(Buf, sizeof(Buf), "==%lu== INFO: libFuzzer starting.\n", GetPid());
|
|
|
|
if (EF->__sanitizer_log_write)
|
|
|
|
__sanitizer_log_write(Buf, sizeof(Buf));
|
|
|
|
Printf("%s", Buf);
|
|
|
|
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
// Set up alarm handler if needed.
|
2020-08-12 04:16:08 +08:00
|
|
|
if (Options.HandleAlrm && Options.UnitTimeoutSec > 0) {
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
std::thread T(AlarmHandler, Options.UnitTimeoutSec / 2 + 1);
|
|
|
|
T.detach();
|
|
|
|
}
|
|
|
|
|
2020-10-29 14:47:38 +08:00
|
|
|
// Options.HandleInt and Options.HandleTerm are not supported on Fuchsia
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
|
|
|
|
// Early exit if no crash handler needed.
|
|
|
|
if (!Options.HandleSegv && !Options.HandleBus && !Options.HandleIll &&
|
|
|
|
!Options.HandleFpe && !Options.HandleAbrt)
|
|
|
|
return;
|
|
|
|
|
2018-07-19 03:20:47 +08:00
|
|
|
// Set up the crash handler and wait until it is ready before proceeding.
|
[fuzzer][fuchsia] Close exception channel before exiting.
On Fuchsia, killing or exiting a process that has a thread listening to its own process's debugger exception channel can hang. Zircon may kill all the threads, send a synthetic exceptions to debugger, and wait for the debugger to have received them. This means the thread listening to the debug exception channel may be killed even as Zircon is waiting for that thread to drain the exception channel, and the process can become stuck in a half-dead state.
This situation is "weird" as it only arises when a process is trying to debug itself. Unfortunately, this is exactly the scenario for libFuzzer on Fuchsia: FuzzerUtilFuchsia spawns a crash-handling thread that acts like a debugger in order to be able to rewrite the crashed threads stack and resume them into libFuzzer's usual POSIX signal handlers. In practice, approximately 25% of fuzzers appear to hang on exit, after generating output and artifacts. These processes hang around until the platform is torn done, which is typically a ClusterFuzz VM. Thus, real-world impact has been somewhat mitigated. The issue should still be resolved for local users, though.
This change improves the behavior of exit() in libFuzzer by adding an atexit handler which closes an event shared with the crash handling thread. This signals to the crash handler that it should close the exception channel and be joined before the process actually exits.
Reviewed By: charco
Differential Revision: https://reviews.llvm.org/D109258
2021-09-17 02:52:23 +08:00
|
|
|
ExitOnErr(_zx_event_create(0, &SignalHandlerEvent), "_zx_event_create");
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
|
[fuzzer][fuchsia] Close exception channel before exiting.
On Fuchsia, killing or exiting a process that has a thread listening to its own process's debugger exception channel can hang. Zircon may kill all the threads, send a synthetic exceptions to debugger, and wait for the debugger to have received them. This means the thread listening to the debug exception channel may be killed even as Zircon is waiting for that thread to drain the exception channel, and the process can become stuck in a half-dead state.
This situation is "weird" as it only arises when a process is trying to debug itself. Unfortunately, this is exactly the scenario for libFuzzer on Fuchsia: FuzzerUtilFuchsia spawns a crash-handling thread that acts like a debugger in order to be able to rewrite the crashed threads stack and resume them into libFuzzer's usual POSIX signal handlers. In practice, approximately 25% of fuzzers appear to hang on exit, after generating output and artifacts. These processes hang around until the platform is torn done, which is typically a ClusterFuzz VM. Thus, real-world impact has been somewhat mitigated. The issue should still be resolved for local users, though.
This change improves the behavior of exit() in libFuzzer by adding an atexit handler which closes an event shared with the crash handling thread. This signals to the crash handler that it should close the exception channel and be joined before the process actually exits.
Reviewed By: charco
Differential Revision: https://reviews.llvm.org/D109258
2021-09-17 02:52:23 +08:00
|
|
|
SignalHandler = std::thread(CrashHandler);
|
|
|
|
zx_status_t Status = _zx_object_wait_one(SignalHandlerEvent, ZX_USER_SIGNAL_0,
|
|
|
|
ZX_TIME_INFINITE, nullptr);
|
2018-07-19 03:20:47 +08:00
|
|
|
ExitOnErr(Status, "_zx_object_wait_one");
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
|
[fuzzer][fuchsia] Close exception channel before exiting.
On Fuchsia, killing or exiting a process that has a thread listening to its own process's debugger exception channel can hang. Zircon may kill all the threads, send a synthetic exceptions to debugger, and wait for the debugger to have received them. This means the thread listening to the debug exception channel may be killed even as Zircon is waiting for that thread to drain the exception channel, and the process can become stuck in a half-dead state.
This situation is "weird" as it only arises when a process is trying to debug itself. Unfortunately, this is exactly the scenario for libFuzzer on Fuchsia: FuzzerUtilFuchsia spawns a crash-handling thread that acts like a debugger in order to be able to rewrite the crashed threads stack and resume them into libFuzzer's usual POSIX signal handlers. In practice, approximately 25% of fuzzers appear to hang on exit, after generating output and artifacts. These processes hang around until the platform is torn done, which is typically a ClusterFuzz VM. Thus, real-world impact has been somewhat mitigated. The issue should still be resolved for local users, though.
This change improves the behavior of exit() in libFuzzer by adding an atexit handler which closes an event shared with the crash handling thread. This signals to the crash handler that it should close the exception channel and be joined before the process actually exits.
Reviewed By: charco
Differential Revision: https://reviews.llvm.org/D109258
2021-09-17 02:52:23 +08:00
|
|
|
std::atexit(StopSignalHandler);
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SleepSeconds(int Seconds) {
|
2018-02-07 16:22:58 +08:00
|
|
|
_zx_nanosleep(_zx_deadline_after(ZX_SEC(Seconds)));
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long GetPid() {
|
|
|
|
zx_status_t rc;
|
|
|
|
zx_info_handle_basic_t Info;
|
2018-05-26 09:02:34 +08:00
|
|
|
if ((rc = _zx_object_get_info(_zx_process_self(), ZX_INFO_HANDLE_BASIC, &Info,
|
2018-07-19 03:20:47 +08:00
|
|
|
sizeof(Info), NULL, NULL)) != ZX_OK) {
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
Printf("libFuzzer: unable to get info about self: %s\n",
|
2018-05-26 09:02:34 +08:00
|
|
|
_zx_status_get_string(rc));
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return Info.koid;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GetPeakRSSMb() {
|
|
|
|
zx_status_t rc;
|
|
|
|
zx_info_task_stats_t Info;
|
2018-02-07 16:22:58 +08:00
|
|
|
if ((rc = _zx_object_get_info(_zx_process_self(), ZX_INFO_TASK_STATS, &Info,
|
2018-07-19 03:20:47 +08:00
|
|
|
sizeof(Info), NULL, NULL)) != ZX_OK) {
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
Printf("libFuzzer: unable to get info about self: %s\n",
|
2018-02-07 16:22:58 +08:00
|
|
|
_zx_status_get_string(rc));
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return (Info.mem_private_bytes + Info.mem_shared_bytes) >> 20;
|
|
|
|
}
|
|
|
|
|
2018-02-07 16:22:58 +08:00
|
|
|
template <typename Fn>
|
|
|
|
class RunOnDestruction {
|
|
|
|
public:
|
|
|
|
explicit RunOnDestruction(Fn fn) : fn_(fn) {}
|
|
|
|
~RunOnDestruction() { fn_(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Fn fn_;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Fn>
|
|
|
|
RunOnDestruction<Fn> at_scope_exit(Fn fn) {
|
|
|
|
return RunOnDestruction<Fn>(fn);
|
|
|
|
}
|
|
|
|
|
2020-01-17 09:20:20 +08:00
|
|
|
static fdio_spawn_action_t clone_fd_action(int localFd, int targetFd) {
|
|
|
|
return {
|
|
|
|
.action = FDIO_SPAWN_ACTION_CLONE_FD,
|
|
|
|
.fd =
|
|
|
|
{
|
|
|
|
.local_fd = localFd,
|
|
|
|
.target_fd = targetFd,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
int ExecuteCommand(const Command &Cmd) {
|
|
|
|
zx_status_t rc;
|
|
|
|
|
|
|
|
// Convert arguments to C array
|
|
|
|
auto Args = Cmd.getArguments();
|
|
|
|
size_t Argc = Args.size();
|
|
|
|
assert(Argc != 0);
|
2018-06-02 09:17:10 +08:00
|
|
|
std::unique_ptr<const char *[]> Argv(new const char *[Argc + 1]);
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
for (size_t i = 0; i < Argc; ++i)
|
|
|
|
Argv[i] = Args[i].c_str();
|
2018-06-02 09:17:10 +08:00
|
|
|
Argv[Argc] = nullptr;
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
|
2018-10-03 01:21:04 +08:00
|
|
|
// Determine output. On Fuchsia, the fuzzer is typically run as a component
|
|
|
|
// that lacks a mutable working directory. Fortunately, when this is the case
|
|
|
|
// a mutable output directory must be specified using "-artifact_prefix=...",
|
|
|
|
// so write the log file(s) there.
|
2019-10-12 07:35:13 +08:00
|
|
|
// However, we don't want to apply this logic for absolute paths.
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
int FdOut = STDOUT_FILENO;
|
2020-01-17 09:20:20 +08:00
|
|
|
bool discardStdout = false;
|
|
|
|
bool discardStderr = false;
|
|
|
|
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
if (Cmd.hasOutputFile()) {
|
2019-10-12 07:35:13 +08:00
|
|
|
std::string Path = Cmd.getOutputFile();
|
2020-01-17 09:20:20 +08:00
|
|
|
if (Path == getDevNull()) {
|
|
|
|
// On Fuchsia, there's no "/dev/null" like-file, so we
|
|
|
|
// just don't copy the FDs into the spawned process.
|
|
|
|
discardStdout = true;
|
|
|
|
} else {
|
|
|
|
bool IsAbsolutePath = Path.length() > 1 && Path[0] == '/';
|
|
|
|
if (!IsAbsolutePath && Cmd.hasFlag("artifact_prefix"))
|
|
|
|
Path = Cmd.getFlagValue("artifact_prefix") + "/" + Path;
|
|
|
|
|
|
|
|
FdOut = open(Path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0);
|
|
|
|
if (FdOut == -1) {
|
|
|
|
Printf("libFuzzer: failed to open %s: %s\n", Path.c_str(),
|
|
|
|
strerror(errno));
|
|
|
|
return ZX_ERR_IO;
|
|
|
|
}
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
}
|
|
|
|
}
|
2018-10-03 01:21:04 +08:00
|
|
|
auto CloseFdOut = at_scope_exit([FdOut]() {
|
|
|
|
if (FdOut != STDOUT_FILENO)
|
|
|
|
close(FdOut);
|
|
|
|
});
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
|
|
|
|
// Determine stderr
|
|
|
|
int FdErr = STDERR_FILENO;
|
2020-01-17 09:20:20 +08:00
|
|
|
if (Cmd.isOutAndErrCombined()) {
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
FdErr = FdOut;
|
2020-01-17 09:20:20 +08:00
|
|
|
if (discardStdout)
|
|
|
|
discardStderr = true;
|
|
|
|
}
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
|
|
|
|
// Clone the file descriptors into the new process
|
2020-01-17 09:20:20 +08:00
|
|
|
std::vector<fdio_spawn_action_t> SpawnActions;
|
|
|
|
SpawnActions.push_back(clone_fd_action(STDIN_FILENO, STDIN_FILENO));
|
|
|
|
|
|
|
|
if (!discardStdout)
|
|
|
|
SpawnActions.push_back(clone_fd_action(FdOut, STDOUT_FILENO));
|
|
|
|
if (!discardStderr)
|
|
|
|
SpawnActions.push_back(clone_fd_action(FdErr, STDERR_FILENO));
|
2018-06-02 09:17:10 +08:00
|
|
|
|
|
|
|
// Start the process.
|
|
|
|
char ErrorMsg[FDIO_SPAWN_ERR_MSG_MAX_LENGTH];
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
zx_handle_t ProcessHandle = ZX_HANDLE_INVALID;
|
2020-01-17 09:20:20 +08:00
|
|
|
rc = fdio_spawn_etc(ZX_HANDLE_INVALID,
|
|
|
|
FDIO_SPAWN_CLONE_ALL & (~FDIO_SPAWN_CLONE_STDIO), Argv[0],
|
|
|
|
Argv.get(), nullptr, SpawnActions.size(),
|
|
|
|
SpawnActions.data(), &ProcessHandle, ErrorMsg);
|
|
|
|
|
2018-06-02 09:17:10 +08:00
|
|
|
if (rc != ZX_OK) {
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
Printf("libFuzzer: failed to launch '%s': %s, %s\n", Argv[0], ErrorMsg,
|
2018-02-07 16:22:58 +08:00
|
|
|
_zx_status_get_string(rc));
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
return rc;
|
|
|
|
}
|
2018-02-07 16:22:58 +08:00
|
|
|
auto CloseHandle = at_scope_exit([&]() { _zx_handle_close(ProcessHandle); });
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
|
|
|
|
// Now join the process and return the exit status.
|
2018-02-07 16:22:58 +08:00
|
|
|
if ((rc = _zx_object_wait_one(ProcessHandle, ZX_PROCESS_TERMINATED,
|
2018-08-28 01:51:52 +08:00
|
|
|
ZX_TIME_INFINITE, nullptr)) != ZX_OK) {
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
Printf("libFuzzer: failed to join '%s': %s\n", Argv[0],
|
2018-02-07 16:22:58 +08:00
|
|
|
_zx_status_get_string(rc));
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
zx_info_process_t Info;
|
2018-02-07 16:22:58 +08:00
|
|
|
if ((rc = _zx_object_get_info(ProcessHandle, ZX_INFO_PROCESS, &Info,
|
|
|
|
sizeof(Info), nullptr, nullptr)) != ZX_OK) {
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
Printf("libFuzzer: unable to get return code from '%s': %s\n", Argv[0],
|
2018-05-26 09:02:34 +08:00
|
|
|
_zx_status_get_string(rc));
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
[crt][fuzzer] Fix up various numeric conversions
Attempting to build a standalone libFuzzer in Fuchsia's default toolchain for the purpose of cross-compiling the unit tests revealed a number of not-quite-proper type conversions. Fuchsia's toolchain include `-std=c++17` and `-Werror`, among others, leading to many errors like `-Wshorten-64-to-32`, `-Wimplicit-float-conversion`, etc.
Most of these have been addressed by simply making the conversion explicit with a `static_cast`. These typically fell into one of two categories: 1) conversions between types where high precision isn't critical, e.g. the "energy" calculations for `InputInfo`, and 2) conversions where the values will never reach the bits being truncated, e.g. `DftTimeInSeconds` is not going to exceed 136 years.
The major exception to this is the number of features: there are several places that treat features as `size_t`, and others as `uint32_t`. This change makes the decision to cap the features at 32 bits. The maximum value of a feature as produced by `TracePC::CollectFeatures` is roughly:
(NumPCsInPCTables + ValueBitMap::kMapSizeInBits + ExtraCountersBegin() - ExtraCountersEnd() + log2(SIZE_MAX)) * 8
It's conceivable for extremely large targets and/or extra counters that this limit could be reached. This shouldn't break fuzzing, but it will cause certain features to collide and lower the fuzzers overall precision. To address this, this change adds a warning to TracePC::PrintModuleInfo about excessive feature size if it is detected, and recommends refactoring the fuzzer into several smaller ones.
Reviewed By: morehouse
Differential Revision: https://reviews.llvm.org/D97992
2021-03-12 08:00:53 +08:00
|
|
|
return static_cast<int>(Info.return_code);
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
}
|
|
|
|
|
2020-02-13 07:43:44 +08:00
|
|
|
bool ExecuteCommand(const Command &BaseCmd, std::string *CmdOutput) {
|
|
|
|
auto LogFilePath = TempPath("SimPopenOut", ".txt");
|
|
|
|
Command Cmd(BaseCmd);
|
|
|
|
Cmd.setOutputFile(LogFilePath);
|
|
|
|
int Ret = ExecuteCommand(Cmd);
|
|
|
|
*CmdOutput = FileToString(LogFilePath);
|
|
|
|
RemoveFile(LogFilePath);
|
|
|
|
return Ret == 0;
|
|
|
|
}
|
|
|
|
|
2021-07-03 00:44:54 +08:00
|
|
|
const void *SearchMemory(const void *Data, size_t DataLen, const void *Patt,
|
|
|
|
size_t PattLen) {
|
|
|
|
return memmem(Data, DataLen, Patt, PattLen);
|
|
|
|
}
|
|
|
|
|
2019-10-30 06:38:51 +08:00
|
|
|
// In fuchsia, accessing /dev/null is not supported. There's nothing
|
|
|
|
// similar to a file that discards everything that is written to it.
|
|
|
|
// The way of doing something similar in fuchsia is by using
|
|
|
|
// fdio_null_create and binding that to a file descriptor.
|
|
|
|
void DiscardOutput(int Fd) {
|
|
|
|
fdio_t *fdio_null = fdio_null_create();
|
|
|
|
if (fdio_null == nullptr) return;
|
|
|
|
int nullfd = fdio_bind_to_fd(fdio_null, -1, 0);
|
|
|
|
if (nullfd < 0) return;
|
|
|
|
dup2(nullfd, Fd);
|
|
|
|
}
|
|
|
|
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
} // namespace fuzzer
|
|
|
|
|
|
|
|
#endif // LIBFUZZER_FUCHSIA
|