diff options
author | Luis Hector Chavez <lhchavez@google.com> | 2018-04-24 08:40:10 -0700 |
---|---|---|
committer | Luis Hector Chavez <lhchavez@google.com> | 2018-04-25 18:29:11 -0700 |
commit | 687cd48d8bce5548c7bf1dcbbfd3fd770e452362 (patch) | |
tree | 3e10b8b545ce30b5d29ed6e0c7c8a99748e59859 /tests | |
parent | 7aed4125be59e756f980bc4ba90350e32088770a (diff) | |
download | extras-687cd48d8bce5548c7bf1dcbbfd3fd770e452362.tar.gz |
Make the NOT_CONFIG_SYSVIPC test also exercise the syscalls
This change augments the NOT_CONFIG_SYSVIPC test, such that in addition
to being evidence-based (by inspecting some paths in /proc), it also
tries to invoke the syscalls. This is done because in some platforms
like Chrome OS, the SYSVIPC kernel config is enabled (because some parts
of the system require that to boot), but when Android is running, all
SYSVIPC syscalls are blocked by an LSM in the kernel.
It also changes the /proc/sysvipc path check from using access(2) and
F_OK to R_OK, since the paths itself is present and visible.
Bug: 77490033
Test: CtsKernelConfigTestCases
Change-Id: I79df1816e0e5d3618da2a0e242c3d685352b7220
Diffstat (limited to 'tests')
-rw-r--r-- | tests/kernel.config/sysvipc_test.cpp | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/tests/kernel.config/sysvipc_test.cpp b/tests/kernel.config/sysvipc_test.cpp index 49952f01..9aeda122 100644 --- a/tests/kernel.config/sysvipc_test.cpp +++ b/tests/kernel.config/sysvipc_test.cpp @@ -18,6 +18,10 @@ #include <linux/kcmp.h> #include <sys/syscall.h> #endif +#include <sys/ipc.h> +#include <sys/msg.h> +#include <sys/sem.h> +#include <sys/shm.h> #include <unistd.h> #include <gtest/gtest.h> @@ -28,6 +32,45 @@ int kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx } #endif +int msgctl(int id, int cmd, msqid_ds* buf) { +#if !defined(__LP64__) || defined(__mips__) + // Annoyingly, the kernel requires this for 32-bit but rejects it for 64-bit. + // Mips64 is an exception to this, it requires the flag. + cmd |= IPC_64; +#endif +#if defined(SYS_msgctl) + return syscall(SYS_msgctl, id, cmd, buf); +#else + return syscall(SYS_ipc, MSGCTL, id, cmd, 0, buf, 0); +#endif +} + +int semctl(int id, int num, int cmd, semid_ds* buf) { +#if !defined(__LP64__) || defined(__mips__) + // Annoyingly, the kernel requires this for 32-bit but rejects it for 64-bit. + // Mips64 is an exception to this, it requires the flag. + cmd |= IPC_64; +#endif +#if defined(SYS_msgctl) + return syscall(SYS_semctl, id, num, cmd, buf); +#else + return syscall(SYS_ipc, SEMCTL, id, num, cmd, buf, 0); +#endif +} + +int shmctl(int id, int cmd, shmid_ds* buf) { +#if !defined(__LP64__) || defined(__mips__) + // Annoyingly, the kernel requires this for 32-bit but rejects it for 64-bit. + // Mips64 is an exception to this, it requires the flag. + cmd |= IPC_64; +#endif +#if defined(SYS_shmctl) + return syscall(SYS_shmctl, id, cmd, buf); +#else + return syscall(SYS_ipc, SHMCTL, id, cmd, 0, buf, 0); +#endif +} + TEST(kernel_config, NOT_CONFIG_SYSVIPC) { #ifdef HAS_KCMP pid_t pid = getpid(); @@ -36,9 +79,19 @@ TEST(kernel_config, NOT_CONFIG_SYSVIPC) { EXPECT_EQ(-1, kcmp(pid, pid, KCMP_SYSVSEM, 0, 0)); EXPECT_EQ(EOPNOTSUPP, error); #endif - EXPECT_EQ(-1, access("/proc/sysvipc", F_OK)); + + EXPECT_EQ(-1, access("/proc/sysvipc", R_OK)); + EXPECT_EQ(-1, access("/proc/sysvipc/msg", F_OK)); + EXPECT_EQ(-1, msgctl(-1, IPC_STAT, nullptr)); + EXPECT_EQ(ENOSYS, errno); + EXPECT_EQ(-1, access("/proc/sysvipc/sem", F_OK)); + EXPECT_EQ(-1, semctl(-1, 0, IPC_STAT, nullptr)); + EXPECT_EQ(ENOSYS, errno); + EXPECT_EQ(-1, access("/proc/sysvipc/shm", F_OK)); + EXPECT_EQ(-1, shmctl(-1, IPC_STAT, nullptr)); + EXPECT_EQ(ENOSYS, errno); } |