summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux
diff options
context:
space:
mode:
Diffstat (limited to 'test/syscalls/linux')
-rw-r--r--test/syscalls/linux/BUILD1
-rw-r--r--test/syscalls/linux/mount.cc36
-rw-r--r--test/syscalls/linux/open.cc12
-rw-r--r--test/syscalls/linux/semaphore.cc43
-rw-r--r--test/syscalls/linux/udp_socket.cc7
5 files changed, 38 insertions, 61 deletions
diff --git a/test/syscalls/linux/BUILD b/test/syscalls/linux/BUILD
index 89d532c70..4e0c8a574 100644
--- a/test/syscalls/linux/BUILD
+++ b/test/syscalls/linux/BUILD
@@ -21,6 +21,7 @@ exports_files(
"socket_ip_unbound.cc",
"socket_ipv4_udp_unbound_external_networking_test.cc",
"socket_ipv4_udp_unbound_loopback.cc",
+ "socket_ipv6_udp_unbound_loopback.cc",
"socket_ipv4_udp_unbound_loopback_nogotsan.cc",
"tcp_socket.cc",
"udp_bind.cc",
diff --git a/test/syscalls/linux/mount.cc b/test/syscalls/linux/mount.cc
index d65b7d031..15b645fb7 100644
--- a/test/syscalls/linux/mount.cc
+++ b/test/syscalls/linux/mount.cc
@@ -345,42 +345,6 @@ TEST(MountTest, RenameRemoveMountPoint) {
ASSERT_THAT(rmdir(dir.path().c_str()), SyscallFailsWithErrno(EBUSY));
}
-TEST(MountTest, MountFuseFilesystemNoDevice) {
- SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_SYS_ADMIN)));
- SKIP_IF(IsRunningOnGvisor() && !IsFUSEEnabled());
-
- auto const dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir());
-
- // Before kernel version 4.16-rc6, FUSE mount is protected by
- // capable(CAP_SYS_ADMIN). After this version, it uses
- // ns_capable(CAP_SYS_ADMIN) to protect. Before the 4.16 kernel, it was not
- // allowed to mount fuse file systems without the global CAP_SYS_ADMIN.
- int res = mount("", dir.path().c_str(), "fuse", 0, "");
- SKIP_IF(!IsRunningOnGvisor() && res == -1 && errno == EPERM);
-
- EXPECT_THAT(mount("", dir.path().c_str(), "fuse", 0, ""),
- SyscallFailsWithErrno(EINVAL));
-}
-
-TEST(MountTest, MountFuseFilesystem) {
- SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_SYS_ADMIN)));
- SKIP_IF(IsRunningOnGvisor() && !IsFUSEEnabled());
-
- const FileDescriptor fd =
- ASSERT_NO_ERRNO_AND_VALUE(Open("/dev/fuse", O_WRONLY));
- std::string mopts = "fd=" + std::to_string(fd.get());
-
- auto const dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir());
-
- // See comments in MountFuseFilesystemNoDevice for the reason why we skip
- // EPERM when running on Linux.
- int res = mount("", dir.path().c_str(), "fuse", 0, "");
- SKIP_IF(!IsRunningOnGvisor() && res == -1 && errno == EPERM);
-
- auto const mount =
- ASSERT_NO_ERRNO_AND_VALUE(Mount("", dir.path(), "fuse", 0, mopts, 0));
-}
-
} // namespace
} // namespace testing
diff --git a/test/syscalls/linux/open.cc b/test/syscalls/linux/open.cc
index 77f390f3c..fcd162ca2 100644
--- a/test/syscalls/linux/open.cc
+++ b/test/syscalls/linux/open.cc
@@ -505,6 +505,18 @@ TEST_F(OpenTest, OpenNonDirectoryWithTrailingSlash) {
EXPECT_THAT(open(bad_path.c_str(), O_RDONLY), SyscallFailsWithErrno(ENOTDIR));
}
+TEST_F(OpenTest, OpenWithStrangeFlags) {
+ // VFS1 incorrectly allows read/write operations on such file descriptors.
+ SKIP_IF(IsRunningWithVFS1());
+
+ const TempPath file = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile());
+ const FileDescriptor fd =
+ ASSERT_NO_ERRNO_AND_VALUE(Open(file.path(), O_WRONLY | O_RDWR));
+ EXPECT_THAT(write(fd.get(), "x", 1), SyscallFailsWithErrno(EBADF));
+ char c;
+ EXPECT_THAT(read(fd.get(), &c, 1), SyscallFailsWithErrno(EBADF));
+}
+
} // namespace
} // namespace testing
diff --git a/test/syscalls/linux/semaphore.cc b/test/syscalls/linux/semaphore.cc
index d485ad15a..0530fce44 100644
--- a/test/syscalls/linux/semaphore.cc
+++ b/test/syscalls/linux/semaphore.cc
@@ -32,8 +32,6 @@
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
-using ::testing::Contains;
-
namespace gvisor {
namespace testing {
namespace {
@@ -793,7 +791,6 @@ TEST(SemaphoreTest, IpcInfo) {
struct seminfo info;
// Drop CAP_IPC_OWNER which allows us to bypass semaphore permissions.
ASSERT_NO_ERRNO(SetCapability(CAP_IPC_OWNER, false));
- ASSERT_THAT(semctl(0, 0, IPC_INFO, &info), SyscallSucceedsWithValue(0));
for (int i = 0; i < kLoops; i++) {
AutoSem sem(semget(IPC_PRIVATE, 1, 0600 | IPC_CREAT));
ASSERT_THAT(sem.get(), SyscallSucceeds());
@@ -805,13 +802,12 @@ TEST(SemaphoreTest, IpcInfo) {
EXPECT_THAT(max_used_index = semctl(0, 0, IPC_INFO, &info),
SyscallSucceeds());
- int index_count = 0;
+ std::set<int> sem_ids_before_max_index;
for (int i = 0; i <= max_used_index; i++) {
struct semid_ds ds = {};
int sem_id = semctl(i, 0, SEM_STAT, &ds);
// Only if index i is used within the registry.
- if (sem_id != -1) {
- ASSERT_THAT(sem_ids, Contains(sem_id));
+ if (sem_ids.find(sem_id) != sem_ids.end()) {
struct semid_ds ipc_stat_ds;
ASSERT_THAT(semctl(sem_id, 0, IPC_STAT, &ipc_stat_ds), SyscallSucceeds());
EXPECT_EQ(ds.sem_perm.__key, ipc_stat_ds.sem_perm.__key);
@@ -833,17 +829,15 @@ TEST(SemaphoreTest, IpcInfo) {
ASSERT_THAT(semctl(sem_id, 0, IPC_SET, &ipc_set_ds), SyscallSucceeds());
ASSERT_THAT(semctl(i, 0, SEM_STAT, &ds), SyscallFailsWithErrno(EACCES));
- index_count += 1;
+ sem_ids_before_max_index.insert(sem_id);
}
}
- EXPECT_EQ(index_count, kLoops);
- ASSERT_THAT(semctl(0, 0, IPC_INFO, &info),
- SyscallSucceedsWithValue(max_used_index));
+ EXPECT_EQ(sem_ids_before_max_index.size(), kLoops);
for (const int sem_id : sem_ids) {
ASSERT_THAT(semctl(sem_id, 0, IPC_RMID), SyscallSucceeds());
}
- ASSERT_THAT(semctl(0, 0, IPC_INFO, &info), SyscallSucceedsWithValue(0));
+ ASSERT_THAT(semctl(0, 0, IPC_INFO, &info), SyscallSucceeds());
EXPECT_EQ(info.semmap, kSemMap);
EXPECT_EQ(info.semmni, kSemMni);
EXPECT_EQ(info.semmns, kSemMns);
@@ -863,7 +857,6 @@ TEST(SemaphoreTest, SemInfo) {
struct seminfo info;
// Drop CAP_IPC_OWNER which allows us to bypass semaphore permissions.
ASSERT_NO_ERRNO(SetCapability(CAP_IPC_OWNER, false));
- ASSERT_THAT(semctl(0, 0, IPC_INFO, &info), SyscallSucceedsWithValue(0));
for (int i = 0; i < kLoops; i++) {
AutoSem sem(semget(IPC_PRIVATE, kSemSetSize, 0600 | IPC_CREAT));
ASSERT_THAT(sem.get(), SyscallSucceeds());
@@ -880,17 +873,19 @@ TEST(SemaphoreTest, SemInfo) {
EXPECT_EQ(info.semmsl, kSemMsl);
EXPECT_EQ(info.semopm, kSemOpm);
EXPECT_EQ(info.semume, kSemUme);
- EXPECT_EQ(info.semusz, sem_ids.size());
+ // There could be semaphores existing in the system during the test, which
+ // prevents the test from getting a exact number, but the test could expect at
+ // least the number of sempahroes it creates in the begining of the test.
+ EXPECT_GE(info.semusz, sem_ids.size());
EXPECT_EQ(info.semvmx, kSemVmx);
- EXPECT_EQ(info.semaem, sem_ids.size() * kSemSetSize);
+ EXPECT_GE(info.semaem, sem_ids.size() * kSemSetSize);
- int index_count = 0;
+ std::set<int> sem_ids_before_max_index;
for (int i = 0; i <= max_used_index; i++) {
struct semid_ds ds = {};
int sem_id = semctl(i, 0, SEM_STAT, &ds);
// Only if index i is used within the registry.
- if (sem_id != -1) {
- ASSERT_THAT(sem_ids, Contains(sem_id));
+ if (sem_ids.find(sem_id) != sem_ids.end()) {
struct semid_ds ipc_stat_ds;
ASSERT_THAT(semctl(sem_id, 0, IPC_STAT, &ipc_stat_ds), SyscallSucceeds());
EXPECT_EQ(ds.sem_perm.__key, ipc_stat_ds.sem_perm.__key);
@@ -912,17 +907,15 @@ TEST(SemaphoreTest, SemInfo) {
ASSERT_THAT(semctl(sem_id, 0, IPC_SET, &ipc_set_ds), SyscallSucceeds());
ASSERT_THAT(semctl(i, 0, SEM_STAT, &ds), SyscallFailsWithErrno(EACCES));
- index_count += 1;
+ sem_ids_before_max_index.insert(sem_id);
}
}
- EXPECT_EQ(index_count, kLoops);
- ASSERT_THAT(semctl(0, 0, SEM_INFO, &info),
- SyscallSucceedsWithValue(max_used_index));
+ EXPECT_EQ(sem_ids_before_max_index.size(), kLoops);
for (const int sem_id : sem_ids) {
ASSERT_THAT(semctl(sem_id, 0, IPC_RMID), SyscallSucceeds());
}
- ASSERT_THAT(semctl(0, 0, SEM_INFO, &info), SyscallSucceedsWithValue(0));
+ ASSERT_THAT(semctl(0, 0, SEM_INFO, &info), SyscallSucceeds());
EXPECT_EQ(info.semmap, kSemMap);
EXPECT_EQ(info.semmni, kSemMni);
EXPECT_EQ(info.semmns, kSemMns);
@@ -930,9 +923,11 @@ TEST(SemaphoreTest, SemInfo) {
EXPECT_EQ(info.semmsl, kSemMsl);
EXPECT_EQ(info.semopm, kSemOpm);
EXPECT_EQ(info.semume, kSemUme);
- EXPECT_EQ(info.semusz, 0);
+ // Apart from semapahores that are not created by the test, we can't determine
+ // the exact number of semaphore sets and semaphores, as a result, semusz and
+ // semaem range from 0 to a random number. Since the numbers are always
+ // non-negative, the test will not check the reslts of semusz and semaem.
EXPECT_EQ(info.semvmx, kSemVmx);
- EXPECT_EQ(info.semaem, 0);
}
} // namespace
diff --git a/test/syscalls/linux/udp_socket.cc b/test/syscalls/linux/udp_socket.cc
index 21727a2e7..650f12350 100644
--- a/test/syscalls/linux/udp_socket.cc
+++ b/test/syscalls/linux/udp_socket.cc
@@ -835,7 +835,12 @@ TEST_P(UdpSocketTest, RecvErrorConnRefused) {
// Check the contents of msg.
EXPECT_EQ(memcmp(got, buf, sizeof(buf)), 0); // iovec check
- EXPECT_NE(msg.msg_flags & MSG_ERRQUEUE, 0);
+ // TODO(b/176251997): The next check fails on the gvisor platform due to the
+ // kernel bug.
+ if (!IsRunningWithHostinet() || GvisorPlatform() == Platform::kPtrace ||
+ GvisorPlatform() == Platform::kKVM ||
+ GvisorPlatform() == Platform::kNative)
+ EXPECT_NE(msg.msg_flags & MSG_ERRQUEUE, 0);
EXPECT_EQ(memcmp(&remote, bind_addr_, addrlen_), 0);
// Check the contents of the control message.