Merge "Check kernel version before running qtaguid test" am: 3b38b58b1f
am: 6563bb9f75 Change-Id: I59ce2ab48b525e6fd6328bb259fe6b720b500925
This commit is contained in:
@@ -15,14 +15,39 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <error.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <cutils/qtaguid.h>
|
#include <cutils/qtaguid.h>
|
||||||
|
|
||||||
|
int hasQtaguidKernelSupport() {
|
||||||
|
struct utsname buf;
|
||||||
|
int kernel_version_major;
|
||||||
|
int kernel_version_minor;
|
||||||
|
|
||||||
|
int ret = uname(&buf);
|
||||||
|
if (ret) {
|
||||||
|
ret = -errno;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
char dummy;
|
||||||
|
ret = sscanf(buf.release, "%d.%d%c", &kernel_version_major, &kernel_version_minor, &dummy);
|
||||||
|
if (ret < 3)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if ((kernel_version_major == 4 && kernel_version_minor < 9) ||
|
||||||
|
(kernel_version_major < 4)) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return access("/proc/net/xt_qtaguid/ctrl", F_OK) != -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int getCtrlSkInfo(int tag, uid_t uid, uint64_t* sk_addr, int* ref_cnt) {
|
int getCtrlSkInfo(int tag, uid_t uid, uint64_t* sk_addr, int* ref_cnt) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
fp = fopen("/proc/net/xt_qtaguid/ctrl", "r");
|
fp = fopen("/proc/net/xt_qtaguid/ctrl", "r");
|
||||||
@@ -70,6 +95,12 @@ void checkNoSocketPointerLeaks(int family) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST (NativeQtaguidTest, close_socket_without_untag) {
|
TEST (NativeQtaguidTest, close_socket_without_untag) {
|
||||||
|
int res = hasQtaguidKernelSupport();
|
||||||
|
ASSERT_LE(0, res);
|
||||||
|
if (!res) {
|
||||||
|
GTEST_LOG_(INFO) << "This test is skipped since kernel may not have the module\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
uid_t uid = getuid();
|
uid_t uid = getuid();
|
||||||
int tag = arc4random();
|
int tag = arc4random();
|
||||||
@@ -83,6 +114,12 @@ TEST (NativeQtaguidTest, close_socket_without_untag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST (NativeQtaguidTest, close_socket_without_untag_ipv6) {
|
TEST (NativeQtaguidTest, close_socket_without_untag_ipv6) {
|
||||||
|
int res = hasQtaguidKernelSupport();
|
||||||
|
ASSERT_LE(0, res);
|
||||||
|
if (!res) {
|
||||||
|
GTEST_LOG_(INFO) << "This test is skipped since kernel may not have the module\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
int sockfd = socket(AF_INET6, SOCK_STREAM, 0);
|
int sockfd = socket(AF_INET6, SOCK_STREAM, 0);
|
||||||
uid_t uid = getuid();
|
uid_t uid = getuid();
|
||||||
int tag = arc4random();
|
int tag = arc4random();
|
||||||
@@ -96,12 +133,17 @@ TEST (NativeQtaguidTest, close_socket_without_untag_ipv6) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST (NativeQtaguidTest, no_socket_addr_leak) {
|
TEST (NativeQtaguidTest, no_socket_addr_leak) {
|
||||||
|
int res = hasQtaguidKernelSupport();
|
||||||
|
ASSERT_LE(0, res);
|
||||||
|
if (!res) {
|
||||||
|
GTEST_LOG_(INFO) << "This test is skipped since kernel may not have the module\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
checkNoSocketPointerLeaks(AF_INET);
|
checkNoSocketPointerLeaks(AF_INET);
|
||||||
checkNoSocketPointerLeaks(AF_INET6);
|
checkNoSocketPointerLeaks(AF_INET6);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
|
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user