OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Sanitizers internally use some syscalls which non-SFI NaCl disallows. | 5 // Sanitizers internally use some syscalls which non-SFI NaCl disallows. |
6 #if !defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER) && \ | 6 #if !defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER) && \ |
7 !defined(MEMORY_SANITIZER) && !defined(LEAK_SANITIZER) | 7 !defined(MEMORY_SANITIZER) && !defined(LEAK_SANITIZER) |
8 | 8 |
9 #include "components/nacl/loader/nonsfi/nonsfi_sandbox.h" | 9 #include "components/nacl/loader/nonsfi/nonsfi_sandbox.h" |
10 | 10 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 195 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
196 prctl_SET_DUMPABLE, | 196 prctl_SET_DUMPABLE, |
197 DEATH_SEGV_MESSAGE( | 197 DEATH_SEGV_MESSAGE( |
198 sandbox::GetPrctlErrorMessageContentForTests()), | 198 sandbox::GetPrctlErrorMessageContentForTests()), |
199 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 199 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
200 syscall(__NR_prctl, PR_SET_DUMPABLE, 1UL); | 200 syscall(__NR_prctl, PR_SET_DUMPABLE, 1UL); |
201 } | 201 } |
202 | 202 |
203 #if defined(OS_NACL_NONSFI) | 203 #if defined(OS_NACL_NONSFI) |
204 BPF_DEATH_TEST_C(NaClNonsfiSandboxTest, | 204 BPF_DEATH_TEST_C(NaClNonsfiSandboxTest, |
205 socketpair, | 205 socketpair_af_unix_disallowed, |
206 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 206 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
207 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 207 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
208 int tmp_fds[2]; | 208 int tmp_fds[2]; |
209 socketpair(AF_UNIX, SOCK_STREAM, 0, tmp_fds); | 209 socketpair(AF_UNIX, SOCK_STREAM, 0, tmp_fds); |
210 } | 210 } |
211 #else | 211 #else |
212 BPF_TEST_C(NaClNonSfiSandboxTest, | 212 BPF_TEST_C(NaClNonSfiSandboxTest, |
213 socketcall_allowed, | 213 socketcall_allowed, |
214 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 214 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
215 base::ScopedFD fds[2]; | 215 base::ScopedFD fds[2]; |
216 struct msghdr msg = {}; | 216 struct msghdr msg = {}; |
217 struct iovec iov; | 217 struct iovec iov; |
218 std::string payload("foo"); | 218 std::string payload("foo"); |
219 iov.iov_base = &payload[0]; | 219 iov.iov_base = &payload[0]; |
220 iov.iov_len = payload.size(); | 220 iov.iov_len = payload.size(); |
221 msg.msg_iov = &iov; | 221 msg.msg_iov = &iov; |
222 msg.msg_iovlen = 1; | 222 msg.msg_iovlen = 1; |
223 DoSocketpair(fds); | 223 DoSocketpair(fds); |
224 BPF_ASSERT_EQ(static_cast<int>(payload.size()), | 224 BPF_ASSERT_EQ(static_cast<int>(payload.size()), |
225 HANDLE_EINTR(sendmsg(fds[1].get(), &msg, 0))); | 225 HANDLE_EINTR(sendmsg(fds[1].get(), &msg, 0))); |
226 BPF_ASSERT_EQ(static_cast<int>(payload.size()), | 226 BPF_ASSERT_EQ(static_cast<int>(payload.size()), |
227 HANDLE_EINTR(recvmsg(fds[0].get(), &msg, 0))); | 227 HANDLE_EINTR(recvmsg(fds[0].get(), &msg, 0))); |
228 BPF_ASSERT_EQ(0, shutdown(fds[0].get(), SHUT_RDWR)); | 228 BPF_ASSERT_EQ(0, shutdown(fds[0].get(), SHUT_RDWR)); |
229 } | 229 } |
230 #endif | 230 #endif |
231 | 231 |
| 232 // On arm and x86_64 the arguments to socketpair are passed in registers, |
| 233 // so they can be filtered by seccomp-bpf. This filter cannot be applied |
| 234 // on x86_32 as the arguments are passed in memory. |
| 235 #if defined(__x86_64__) || defined(__arm__) |
| 236 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 237 socketpair_af_inet_disallowed, |
| 238 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 239 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 240 int fds[2]; |
| 241 socketpair(AF_INET, SOCK_STREAM, 0, fds); |
| 242 } |
| 243 #endif |
| 244 |
232 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 245 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
233 accept, | 246 accept, |
234 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 247 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
235 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 248 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
236 #if defined(__i386__) | 249 #if defined(__i386__) |
237 uintptr_t args[] = {0, 0, 0}; | 250 uintptr_t args[] = {0, 0, 0}; |
238 syscall(__NR_socketcall, SYS_ACCEPT, args); | 251 syscall(__NR_socketcall, SYS_ACCEPT, args); |
239 #else | 252 #else |
240 syscall(__NR_accept, 0, 0, 0); | 253 syscall(__NR_accept, 0, 0, 0); |
241 #endif | 254 #endif |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 399 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
387 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 400 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
388 #if defined(__i386__) | 401 #if defined(__i386__) |
389 uintptr_t args[] = {0, 0, 0}; | 402 uintptr_t args[] = {0, 0, 0}; |
390 syscall(__NR_socketcall, SYS_SOCKET, args); | 403 syscall(__NR_socketcall, SYS_SOCKET, args); |
391 #else | 404 #else |
392 syscall(__NR_socket, 0, 0, 0); | 405 syscall(__NR_socket, 0, 0, 0); |
393 #endif | 406 #endif |
394 } | 407 } |
395 | 408 |
396 #if defined(__x86_64__) || defined(__arm__) | |
397 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | |
398 socketpair, | |
399 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
400 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | |
401 int fds[2]; | |
402 socketpair(AF_INET, SOCK_STREAM, 0, fds); | |
403 } | |
404 #endif | |
405 | |
406 BPF_TEST_C(NaClNonSfiSandboxTest, | 409 BPF_TEST_C(NaClNonSfiSandboxTest, |
407 fcntl_SETFD_allowed, | 410 fcntl_SETFD_allowed, |
408 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 411 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
409 base::ScopedFD fds[2]; | 412 base::ScopedFD fds[2]; |
410 DoPipe(fds); | 413 DoPipe(fds); |
411 BPF_ASSERT_EQ(0, fcntl(fds[0].get(), F_SETFD, FD_CLOEXEC)); | 414 BPF_ASSERT_EQ(0, fcntl(fds[0].get(), F_SETFD, FD_CLOEXEC)); |
412 } | 415 } |
413 | 416 |
414 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 417 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
415 fcntl_SETFD, | 418 fcntl_SETFD, |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 RESTRICT_SYSCALL_EPERM_TEST(ptrace); | 677 RESTRICT_SYSCALL_EPERM_TEST(ptrace); |
675 RESTRICT_SYSCALL_EPERM_TEST(set_robust_list); | 678 RESTRICT_SYSCALL_EPERM_TEST(set_robust_list); |
676 #if defined(__i386__) || defined(__x86_64__) | 679 #if defined(__i386__) || defined(__x86_64__) |
677 RESTRICT_SYSCALL_EPERM_TEST(time); | 680 RESTRICT_SYSCALL_EPERM_TEST(time); |
678 #endif | 681 #endif |
679 | 682 |
680 } // namespace | 683 } // namespace |
681 | 684 |
682 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER && | 685 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER && |
683 // !MEMORY_SANITIZER && !LEAK_SANITIZER | 686 // !MEMORY_SANITIZER && !LEAK_SANITIZER |
OLD | NEW |