OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <asm/unistd.h> | 5 #include <asm/unistd.h> |
6 #include <fcntl.h> | 6 #include <fcntl.h> |
7 #include <sys/mman.h> | 7 #include <sys/mman.h> |
8 #include <sys/syscall.h> | 8 #include <sys/syscall.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 TEST(Syscall, TrivialSyscallNoArgs) { | 58 TEST(Syscall, TrivialSyscallNoArgs) { |
59 // Test that we can do basic system calls | 59 // Test that we can do basic system calls |
60 EXPECT_EQ(SandboxSyscall(__NR_getpid), syscall(__NR_getpid)); | 60 EXPECT_EQ(SandboxSyscall(__NR_getpid), syscall(__NR_getpid)); |
61 } | 61 } |
62 | 62 |
63 TEST(Syscall, TrivialSyscallOneArg) { | 63 TEST(Syscall, TrivialSyscallOneArg) { |
64 int new_fd; | 64 int new_fd; |
65 // Duplicate standard error and close it. | 65 // Duplicate standard error and close it. |
66 ASSERT_GE(new_fd = SandboxSyscall(__NR_dup, 2), 0); | 66 ASSERT_GE(new_fd = SandboxSyscall(__NR_dup, 2), 0); |
67 int close_return_value = HANDLE_EINTR(SandboxSyscall(__NR_close, new_fd)); | 67 int close_return_value = IGNORE_EINTR(SandboxSyscall(__NR_close, new_fd)); |
68 ASSERT_EQ(close_return_value, 0); | 68 ASSERT_EQ(close_return_value, 0); |
69 } | 69 } |
70 | 70 |
71 // SIGSYS trap handler that will be called on __NR_uname. | 71 // SIGSYS trap handler that will be called on __NR_uname. |
72 intptr_t CopySyscallArgsToAux(const struct arch_seccomp_data& args, void* aux) { | 72 intptr_t CopySyscallArgsToAux(const struct arch_seccomp_data& args, void* aux) { |
73 // |aux| is a pointer to our BPF_AUX. | 73 // |aux| is a pointer to our BPF_AUX. |
74 std::vector<uint64_t>* const seen_syscall_args = | 74 std::vector<uint64_t>* const seen_syscall_args = |
75 static_cast<std::vector<uint64_t>*>(aux); | 75 static_cast<std::vector<uint64_t>*>(aux); |
76 BPF_ASSERT(arraysize(args.args) == 6); | 76 BPF_ASSERT(arraysize(args.args) == 6); |
77 seen_syscall_args->assign(args.args, args.args + arraysize(args.args)); | 77 seen_syscall_args->assign(args.args, args.args + arraysize(args.args)); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 addr0, | 153 addr0, |
154 4096L, | 154 4096L, |
155 PROT_READ | PROT_WRITE, | 155 PROT_READ | PROT_WRITE, |
156 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, | 156 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, |
157 fd, | 157 fd, |
158 0L))); | 158 0L))); |
159 ++*addr1; // This should not seg fault | 159 ++*addr1; // This should not seg fault |
160 | 160 |
161 // Clean up | 161 // Clean up |
162 EXPECT_EQ(0, SandboxSyscall(__NR_munmap, addr1, 4096L)); | 162 EXPECT_EQ(0, SandboxSyscall(__NR_munmap, addr1, 4096L)); |
163 EXPECT_EQ(0, HANDLE_EINTR(SandboxSyscall(__NR_close, fd))); | 163 EXPECT_EQ(0, IGNORE_EINTR(SandboxSyscall(__NR_close, fd))); |
164 | 164 |
165 // Check that the offset argument (i.e. the sixth argument) is processed | 165 // Check that the offset argument (i.e. the sixth argument) is processed |
166 // correctly. | 166 // correctly. |
167 ASSERT_GE(fd = SandboxSyscall(__NR_open, "/proc/self/exe", O_RDONLY, 0L), 0); | 167 ASSERT_GE(fd = SandboxSyscall(__NR_open, "/proc/self/exe", O_RDONLY, 0L), 0); |
168 char* addr2, *addr3; | 168 char* addr2, *addr3; |
169 ASSERT_NE((char*)NULL, | 169 ASSERT_NE((char*)NULL, |
170 addr2 = reinterpret_cast<char*>(SandboxSyscall( | 170 addr2 = reinterpret_cast<char*>(SandboxSyscall( |
171 kMMapNr, (void*)NULL, 8192L, PROT_READ, MAP_PRIVATE, fd, 0L))); | 171 kMMapNr, (void*)NULL, 8192L, PROT_READ, MAP_PRIVATE, fd, 0L))); |
172 ASSERT_NE((char*)NULL, | 172 ASSERT_NE((char*)NULL, |
173 addr3 = reinterpret_cast<char*>(SandboxSyscall(kMMapNr, | 173 addr3 = reinterpret_cast<char*>(SandboxSyscall(kMMapNr, |
(...skipping 12 matching lines...) Expand all Loading... |
186 | 186 |
187 // Just to be absolutely on the safe side, also verify that the file | 187 // Just to be absolutely on the safe side, also verify that the file |
188 // contents matches what we are getting from a read() operation. | 188 // contents matches what we are getting from a read() operation. |
189 char buf[8192]; | 189 char buf[8192]; |
190 EXPECT_EQ(8192, SandboxSyscall(__NR_read, fd, buf, 8192L)); | 190 EXPECT_EQ(8192, SandboxSyscall(__NR_read, fd, buf, 8192L)); |
191 EXPECT_EQ(0, memcmp(addr2, buf, 8192)); | 191 EXPECT_EQ(0, memcmp(addr2, buf, 8192)); |
192 | 192 |
193 // Clean up | 193 // Clean up |
194 EXPECT_EQ(0, SandboxSyscall(__NR_munmap, addr2, 8192L)); | 194 EXPECT_EQ(0, SandboxSyscall(__NR_munmap, addr2, 8192L)); |
195 EXPECT_EQ(0, SandboxSyscall(__NR_munmap, addr3, 4096L)); | 195 EXPECT_EQ(0, SandboxSyscall(__NR_munmap, addr3, 4096L)); |
196 EXPECT_EQ(0, HANDLE_EINTR(SandboxSyscall(__NR_close, fd))); | 196 EXPECT_EQ(0, IGNORE_EINTR(SandboxSyscall(__NR_close, fd))); |
197 } | 197 } |
198 | 198 |
199 } // namespace | 199 } // namespace |
OLD | NEW |