Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/nacl/loader/nonsfi/nonsfi_sandbox.h" | |
| 6 | |
| 7 #include <errno.h> | |
| 8 #include <fcntl.h> | |
| 9 #include <pthread.h> | |
| 10 #include <sched.h> | |
| 11 #include <signal.h> | |
| 12 #include <stdlib.h> | |
| 13 #include <string.h> | |
| 14 #include <sys/mman.h> | |
| 15 #include <sys/prctl.h> | |
| 16 #include <sys/ptrace.h> | |
| 17 #include <sys/socket.h> | |
| 18 #include <sys/syscall.h> | |
| 19 #include <sys/types.h> | |
| 20 #include <sys/wait.h> | |
| 21 #include <unistd.h> | |
| 22 | |
| 23 #include "base/bind.h" | |
| 24 #include "base/callback.h" | |
| 25 #include "base/compiler_specific.h" | |
| 26 #include "base/files/scoped_file.h" | |
| 27 #include "base/logging.h" | |
| 28 #include "base/posix/eintr_wrapper.h" | |
| 29 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" | |
| 30 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" | |
| 31 | |
| 32 namespace { | |
| 33 | |
| 34 void DoPipe(base::ScopedFD* fds) { | |
| 35 int tmp_fds[2]; | |
| 36 BPF_ASSERT_EQ(0, pipe(tmp_fds)); | |
| 37 fds[0].reset(tmp_fds[0]); | |
| 38 fds[1].reset(tmp_fds[1]); | |
| 39 } | |
| 40 | |
| 41 void DoSocketpair(base::ScopedFD* fds) { | |
| 42 int tmp_fds[2]; | |
| 43 BPF_ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, tmp_fds)); | |
| 44 fds[0].reset(tmp_fds[0]); | |
| 45 fds[1].reset(tmp_fds[1]); | |
| 46 } | |
| 47 | |
| 48 TEST(NaClNonSfiSandboxTest, BPFIsSupported) { | |
| 49 bool seccomp_bpf_supported = false; | |
| 50 // Seccomp-BPF tests die under TSAN v2. See http://crbug.com/356588 | |
| 51 #if !defined(THREAD_SANITIZER) | |
| 52 seccomp_bpf_supported = ( | |
| 53 sandbox::SandboxBPF::SupportsSeccompSandbox(-1) == | |
| 54 sandbox::SandboxBPF::STATUS_AVAILABLE); | |
| 55 #endif | |
| 56 | |
| 57 if (!seccomp_bpf_supported) { | |
| 58 LOG(ERROR) << "Seccomp BPF is not supported, these tests " | |
| 59 << "will pass without running"; | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 BPF_DEATH_TEST(NaClNonSfiSandboxTest, invalid_sysno, | |
| 64 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 65 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 66 syscall(999); | |
| 67 } | |
| 68 | |
| 69 // To make this test pass, we need to allow sched_getaffinity and | |
| 70 // mmap. We just disable this test not to complicate the sandbox. | |
| 71 #if !defined(ADDRESS_SANITIZER) | |
| 72 const int kExpectedValue = 123; | |
| 73 | |
| 74 void* SetValueInThread(void* test_val_ptr) { | |
| 75 *reinterpret_cast<int*>(test_val_ptr) = kExpectedValue; | |
| 76 return NULL; | |
| 77 } | |
| 78 | |
| 79 BPF_TEST(NaClNonSfiSandboxTest, clone_by_pthread_create, | |
|
jln (very slow on Chromium)
2014/04/17 18:34:17
sandbox/linux/tests/unit_tests.h provides DISABLE_
hamaji
2014/04/17 19:13:43
Done.
| |
| 80 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 81 // clone call for thread creation is allowed. | |
| 82 pthread_t th; | |
| 83 int test_val = 42; | |
| 84 BPF_ASSERT_EQ(0, pthread_create(&th, NULL, &SetValueInThread, &test_val)); | |
| 85 BPF_ASSERT_EQ(0, pthread_join(th, NULL)); | |
| 86 BPF_ASSERT_EQ(kExpectedValue, test_val); | |
| 87 } | |
| 88 #endif | |
| 89 | |
| 90 int DoFork() { | |
| 91 // Call clone() to do a fork(). | |
| 92 const int pid = syscall(__NR_clone, SIGCHLD, NULL); | |
| 93 if (pid == 0) | |
| 94 _exit(0); | |
| 95 return pid; | |
| 96 } | |
| 97 | |
| 98 // The sanity check for DoFork without the sandbox. | |
| 99 TEST(NaClNonSfiSandboxTest, DoFork) { | |
| 100 const int pid = DoFork(); | |
| 101 ASSERT_LT(0, pid); | |
| 102 int status; | |
| 103 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0))); | |
| 104 ASSERT_TRUE(WIFEXITED(status)); | |
| 105 ASSERT_EQ(0, WEXITSTATUS(status)); | |
| 106 } | |
| 107 | |
| 108 // Then, try this in the sandbox. | |
| 109 BPF_DEATH_TEST(NaClNonSfiSandboxTest, clone_for_fork, | |
| 110 DEATH_MESSAGE(sandbox::GetCloneErrorMessageContentForTests()), | |
| 111 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 112 DoFork(); | |
| 113 } | |
| 114 | |
| 115 BPF_TEST(NaClNonSfiSandboxTest, prctl_SET_NAME, | |
| 116 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 117 errno = 0; | |
| 118 BPF_ASSERT_EQ(-1, syscall(__NR_prctl, PR_SET_NAME, "foo")); | |
| 119 BPF_ASSERT_EQ(EPERM, errno); | |
| 120 } | |
| 121 | |
| 122 BPF_DEATH_TEST(NaClNonSfiSandboxTest, prctl_SET_DUMPABLE, | |
| 123 DEATH_MESSAGE(sandbox::GetPrctlErrorMessageContentForTests()), | |
| 124 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 125 syscall(__NR_prctl, PR_SET_DUMPABLE, 1UL); | |
| 126 } | |
| 127 | |
| 128 BPF_TEST(NaClNonSfiSandboxTest, socketcall_allowed, | |
| 129 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 130 base::ScopedFD fds[2]; | |
| 131 struct msghdr msg = {}; | |
| 132 struct iovec iov; | |
| 133 std::string payload("foo"); | |
| 134 iov.iov_base = &payload[0]; | |
| 135 iov.iov_len = payload.size(); | |
| 136 msg.msg_iov = &iov; | |
| 137 msg.msg_iovlen = 1; | |
| 138 DoSocketpair(fds); | |
| 139 BPF_ASSERT_EQ(static_cast<int>(payload.size()), | |
| 140 HANDLE_EINTR(sendmsg(fds[1].get(), &msg, 0))); | |
| 141 BPF_ASSERT_EQ(static_cast<int>(payload.size()), | |
| 142 HANDLE_EINTR(recvmsg(fds[0].get(), &msg, 0))); | |
| 143 BPF_ASSERT_EQ(0, shutdown(fds[0].get(), SHUT_RDWR)); | |
| 144 } | |
| 145 | |
| 146 BPF_DEATH_TEST(NaClNonSfiSandboxTest, accept, | |
| 147 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 148 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 149 accept(0, NULL, NULL); | |
| 150 } | |
| 151 | |
| 152 BPF_DEATH_TEST(NaClNonSfiSandboxTest, bind, | |
| 153 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 154 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 155 bind(0, NULL, 0); | |
| 156 } | |
| 157 | |
| 158 BPF_DEATH_TEST(NaClNonSfiSandboxTest, connect, | |
| 159 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 160 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 161 connect(0, NULL, 0); | |
| 162 } | |
| 163 | |
| 164 BPF_DEATH_TEST(NaClNonSfiSandboxTest, getpeername, | |
| 165 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 166 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 167 getpeername(0, NULL, NULL); | |
| 168 } | |
| 169 | |
| 170 BPF_DEATH_TEST(NaClNonSfiSandboxTest, getsockname, | |
| 171 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 172 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 173 socklen_t addrlen = 0; | |
| 174 getsockname(0, NULL, &addrlen); | |
|
hamaji
2014/04/17 18:25:36
It seems ASan checks the memory the third argument
jln (very slow on Chromium)
2014/04/17 18:34:17
It probably doesn't hurt to make the second argume
hamaji
2014/04/17 19:13:43
Done.
| |
| 175 } | |
| 176 | |
| 177 BPF_DEATH_TEST(NaClNonSfiSandboxTest, getsockopt, | |
| 178 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 179 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 180 getsockopt(0, 0, 0, NULL, NULL); | |
| 181 } | |
| 182 | |
| 183 BPF_DEATH_TEST(NaClNonSfiSandboxTest, listen, | |
| 184 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 185 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 186 listen(0, 0); | |
| 187 } | |
| 188 | |
| 189 BPF_DEATH_TEST(NaClNonSfiSandboxTest, recv, | |
| 190 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 191 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 192 recv(0, NULL, 0, 0); | |
| 193 } | |
| 194 | |
| 195 BPF_DEATH_TEST(NaClNonSfiSandboxTest, recvfrom, | |
| 196 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 197 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 198 recvfrom(0, NULL, 0, 0, NULL, NULL); | |
| 199 } | |
| 200 | |
| 201 BPF_DEATH_TEST(NaClNonSfiSandboxTest, send, | |
| 202 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 203 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 204 send(0, NULL, 0, 0); | |
| 205 } | |
| 206 | |
| 207 BPF_DEATH_TEST(NaClNonSfiSandboxTest, sendto, | |
| 208 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 209 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 210 sendto(0, NULL, 0, 0, NULL, 0); | |
| 211 } | |
| 212 | |
| 213 BPF_DEATH_TEST(NaClNonSfiSandboxTest, setsockopt, | |
| 214 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 215 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 216 setsockopt(0, 0, 0, NULL, 0); | |
| 217 } | |
| 218 | |
| 219 BPF_DEATH_TEST(NaClNonSfiSandboxTest, socket, | |
| 220 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 221 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 222 socket(0, 0, 0); | |
| 223 } | |
| 224 | |
| 225 #if defined(__x86_64__) || defined(__arm__) | |
| 226 BPF_DEATH_TEST(NaClNonSfiSandboxTest, socketpair, | |
| 227 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 228 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 229 int fds[2]; | |
| 230 socketpair(AF_INET, SOCK_STREAM, 0, fds); | |
| 231 } | |
| 232 #endif | |
| 233 | |
| 234 BPF_TEST(NaClNonSfiSandboxTest, fcntl_SETFD_allowed, | |
| 235 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 236 base::ScopedFD fds[2]; | |
| 237 DoSocketpair(fds); | |
| 238 BPF_ASSERT_EQ(0, fcntl(fds[0].get(), F_SETFD, FD_CLOEXEC)); | |
| 239 } | |
| 240 | |
| 241 BPF_DEATH_TEST(NaClNonSfiSandboxTest, fcntl_SETFD, | |
| 242 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 243 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 244 base::ScopedFD fds[2]; | |
| 245 DoSocketpair(fds); | |
| 246 fcntl(fds[0].get(), F_SETFD, 99); | |
| 247 } | |
| 248 | |
| 249 BPF_TEST(NaClNonSfiSandboxTest, fcntl_GETFL_SETFL_allowed, | |
| 250 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 251 base::ScopedFD fds[2]; | |
| 252 DoPipe(fds); | |
| 253 const int fd = fds[0].get(); | |
| 254 BPF_ASSERT_EQ(0, fcntl(fd, F_GETFL)); | |
| 255 BPF_ASSERT_EQ(0, fcntl(fd, F_SETFL, O_RDWR | O_NONBLOCK)); | |
| 256 BPF_ASSERT_EQ(O_NONBLOCK, fcntl(fd, F_GETFL)); | |
| 257 } | |
| 258 | |
| 259 BPF_DEATH_TEST(NaClNonSfiSandboxTest, fcntl_GETFL_SETFL, | |
| 260 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 261 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 262 base::ScopedFD fds[2]; | |
| 263 DoSocketpair(fds); | |
| 264 fcntl(fds[0].get(), F_SETFL, O_APPEND); | |
| 265 } | |
| 266 | |
| 267 BPF_DEATH_TEST(NaClNonSfiSandboxTest, fcntl_DUPFD, | |
| 268 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 269 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 270 fcntl(0, F_DUPFD); | |
| 271 } | |
| 272 | |
| 273 BPF_DEATH_TEST(NaClNonSfiSandboxTest, fcntl_DUPFD_CLOEXEC, | |
| 274 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 275 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 276 fcntl(0, F_DUPFD_CLOEXEC); | |
| 277 } | |
| 278 | |
| 279 void* DoAllowedAnonymousMmap() { | |
| 280 return mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, | |
| 281 MAP_ANONYMOUS | MAP_SHARED, -1, 0); | |
| 282 } | |
| 283 | |
| 284 BPF_TEST(NaClNonSfiSandboxTest, mmap_allowed, | |
| 285 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 286 void* ptr = DoAllowedAnonymousMmap(); | |
| 287 BPF_ASSERT_NE(MAP_FAILED, ptr); | |
| 288 BPF_ASSERT_EQ(0, munmap(ptr, getpagesize())); | |
| 289 } | |
| 290 | |
| 291 BPF_DEATH_TEST(NaClNonSfiSandboxTest, mmap_unallowed_flag, | |
| 292 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 293 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 294 mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, | |
| 295 MAP_ANONYMOUS | MAP_POPULATE, -1, 0); | |
| 296 } | |
| 297 | |
| 298 BPF_DEATH_TEST(NaClNonSfiSandboxTest, mmap_unallowed_prot, | |
| 299 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 300 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 301 mmap(NULL, getpagesize(), PROT_READ | PROT_GROWSDOWN, | |
| 302 MAP_ANONYMOUS, -1, 0); | |
| 303 } | |
| 304 | |
| 305 // TODO(hamaji): Disallow RWX mmap. | |
| 306 #if 0 | |
| 307 BPF_DEATH_TEST(NaClNonSfiSandboxTest, mmap_rwx, | |
| 308 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 309 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 310 mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC, | |
| 311 MAP_ANONYMOUS, -1, 0); | |
| 312 } | |
| 313 #endif | |
| 314 | |
| 315 BPF_TEST(NaClNonSfiSandboxTest, mprotect_allowed, | |
| 316 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 317 void* ptr = DoAllowedAnonymousMmap(); | |
| 318 BPF_ASSERT_NE(MAP_FAILED, ptr); | |
| 319 BPF_ASSERT_EQ(0, mprotect(ptr, getpagesize(), PROT_READ)); | |
| 320 BPF_ASSERT_EQ(0, munmap(ptr, getpagesize())); | |
| 321 } | |
| 322 | |
| 323 BPF_DEATH_TEST(NaClNonSfiSandboxTest, mprotect_unallowed_prot, | |
| 324 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 325 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 326 // We have tested DoAllowedAnonymousMmap is allowed in | |
| 327 // mmap_allowed, so we can make sure the following mprotect call | |
| 328 // kills the process. | |
| 329 void* ptr = DoAllowedAnonymousMmap(); | |
| 330 BPF_ASSERT_NE(MAP_FAILED, ptr); | |
| 331 mprotect(ptr, getpagesize(), PROT_READ | PROT_GROWSDOWN); | |
| 332 } | |
| 333 | |
| 334 BPF_TEST(NaClNonSfiSandboxTest, brk, | |
| 335 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 336 char* next_brk = static_cast<char*>(sbrk(0)) + getpagesize(); | |
| 337 // The kernel interface must return zero for brk. | |
| 338 BPF_ASSERT_EQ(0, syscall(__NR_brk, next_brk)); | |
| 339 // The libc wrapper translates it to ENOMEM. | |
| 340 errno = 0; | |
| 341 BPF_ASSERT_EQ(-1, brk(next_brk)); | |
| 342 BPF_ASSERT_EQ(ENOMEM, errno); | |
| 343 } | |
| 344 | |
| 345 #if defined(__i386__) || defined(__arm__) | |
| 346 BPF_TEST(NaClNonSfiSandboxTest, getegid32_EPERM, | |
| 347 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 348 errno = 0; | |
| 349 BPF_ASSERT_EQ(-1, syscall(__NR_getegid32)); | |
| 350 BPF_ASSERT_EQ(EPERM, errno); | |
| 351 } | |
| 352 | |
| 353 BPF_TEST(NaClNonSfiSandboxTest, geteuid32_EPERM, | |
| 354 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 355 errno = 0; | |
| 356 BPF_ASSERT_EQ(-1, syscall(__NR_geteuid32)); | |
| 357 BPF_ASSERT_EQ(EPERM, errno); | |
| 358 } | |
| 359 | |
| 360 BPF_TEST(NaClNonSfiSandboxTest, getgid32_EPERM, | |
| 361 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 362 errno = 0; | |
| 363 BPF_ASSERT_EQ(-1, syscall(__NR_getgid32)); | |
| 364 BPF_ASSERT_EQ(EPERM, errno); | |
| 365 } | |
| 366 | |
| 367 BPF_TEST(NaClNonSfiSandboxTest, getuid32_EPERM, | |
| 368 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 369 errno = 0; | |
| 370 BPF_ASSERT_EQ(-1, syscall(__NR_getuid32)); | |
| 371 BPF_ASSERT_EQ(EPERM, errno); | |
| 372 } | |
| 373 | |
| 374 BPF_DEATH_TEST(NaClNonSfiSandboxTest, getegid_SIGSYS, | |
| 375 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 376 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 377 syscall(__NR_getegid); | |
| 378 } | |
| 379 | |
| 380 BPF_DEATH_TEST(NaClNonSfiSandboxTest, geteuid_SIGSYS, | |
| 381 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 382 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 383 syscall(__NR_geteuid); | |
| 384 } | |
| 385 | |
| 386 BPF_DEATH_TEST(NaClNonSfiSandboxTest, getgid_SIGSYS, | |
| 387 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 388 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 389 syscall(__NR_getgid); | |
| 390 } | |
| 391 | |
| 392 BPF_DEATH_TEST(NaClNonSfiSandboxTest, getuid_SIGSYS, | |
| 393 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 394 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 395 syscall(__NR_getuid); | |
| 396 } | |
| 397 #endif | |
| 398 | |
| 399 #if defined(__x86_64__) | |
| 400 BPF_TEST(NaClNonSfiSandboxTest, getegid_EPERM, | |
| 401 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 402 errno = 0; | |
| 403 BPF_ASSERT_EQ(-1, syscall(__NR_getegid)); | |
| 404 BPF_ASSERT_EQ(EPERM, errno); | |
| 405 } | |
| 406 | |
| 407 BPF_TEST(NaClNonSfiSandboxTest, geteuid_EPERM, | |
| 408 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 409 errno = 0; | |
| 410 BPF_ASSERT_EQ(-1, syscall(__NR_geteuid)); | |
| 411 BPF_ASSERT_EQ(EPERM, errno); | |
| 412 } | |
| 413 | |
| 414 BPF_TEST(NaClNonSfiSandboxTest, getgid_EPERM, | |
| 415 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 416 errno = 0; | |
| 417 BPF_ASSERT_EQ(-1, syscall(__NR_getgid)); | |
| 418 BPF_ASSERT_EQ(EPERM, errno); | |
| 419 } | |
| 420 | |
| 421 BPF_TEST(NaClNonSfiSandboxTest, getuid_EPERM, | |
| 422 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 423 errno = 0; | |
| 424 BPF_ASSERT_EQ(-1, syscall(__NR_getuid)); | |
| 425 BPF_ASSERT_EQ(EPERM, errno); | |
| 426 } | |
| 427 #endif | |
| 428 | |
| 429 BPF_TEST(NaClNonSfiSandboxTest, madvise_EPERM, | |
| 430 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 431 errno = 0; | |
| 432 BPF_ASSERT_EQ(-1, syscall(__NR_madvise)); | |
| 433 BPF_ASSERT_EQ(EPERM, errno); | |
| 434 } | |
| 435 | |
| 436 BPF_TEST(NaClNonSfiSandboxTest, open_EPERM, | |
| 437 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 438 errno = 0; | |
| 439 BPF_ASSERT_EQ(-1, syscall(__NR_open)); | |
| 440 BPF_ASSERT_EQ(EPERM, errno); | |
| 441 } | |
| 442 | |
| 443 BPF_TEST(NaClNonSfiSandboxTest, ptrace_EPERM, | |
| 444 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 445 errno = 0; | |
| 446 BPF_ASSERT_EQ(-1, syscall(__NR_ptrace)); | |
| 447 BPF_ASSERT_EQ(EPERM, errno); | |
| 448 } | |
| 449 | |
| 450 BPF_TEST(NaClNonSfiSandboxTest, set_robust_list_EPERM, | |
| 451 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 452 errno = 0; | |
| 453 BPF_ASSERT_EQ(-1, syscall(__NR_set_robust_list)); | |
| 454 BPF_ASSERT_EQ(EPERM, errno); | |
| 455 } | |
| 456 | |
| 457 #if defined(__i386__) || defined(__x86_64__) | |
| 458 BPF_TEST(NaClNonSfiSandboxTest, time_EPERM, | |
| 459 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { | |
| 460 errno = 0; | |
| 461 BPF_ASSERT_EQ(-1, syscall(__NR_time)); | |
| 462 BPF_ASSERT_EQ(EPERM, errno); | |
| 463 } | |
| 464 #endif | |
| 465 | |
| 466 } // namespace | |
| OLD | NEW |