| 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <fcntl.h> | 6 #include <fcntl.h> |
| 7 #include <linux/unistd.h> | 7 #include <linux/unistd.h> |
| 8 #include <netinet/in.h> | 8 #include <netinet/in.h> |
| 9 #include <netinet/tcp.h> | 9 #include <netinet/tcp.h> |
| 10 #include <netinet/udp.h> | 10 #include <netinet/udp.h> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include <sys/shm.h> | 21 #include <sys/shm.h> |
| 22 #include <sys/socket.h> | 22 #include <sys/socket.h> |
| 23 #include <sys/time.h> | 23 #include <sys/time.h> |
| 24 #include <sys/types.h> | 24 #include <sys/types.h> |
| 25 #include <time.h> | 25 #include <time.h> |
| 26 #include <unistd.h> | 26 #include <unistd.h> |
| 27 | 27 |
| 28 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 28 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
| 29 #include "sandbox/linux/seccomp-bpf/util.h" | 29 #include "sandbox/linux/seccomp-bpf/util.h" |
| 30 | 30 |
| 31 using playground2::arch_seccomp_data; |
| 32 using playground2::ErrorCode; |
| 31 using playground2::Sandbox; | 33 using playground2::Sandbox; |
| 32 using playground2::Util; | 34 using playground2::Util; |
| 33 | 35 |
| 34 #define ERR EPERM | 36 #define ERR EPERM |
| 35 | 37 |
| 36 // We don't expect our sandbox to do anything useful yet. So, we will fail | 38 // We don't expect our sandbox to do anything useful yet. So, we will fail |
| 37 // almost immediately. For now, force the code to continue running. The | 39 // almost immediately. For now, force the code to continue running. The |
| 38 // following line should be removed as soon as the sandbox is starting to | 40 // following line should be removed as soon as the sandbox is starting to |
| 39 // actually enforce restrictions in a meaningful way: | 41 // actually enforce restrictions in a meaningful way: |
| 40 #define _exit(x) do { } while (0) | 42 #define _exit(x) do { } while (0) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 130 |
| 129 ptr = strrchr(ptr, '\000'); | 131 ptr = strrchr(ptr, '\000'); |
| 130 strncat(ptr, msg1, sizeof(buf) - (ptr - buf)); | 132 strncat(ptr, msg1, sizeof(buf) - (ptr - buf)); |
| 131 | 133 |
| 132 ptr = strrchr(ptr, '\000'); | 134 ptr = strrchr(ptr, '\000'); |
| 133 if (HANDLE_EINTR(write(2, buf, ptr - buf))) { } | 135 if (HANDLE_EINTR(write(2, buf, ptr - buf))) { } |
| 134 | 136 |
| 135 return -ERR; | 137 return -ERR; |
| 136 } | 138 } |
| 137 | 139 |
| 138 static Sandbox::ErrorCode evaluator(int sysno) { | 140 static ErrorCode evaluator(int sysno) { |
| 139 switch (sysno) { | 141 switch (sysno) { |
| 140 #if defined(__NR_accept) | 142 #if defined(__NR_accept) |
| 141 case __NR_accept: case __NR_accept4: | 143 case __NR_accept: case __NR_accept4: |
| 142 #endif | 144 #endif |
| 143 case __NR_alarm: | 145 case __NR_alarm: |
| 144 case __NR_brk: | 146 case __NR_brk: |
| 145 case __NR_clock_gettime: | 147 case __NR_clock_gettime: |
| 146 case __NR_close: | 148 case __NR_close: |
| 147 case __NR_dup: case __NR_dup2: | 149 case __NR_dup: case __NR_dup2: |
| 148 case __NR_epoll_create: case __NR_epoll_ctl: case __NR_epoll_wait: | 150 case __NR_epoll_create: case __NR_epoll_ctl: case __NR_epoll_wait: |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 case __NR_rt_sigreturn: | 215 case __NR_rt_sigreturn: |
| 214 #if defined(__NR_sigreturn) | 216 #if defined(__NR_sigreturn) |
| 215 case __NR_sigreturn: | 217 case __NR_sigreturn: |
| 216 #endif | 218 #endif |
| 217 #if defined(__NR_socketpair) | 219 #if defined(__NR_socketpair) |
| 218 case __NR_socketpair: | 220 case __NR_socketpair: |
| 219 #endif | 221 #endif |
| 220 case __NR_time: | 222 case __NR_time: |
| 221 case __NR_uname: | 223 case __NR_uname: |
| 222 case __NR_write: case __NR_writev: | 224 case __NR_write: case __NR_writev: |
| 223 return Sandbox::SB_ALLOWED; | 225 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 224 | 226 |
| 225 // The following system calls are temporarily permitted. This must be | 227 // The following system calls are temporarily permitted. This must be |
| 226 // tightened later. But we currently don't implement enough of the sandboxing | 228 // tightened later. But we currently don't implement enough of the sandboxing |
| 227 // API to do so. | 229 // API to do so. |
| 228 // As is, this sandbox isn't exactly safe :-/ | 230 // As is, this sandbox isn't exactly safe :-/ |
| 229 #if defined(__NR_sendmsg) | 231 #if defined(__NR_sendmsg) |
| 230 case __NR_sendmsg: case __NR_sendto: | 232 case __NR_sendmsg: case __NR_sendto: |
| 231 case __NR_recvmsg: case __NR_recvfrom: | 233 case __NR_recvmsg: case __NR_recvfrom: |
| 232 case __NR_getsockopt: case __NR_setsockopt: | 234 case __NR_getsockopt: case __NR_setsockopt: |
| 233 #elif defined(__NR_socketcall) | 235 #elif defined(__NR_socketcall) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 245 #endif | 247 #endif |
| 246 #if defined(__NR_ugetrlimit) | 248 #if defined(__NR_ugetrlimit) |
| 247 case __NR_ugetrlimit: | 249 case __NR_ugetrlimit: |
| 248 #endif | 250 #endif |
| 249 case __NR_getrlimit: | 251 case __NR_getrlimit: |
| 250 case __NR_ioctl: | 252 case __NR_ioctl: |
| 251 case __NR_prctl: | 253 case __NR_prctl: |
| 252 case __NR_clone: | 254 case __NR_clone: |
| 253 case __NR_munmap: case __NR_mprotect: case __NR_madvise: | 255 case __NR_munmap: case __NR_mprotect: case __NR_madvise: |
| 254 case __NR_remap_file_pages: | 256 case __NR_remap_file_pages: |
| 255 return Sandbox::SB_ALLOWED; | 257 return ErrorCode(ErrorCode::ERR_ALLOWED); |
| 256 | 258 |
| 257 // Everything that isn't explicitly allowed is denied. | 259 // Everything that isn't explicitly allowed is denied. |
| 258 default: | 260 default: |
| 259 return Sandbox::ErrorCode(defaultHandler, NULL); | 261 return Sandbox::Trap(defaultHandler, NULL); |
| 260 } | 262 } |
| 261 } | 263 } |
| 262 | 264 |
| 263 static void *threadFnc(void *arg) { | 265 static void *threadFnc(void *arg) { |
| 264 return arg; | 266 return arg; |
| 265 } | 267 } |
| 266 | 268 |
| 267 static void *sendmsgStressThreadFnc(void *arg) { | 269 static void *sendmsgStressThreadFnc(void *arg) { |
| 268 if (arg) { } | 270 if (arg) { } |
| 269 static const int repetitions = 100; | 271 static const int repetitions = 100; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 perror("pthread_create"); | 405 perror("pthread_create"); |
| 404 _exit(1); | 406 _exit(1); |
| 405 } | 407 } |
| 406 } | 408 } |
| 407 for (int i = 0; i < kSendmsgStressNumThreads; ++i) { | 409 for (int i = 0; i < kSendmsgStressNumThreads; ++i) { |
| 408 pthread_join(sendmsgStressThreads[i], NULL); | 410 pthread_join(sendmsgStressThreads[i], NULL); |
| 409 } | 411 } |
| 410 | 412 |
| 411 return 0; | 413 return 0; |
| 412 } | 414 } |
| OLD | NEW |