aboutsummaryrefslogtreecommitdiffstats
path: root/tools/android
diff options
context:
space:
mode:
authorZach Riggle <riggle@google.com>2018-10-11 16:01:25 -0500
committerDmitry Vyukov <dvyukov@google.com>2018-10-12 16:39:26 +0200
commitcaf12900683e434dcd16bdac59b909f13fb09099 (patch)
tree95f376cf9cba7a65831072fee8ff8a8dddf7a8a9 /tools/android
parent751b7baf9499cf287eaaa58e0978e377fa651015 (diff)
Android: Add simple test harness for Sandbox
Diffstat (limited to 'tools/android')
-rw-r--r--tools/android/Makefile18
-rw-r--r--tools/android/jni/Android.mk8
-rw-r--r--tools/android/jni/Application.mk5
-rw-r--r--tools/android/jni/sandbox_test.c43
4 files changed, 74 insertions, 0 deletions
diff --git a/tools/android/Makefile b/tools/android/Makefile
new file mode 100644
index 000000000..556868f97
--- /dev/null
+++ b/tools/android/Makefile
@@ -0,0 +1,18 @@
+TARGET := libs/arm64-v8a/sandbox_test
+SRC := jni/sandbox_test.c
+
+all: $(TARGET)
+
+$(TARGET): $(SRC)
+ ndk-build
+
+push: $(TARGET)
+ adb push "$^" /data/local/tmp
+
+run: push
+ adb shell /data/local/tmp/sandbox_test
+
+clean:
+ rm -rf libs obj
+
+.PHONY: all push run
diff --git a/tools/android/jni/Android.mk b/tools/android/jni/Android.mk
new file mode 100644
index 000000000..d7c4a2901
--- /dev/null
+++ b/tools/android/jni/Android.mk
@@ -0,0 +1,8 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := sandbox_test
+LOCAL_SRC_FILES := sandbox_test.c
+LOCAL_C_INCLUDES := ../../
+
+include $(BUILD_EXECUTABLE)
diff --git a/tools/android/jni/Application.mk b/tools/android/jni/Application.mk
new file mode 100644
index 000000000..59fa1a575
--- /dev/null
+++ b/tools/android/jni/Application.mk
@@ -0,0 +1,5 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+APP_ABI:= arm64-v8a
+APP_PLATFORM:=latest
diff --git a/tools/android/jni/sandbox_test.c b/tools/android/jni/sandbox_test.c
new file mode 100644
index 000000000..467ba3313
--- /dev/null
+++ b/tools/android/jni/sandbox_test.c
@@ -0,0 +1,43 @@
+#define GOOS_linux 1
+#define SYZ_SANDBOX_ANDROID_UNTRUSTED_APP 1
+#define SYZ_USE_TMP_DIR 1
+#define fail(...) do { dprintf(2, __VA_ARGS__); dprintf(2, "\n"); perror("errno"); exit(1); } while(0)
+#define error(...) do { dprintf(2, __VA_ARGS__); } while(0)
+#define debug(...) do { dprintf(2, __VA_ARGS__); } while(0)
+
+#include <stdlib.h>
+#include <string.h>
+
+void doexit(int status)
+{
+ exit(status);
+}
+
+static void loop() {
+ exit(system("id"));
+}
+
+static void use_temporary_dir(void)
+{
+#if SYZ_SANDBOX_ANDROID_UNTRUSTED_APP
+ char tmpdir_template[] = "/data/data/syzkaller/syzkaller.XXXXXX";
+#else
+ char tmpdir_template[] = "./syzkaller.XXXXXX";
+#endif
+ char* tmpdir = mkdtemp(tmpdir_template);
+ if (!tmpdir)
+ fail("failed to mkdtemp");
+ if (chmod(tmpdir, 0777))
+ fail("failed to chmod");
+ if (chdir(tmpdir))
+ fail("failed to chdir");
+}
+
+
+
+#include "executor/common_linux.h"
+
+int main() {
+ use_temporary_dir();
+ do_sandbox_android_untrusted_app();
+}