summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux/pread64.cc
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2020-04-13 17:58:52 -0700
committergVisor bot <gvisor-bot@google.com>2020-04-13 18:00:17 -0700
commit71e6ac3e1f551cf52166bf501de114f06502b994 (patch)
treeda47d4a0d643d4aa0e446a94aa760e991a2d09fc /test/syscalls/linux/pread64.cc
parentd303684d7ab9b8a3961398fcf12560956ee9e2e3 (diff)
Don't allow read/write when offset+size overflows.
PiperOrigin-RevId: 306348346
Diffstat (limited to 'test/syscalls/linux/pread64.cc')
-rw-r--r--test/syscalls/linux/pread64.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/syscalls/linux/pread64.cc b/test/syscalls/linux/pread64.cc
index 2cecf2e5f..bcdbbb044 100644
--- a/test/syscalls/linux/pread64.cc
+++ b/test/syscalls/linux/pread64.cc
@@ -14,6 +14,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <linux/unistd.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/types.h>
@@ -118,6 +119,21 @@ TEST_F(Pread64Test, EndOfFile) {
EXPECT_THAT(pread64(fd.get(), buf, 1024, 0), SyscallSucceedsWithValue(0));
}
+int memfd_create(const std::string& name, unsigned int flags) {
+ return syscall(__NR_memfd_create, name.c_str(), flags);
+}
+
+TEST_F(Pread64Test, Overflow) {
+ int f = memfd_create("negative", 0);
+ const FileDescriptor fd(f);
+
+ EXPECT_THAT(ftruncate(fd.get(), 0x7fffffffffffffffull), SyscallSucceeds());
+
+ char buf[10];
+ EXPECT_THAT(pread64(fd.get(), buf, sizeof(buf), 0x7fffffffffffffffull),
+ SyscallFailsWithErrno(EINVAL));
+}
+
TEST(Pread64TestNoTempFile, CantReadSocketPair_NoRandomSave) {
int sock_fds[2];
EXPECT_THAT(socketpair(AF_UNIX, SOCK_STREAM, 0, sock_fds), SyscallSucceeds());