From 421de905446320b6f724a930238371cbefdae789 Mon Sep 17 00:00:00 2001 From: Tri Vo Date: Wed, 18 Nov 2020 12:17:14 -0800 Subject: [PATCH 1/2] trusty: Add libtrusty_test Used by tests on the system side of the Treble boundary, e.g. fuzzing Test: m libtrusty libtrusty_test Change-Id: I56a15c80eb7c4b9e51f8e59a7cd1abdfc35d8d5a --- trusty/libtrusty/Android.bp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/trusty/libtrusty/Android.bp b/trusty/libtrusty/Android.bp index 8dba78d91..708fdbdb5 100644 --- a/trusty/libtrusty/Android.bp +++ b/trusty/libtrusty/Android.bp @@ -12,10 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -cc_library { - name: "libtrusty", - vendor: true, - +cc_defaults { + name: "libtrusty_defaults", srcs: ["trusty.c"], export_include_dirs: ["include"], cflags: [ @@ -25,3 +23,16 @@ cc_library { shared_libs: ["liblog"], } + +cc_library { + name: "libtrusty", + vendor: true, + defaults: ["libtrusty_defaults"], +} + +// TODO(b/170753563): cc_fuzz can't deal with vendor components. Build libtrusty +// for system. +cc_test_library { + name: "libtrusty_test", + defaults: ["libtrusty_defaults"], +} From 90c0e833c9b5e510ea4d7b2786cf190490550f4e Mon Sep 17 00:00:00 2001 From: Tri Vo Date: Wed, 18 Nov 2020 16:17:09 -0800 Subject: [PATCH 2/2] trusty: fuzz: make utils lib use libtrusty_test Test: m libtrusty_fuzz_utils Change-Id: Id77b87bb14f09b29f53c78a4ea89073fbe1c83a1 --- trusty/fuzz/Android.bp | 5 ++--- trusty/fuzz/utils.cpp | 19 ++----------------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/trusty/fuzz/Android.bp b/trusty/fuzz/Android.bp index 969431ce2..ac49751ea 100644 --- a/trusty/fuzz/Android.bp +++ b/trusty/fuzz/Android.bp @@ -14,10 +14,8 @@ cc_defaults { name: "trusty_fuzzer_defaults", - static_libs: [ - "libtrusty_fuzz_utils", - ], shared_libs: [ + "libtrusty_fuzz_utils", "libbase", "liblog", ], @@ -36,6 +34,7 @@ cc_library { srcs: ["utils.cpp"], export_include_dirs: ["include"], shared_libs: [ + "libtrusty_test", "libbase", "liblog", ], diff --git a/trusty/fuzz/utils.cpp b/trusty/fuzz/utils.cpp index 240afe705..f4cf0b612 100644 --- a/trusty/fuzz/utils.cpp +++ b/trusty/fuzz/utils.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include using android::base::ErrnoError; @@ -32,9 +33,6 @@ using android::base::Error; using android::base::Result; using android::base::unique_fd; -#define TIPC_IOC_MAGIC 'r' -#define TIPC_IOC_CONNECT _IOW(TIPC_IOC_MAGIC, 0x80, char*) - namespace { const size_t kTimeoutSeconds = 5; @@ -80,27 +78,14 @@ TrustyApp::TrustyApp(std::string tipc_dev, std::string ta_port) : tipc_dev_(tipc_dev), ta_port_(ta_port), ta_fd_(-1) {} Result TrustyApp::Connect() { - /* - * TODO: We can't use libtrusty because (yet) - * (1) cc_fuzz can't deal with vendor components (b/170753563) - * (2) We need non-blocking behavior to detect Trusty going down. - * (we could implement the timeout in the fuzzing code though, as - * it needs to be around the call to read()) - */ alarm(kTimeoutSeconds); - int fd = open(tipc_dev_.c_str(), O_RDWR); + int fd = tipc_connect(tipc_dev_.c_str(), ta_port_.c_str()); alarm(0); if (fd < 0) { return ErrnoError() << "failed to open TIPC device: "; } ta_fd_.reset(fd); - // This ioctl will time out in the kernel if it can't connect. - int rc = TEMP_FAILURE_RETRY(ioctl(ta_fd_, TIPC_IOC_CONNECT, ta_port_.c_str())); - if (rc < 0) { - return ErrnoError() << "failed to connect to TIPC service: "; - } - return {}; }