summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2020-04-17 15:31:51 -0700
committergVisor bot <gvisor-bot@google.com>2020-04-17 15:33:05 -0700
commite838290e671c9d72dbaa3aba13bf0c35f1147de4 (patch)
treeb99612b463da2f05a5454417d4d3c98e048096a5 /test/syscalls/linux
parent486759a37d61b770019a81af00e0e733c655b3a8 (diff)
prlimit: don't check credentials on self
prlimit was erroneously comparing UIDs and GIDs when getting/setting a process' own limits. From the manpage: To set or get the resources of a process other than itself, the caller must have the CAP_SYS_RESOURCE capability, or the real, effective, and saved set user IDs of the target process must match the real user ID of the caller and the real, effective, and saved set group IDs of the target process must match the real group ID of the caller. PiperOrigin-RevId: 307127266
Diffstat (limited to 'test/syscalls/linux')
-rw-r--r--test/syscalls/linux/uidgid.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/syscalls/linux/uidgid.cc b/test/syscalls/linux/uidgid.cc
index 6218fbce1..ff66a79f4 100644
--- a/test/syscalls/linux/uidgid.cc
+++ b/test/syscalls/linux/uidgid.cc
@@ -14,6 +14,7 @@
#include <errno.h>
#include <grp.h>
+#include <sys/resource.h>
#include <sys/types.h>
#include <unistd.h>
@@ -249,6 +250,17 @@ TEST(UidGidRootTest, Setgroups) {
SyscallFailsWithErrno(EFAULT));
}
+TEST(UidGidRootTest, Setuid_prlimit) {
+ SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(IsRoot()));
+
+ // Change our UID.
+ EXPECT_THAT(seteuid(65534), SyscallSucceeds());
+
+ // Despite the UID change, we should be able to get our own limits.
+ struct rlimit rl = {};
+ ASSERT_THAT(prlimit(0, RLIMIT_NOFILE, NULL, &rl), SyscallSucceeds());
+}
+
} // namespace
} // namespace testing