Loading trusty/fuzz/include/trusty/fuzz/utils.h +1 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ class TrustyApp { android::base::Result<void> Connect(); android::base::Result<void> Read(void* buf, size_t len); android::base::Result<void> Write(const void* buf, size_t len); void Disconnect(); android::base::Result<int> GetRawFd(); Loading trusty/fuzz/tipc_fuzzer.cpp +11 −15 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ using android::trusty::fuzz::TrustyApp; #error "Binary file name must be parameterized using -DTRUSTY_APP_FILENAME." #endif static TrustyApp kTrustyApp(TIPC_DEV, TRUSTY_APP_PORT); static std::unique_ptr<CoverageRecord> record; extern "C" int LLVMFuzzerInitialize(int* /* argc */, char*** /* argv */) { Loading @@ -52,8 +53,7 @@ extern "C" int LLVMFuzzerInitialize(int* /* argc */, char*** /* argv */) { } /* Make sure lazy-loaded TAs have started and connected to coverage service. */ TrustyApp ta(TIPC_DEV, TRUSTY_APP_PORT); auto ret = ta.Connect(); auto ret = kTrustyApp.Connect(); if (!ret.ok()) { std::cerr << ret.error() << std::endl; exit(-1); Loading @@ -79,22 +79,18 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { ExtraCounters counters(record.get()); counters.Reset(); TrustyApp ta(TIPC_DEV, TRUSTY_APP_PORT); auto ret = ta.Connect(); if (!ret.ok()) { std::cerr << ret.error() << std::endl; android::trusty::fuzz::Abort(); auto ret = kTrustyApp.Write(data, size); if (ret.ok()) { ret = kTrustyApp.Read(&buf, sizeof(buf)); } ret = ta.Write(data, size); // Reconnect to ensure that the service is still up kTrustyApp.Disconnect(); ret = kTrustyApp.Connect(); if (!ret.ok()) { return -1; } ret = ta.Read(&buf, sizeof(buf)); if (!ret.ok()) { return -1; std::cerr << ret.error() << std::endl; android::trusty::fuzz::Abort(); } return 0; return ret.ok() ? 0 : -1; } trusty/fuzz/utils.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -127,6 +127,10 @@ Result<int> TrustyApp::GetRawFd() { return ta_fd_; } void TrustyApp::Disconnect() { ta_fd_.reset(); } void Abort() { PrintTrustyLog(); exit(-1); Loading Loading
trusty/fuzz/include/trusty/fuzz/utils.h +1 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ class TrustyApp { android::base::Result<void> Connect(); android::base::Result<void> Read(void* buf, size_t len); android::base::Result<void> Write(const void* buf, size_t len); void Disconnect(); android::base::Result<int> GetRawFd(); Loading
trusty/fuzz/tipc_fuzzer.cpp +11 −15 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ using android::trusty::fuzz::TrustyApp; #error "Binary file name must be parameterized using -DTRUSTY_APP_FILENAME." #endif static TrustyApp kTrustyApp(TIPC_DEV, TRUSTY_APP_PORT); static std::unique_ptr<CoverageRecord> record; extern "C" int LLVMFuzzerInitialize(int* /* argc */, char*** /* argv */) { Loading @@ -52,8 +53,7 @@ extern "C" int LLVMFuzzerInitialize(int* /* argc */, char*** /* argv */) { } /* Make sure lazy-loaded TAs have started and connected to coverage service. */ TrustyApp ta(TIPC_DEV, TRUSTY_APP_PORT); auto ret = ta.Connect(); auto ret = kTrustyApp.Connect(); if (!ret.ok()) { std::cerr << ret.error() << std::endl; exit(-1); Loading @@ -79,22 +79,18 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { ExtraCounters counters(record.get()); counters.Reset(); TrustyApp ta(TIPC_DEV, TRUSTY_APP_PORT); auto ret = ta.Connect(); if (!ret.ok()) { std::cerr << ret.error() << std::endl; android::trusty::fuzz::Abort(); auto ret = kTrustyApp.Write(data, size); if (ret.ok()) { ret = kTrustyApp.Read(&buf, sizeof(buf)); } ret = ta.Write(data, size); // Reconnect to ensure that the service is still up kTrustyApp.Disconnect(); ret = kTrustyApp.Connect(); if (!ret.ok()) { return -1; } ret = ta.Read(&buf, sizeof(buf)); if (!ret.ok()) { return -1; std::cerr << ret.error() << std::endl; android::trusty::fuzz::Abort(); } return 0; return ret.ok() ? 0 : -1; }
trusty/fuzz/utils.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -127,6 +127,10 @@ Result<int> TrustyApp::GetRawFd() { return ta_fd_; } void TrustyApp::Disconnect() { ta_fd_.reset(); } void Abort() { PrintTrustyLog(); exit(-1); Loading