doSockDiagTest() should pass if sock_diag protocol not supported.
NETLINK_SOCK_DIAG protocol is required to exploit b/8263507. If the
vulnerable code is inaccessible by known errors, the test should pass.
Bug: 12476489
Change-Id: I249af25712704d34c9907f36561621f9fef9a3bf
diff --git a/tests/tests/security/jni/android_security_cts_NativeCodeTest.cpp b/tests/tests/security/jni/android_security_cts_NativeCodeTest.cpp
index 338df7b..1db8e97 100644
--- a/tests/tests/security/jni/android_security_cts_NativeCodeTest.cpp
+++ b/tests/tests/security/jni/android_security_cts_NativeCodeTest.cpp
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <cutils/log.h>
#include <linux/perf_event.h>
+#include <errno.h>
#define PASSED 0
#define UNKNOWN_ERROR -1
@@ -97,7 +98,16 @@
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG);
if (fd == -1) {
- return UNKNOWN_ERROR;
+ switch (errno) {
+ /* NETLINK_SOCK_DIAG not accessible, vector dne */
+ case EACCES:
+ case EAFNOSUPPORT:
+ case EPERM:
+ case EPROTONOSUPPORT:
+ return PASSED;
+ default:
+ return UNKNOWN_ERROR;
+ }
}
/* prepare and send netlink packet */
memset(&nladdr, 0, sizeof(nladdr));