summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2013-07-08 12:26:43 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-07-08 12:26:43 -0700
commit9365f2d871c16378f0f40a8e8d6e70e1a030c2b8 (patch)
treea6a53bdcd59d5d55ef2b9457a7bf9fdadc97f88f
parentc8a3995aac9eeb722541c89b90a733768988ddb6 (diff)
parentaa3e957fe67e1c9eb0728c1f302e209452d3b00e (diff)
downloadcts-9365f2d871c16378f0f40a8e8d6e70e1a030c2b8.tar.gz
am aa3e957f: am c6daa518: am 86616f3c: am 59507a6d: am deadf911: Add test for CVE-2013-2094
* commit 'aa3e957fe67e1c9eb0728c1f302e209452d3b00e': Add test for CVE-2013-2094
-rw-r--r--tests/tests/security/jni/Android.mk3
-rw-r--r--tests/tests/security/jni/CtsSecurityJniOnLoad.cpp5
-rw-r--r--tests/tests/security/jni/android_security_cts_NativeCodeTest.cpp51
-rw-r--r--tests/tests/security/src/android/security/cts/NativeCodeTest.java40
4 files changed, 98 insertions, 1 deletions
diff --git a/tests/tests/security/jni/Android.mk b/tests/tests/security/jni/Android.mk
index ee185c5b965..5821ec06019 100644
--- a/tests/tests/security/jni/Android.mk
+++ b/tests/tests/security/jni/Android.mk
@@ -23,7 +23,8 @@ LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := \
CtsSecurityJniOnLoad.cpp \
- android_security_cts_CharDeviceTest.cpp
+ android_security_cts_CharDeviceTest.cpp \
+ android_security_cts_NativeCodeTest.cpp
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
diff --git a/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp b/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
index 045581f7da6..7244fc2e327 100644
--- a/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
+++ b/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
@@ -18,6 +18,7 @@
#include <stdio.h>
extern int register_android_security_cts_CharDeviceTest(JNIEnv*);
+extern int register_android_security_cts_NativeCodeTest(JNIEnv*);
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
JNIEnv *env = NULL;
@@ -30,5 +31,9 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}
+ if (register_android_security_cts_NativeCodeTest(env)) {
+ return JNI_ERR;
+ }
+
return JNI_VERSION_1_4;
}
diff --git a/tests/tests/security/jni/android_security_cts_NativeCodeTest.cpp b/tests/tests/security/jni/android_security_cts_NativeCodeTest.cpp
new file mode 100644
index 00000000000..7af42985e94
--- /dev/null
+++ b/tests/tests/security/jni/android_security_cts_NativeCodeTest.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2013 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 <jni.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+/*
+ * Returns true iff this device is vulnerable to CVE-2013-2094.
+ * A patch for CVE-2013-2094 can be found at
+ * http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=8176cced706b5e5d15887584150764894e94e02f
+ */
+static jboolean android_security_cts_NativeCodeTest_doPerfEventTest(JNIEnv* env, jobject thiz)
+{
+ uint64_t attr[10] = { 0x4800000001, (uint32_t) -1, 0, 0, 0, 0x300 };
+
+ int fd = syscall(__NR_perf_event_open, attr, 0, -1, -1, 0);
+ jboolean result = (fd != -1);
+
+ if (fd != -1) {
+ close(fd);
+ }
+
+ return result;
+}
+
+static JNINativeMethod gMethods[] = {
+ { "doPerfEventTest", "()Z",
+ (void *) android_security_cts_NativeCodeTest_doPerfEventTest },
+};
+
+int register_android_security_cts_NativeCodeTest(JNIEnv* env)
+{
+ jclass clazz = env->FindClass("android/security/cts/NativeCodeTest");
+ return env->RegisterNatives(clazz, gMethods,
+ sizeof(gMethods) / sizeof(JNINativeMethod));
+}
diff --git a/tests/tests/security/src/android/security/cts/NativeCodeTest.java b/tests/tests/security/src/android/security/cts/NativeCodeTest.java
new file mode 100644
index 00000000000..2522ef57583
--- /dev/null
+++ b/tests/tests/security/src/android/security/cts/NativeCodeTest.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2013 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 junit.framework.TestCase;
+
+public class NativeCodeTest extends TestCase {
+
+ static {
+ System.loadLibrary("ctssecurity_jni");
+ }
+
+ public void testPerfEvent() throws Exception {
+ assertFalse("Device is vulnerable to CVE-2013-2094. Please apply security patch "
+ + "at http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/"
+ + "commit/?id=8176cced706b5e5d15887584150764894e94e02f",
+ doPerfEventTest());
+ }
+
+ /**
+ * Returns true iff this device is vulnerable to CVE-2013-2094.
+ * A patch for CVE-2013-2094 can be found at
+ * http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=8176cced706b5e5d15887584150764894e94e02f
+ */
+ private static native boolean doPerfEventTest();
+}