CTS/STS test for Android Security b/62058746

Bug: 62058746
Change-Id: I955199e4e94b46d6677f8e1b9f4c98c470078156
diff --git a/hostsidetests/security/AndroidTest.xml b/hostsidetests/security/AndroidTest.xml
index 1638efc..4695c28 100644
--- a/hostsidetests/security/AndroidTest.xml
+++ b/hostsidetests/security/AndroidTest.xml
@@ -127,6 +127,13 @@
         <option name="push" value="Bug-35644812->/data/local/tmp/Bug-35644812" />
         <option name="push" value="Bug-36492827->/data/local/tmp/Bug-36492827" />
 
+        <!--__________________-->
+        <!-- Bulletin 2017-10 -->
+        <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
+
+        <option name="push" value="Bug-62058746->/data/local/tmp/Bug-62058746" />
+
+
         <option name="append-bitness" value="true" />
     </target_preparer>
     <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >
diff --git a/hostsidetests/security/securityPatch/Bug-62058746/Android.mk b/hostsidetests/security/securityPatch/Bug-62058746/Android.mk
new file mode 100644
index 0000000..b34be83
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-62058746/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := Bug-62058746
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-62058746/poc.c b/hostsidetests/security/securityPatch/Bug-62058746/poc.c
new file mode 100644
index 0000000..05d54fe
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-62058746/poc.c
@@ -0,0 +1,50 @@
+/**
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#define _GNU_SOURCE
+
+#include <ctype.h>
+#include <dirent.h>
+#include <dlfcn.h>
+#include <elf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/ptrace.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#define FILE_PATH ("/proc/cld/athdiagpfs")
+
+#define TEST_SIZE (8092)
+
+void *read_test(int arg) {
+  size_t buffer_size = (size_t)arg;
+  FILE *fd = fopen(FILE_PATH, "rb");
+  char *buffer = (char *)malloc(sizeof(char) * buffer_size);
+  memset(buffer, '0', buffer_size);
+  buffer[buffer_size-1] = '\0';
+  while (fgets(buffer, buffer_size, fd))  { }
+  return NULL;
+}
+
+int main() { read_test(TEST_SIZE); }
diff --git a/hostsidetests/security/src/android/security/cts/Poc17_10.java b/hostsidetests/security/src/android/security/cts/Poc17_10.java
new file mode 100644
index 0000000..8b5cbc6
--- /dev/null
+++ b/hostsidetests/security/src/android/security/cts/Poc17_10.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.security.cts;
+
+import android.platform.test.annotations.SecurityTest;
+
+@SecurityTest
+public class Poc17_10 extends SecurityTestCase {
+
+    /**
+     * b/62058746
+     */
+    @SecurityTest
+    public void testPocBug_62058746() throws Exception {
+        enableAdbRoot(getDevice());
+        if (containsDriver(getDevice(), "/proc/cld/athdiagpfs")) {
+          AdbUtils.runPocNoOutput("Bug-62058746", getDevice(), 60);
+        }
+    }
+}