CTS test for Android Security b/162383705
Bug: 162383705
Bug: 163560392
Test: Ran the new testcase on android-11.0.0_r1 with/without patch
Change-Id: I66d9cfb07794c3fcf8587f2de14bf8a818de30fd
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2020-0420/Android.bp b/hostsidetests/securitybulletin/securityPatch/CVE-2020-0420/Android.bp
new file mode 100644
index 0000000..b4078ae
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2020-0420/Android.bp
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2021 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.
+ *
+ */
+
+cc_test {
+ name: "CVE-2020-0420",
+ defaults: ["cts_hostsidetests_securitybulletin_defaults"],
+ srcs: [
+ "poc.cpp",
+ ],
+ shared_libs: [
+ "libutils",
+ "libbinder",
+ "libmedia",
+ "liblog",
+ ],
+}
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2020-0420/poc.cpp b/hostsidetests/securitybulletin/securityPatch/CVE-2020-0420/poc.cpp
new file mode 100644
index 0000000..426c6d2
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2020-0420/poc.cpp
@@ -0,0 +1,59 @@
+/**
+ * Copyright (C) 2021 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 "../includes/common.h"
+#include <binder/IServiceManager.h>
+#include <binder/Parcel.h>
+#include <stdio.h>
+
+using namespace android;
+
+int main(void) {
+ status_t err;
+ sp<IServiceManager> sm = defaultServiceManager();
+ String16 name(String16("gpu"));
+ sp<IBinder> service = sm->checkService(name);
+ String16 interface_name = service->getInterfaceDescriptor();
+
+ Parcel data, reply;
+ std::string UpdatableDriverPath("CVE-2020-0420");
+ data.writeInterfaceToken(interface_name);
+ data.writeUtf8AsUtf16(UpdatableDriverPath);
+ err = service->transact(3 /*SET_UPDATABLE_DRIVER_PATH,*/, data, &reply, 0);
+ if (err != OK) {
+ return EXIT_FAILURE;
+ }
+
+ Parcel data1, reply1;
+ data1.writeInterfaceToken(interface_name);
+ err = service->transact(4 /*GET_UPDATABLE_DRIVER_PATH,*/, data1, &reply1, 0);
+ if (err != OK) {
+ return EXIT_FAILURE;
+ }
+ std::string driverPath;
+ err = reply1.readUtf8FromUtf16(&driverPath);
+ if (err != OK) {
+ return EXIT_FAILURE;
+ }
+
+ /** If the driver path returned is same as that was set, then there is no
+ * check in the API and the vulnerability is present.
+ */
+ if (0 == strcmp(driverPath.c_str(), UpdatableDriverPath.c_str())) {
+ return EXIT_VULNERABLE;
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2020_0420.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2020_0420.java
new file mode 100644
index 0000000..bff13f3
--- /dev/null
+++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2020_0420.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2021 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.AsbSecurityTest;
+import android.platform.test.annotations.SecurityTest;
+import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(DeviceJUnit4ClassRunner.class)
+public class CVE_2020_0420 extends SecurityTestCase {
+
+ /**
+ * b/162383705
+ * Vulnerability Behaviour: EXIT_VULNERABLE (113)
+ */
+ @AsbSecurityTest(cveBugId = 162383705)
+ @SecurityTest(minPatchLevel = "2020-10")
+ @Test
+ public void testPocCVE_2020_0420() throws Exception {
+ AdbUtils.runPocAssertNoCrashesNotVulnerable("CVE-2020-0420", null, getDevice());
+ }
+}