diff options
author | Andrei Vagin <avagin@google.com> | 2019-04-04 17:42:51 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-04-04 17:43:53 -0700 |
commit | 88409e983c463b6d9c8085e7fdbe7ff45b3c5184 (patch) | |
tree | f5ba3e9b1c67a7641a8d4d7c4106bd5bc5c2dcf1 /test/syscalls/linux/mount.cc | |
parent | 75a5ccf5d98876c26305da0feff20e4a148027ec (diff) |
gvisor: Add support for the MS_NOEXEC mount option
https://github.com/google/gvisor/issues/145
PiperOrigin-RevId: 242044115
Change-Id: I8f140fe05e32ecd438b6be218e224e4b7fe05878
Diffstat (limited to 'test/syscalls/linux/mount.cc')
-rw-r--r-- | test/syscalls/linux/mount.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/syscalls/linux/mount.cc b/test/syscalls/linux/mount.cc index 6bb4287a3..201b83e87 100644 --- a/test/syscalls/linux/mount.cc +++ b/test/syscalls/linux/mount.cc @@ -31,6 +31,7 @@ #include "test/util/file_descriptor.h" #include "test/util/fs_util.h" #include "test/util/mount_util.h" +#include "test/util/multiprocess_util.h" #include "test/util/posix_error.h" #include "test/util/temp_path.h" #include "test/util/test_util.h" @@ -277,6 +278,23 @@ TEST(MountTest, MountNoAtime) { EXPECT_EQ(before, after); } +TEST(MountTest, MountNoExec) { + SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_SYS_ADMIN))); + + auto const dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir()); + auto const mount = ASSERT_NO_ERRNO_AND_VALUE( + Mount("", dir.path(), "tmpfs", MS_NOEXEC, "mode=0777", 0)); + + std::string const contents = "No no no, don't follow the instructions!"; + auto const file = ASSERT_NO_ERRNO_AND_VALUE( + TempPath::CreateFileWith(dir.path(), contents, 0777)); + + int execve_errno; + ASSERT_NO_ERRNO_AND_VALUE( + ForkAndExec(file.path(), {}, {}, nullptr, &execve_errno)); + EXPECT_EQ(execve_errno, EACCES); +} + TEST(MountTest, RenameRemoveMountPoint) { SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_SYS_ADMIN))); |