Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: sandbox/linux/seccomp-bpf/demo.cc

Issue 10833044: Refactored ErrorCode into it's own class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased, and removed "protected" as requested by jln Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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::ErrorCode;
31 using playground2::Sandbox; 32 using playground2::Sandbox;
32 using playground2::Util; 33 using playground2::Util;
33 34
34 #define ERR EPERM 35 #define ERR EPERM
35 36
36 // We don't expect our sandbox to do anything useful yet. So, we will fail 37 // 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 38 // 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 39 // following line should be removed as soon as the sandbox is starting to
39 // actually enforce restrictions in a meaningful way: 40 // actually enforce restrictions in a meaningful way:
40 #define _exit(x) do { } while (0) 41 #define _exit(x) do { } while (0)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 129
129 ptr = strrchr(ptr, '\000'); 130 ptr = strrchr(ptr, '\000');
130 strncat(ptr, msg1, sizeof(buf) - (ptr - buf)); 131 strncat(ptr, msg1, sizeof(buf) - (ptr - buf));
131 132
132 ptr = strrchr(ptr, '\000'); 133 ptr = strrchr(ptr, '\000');
133 if (HANDLE_EINTR(write(2, buf, ptr - buf))) { } 134 if (HANDLE_EINTR(write(2, buf, ptr - buf))) { }
134 135
135 return -ERR; 136 return -ERR;
136 } 137 }
137 138
138 static Sandbox::ErrorCode evaluator(int sysno) { 139 static ErrorCode evaluator(int sysno) {
139 switch (sysno) { 140 switch (sysno) {
140 #if defined(__NR_accept) 141 #if defined(__NR_accept)
141 case __NR_accept: case __NR_accept4: 142 case __NR_accept: case __NR_accept4:
142 #endif 143 #endif
143 case __NR_alarm: 144 case __NR_alarm:
144 case __NR_brk: 145 case __NR_brk:
145 case __NR_clock_gettime: 146 case __NR_clock_gettime:
146 case __NR_close: 147 case __NR_close:
147 case __NR_dup: case __NR_dup2: 148 case __NR_dup: case __NR_dup2:
148 case __NR_epoll_create: case __NR_epoll_ctl: case __NR_epoll_wait: 149 case __NR_epoll_create: case __NR_epoll_ctl: case __NR_epoll_wait:
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 case __NR_rt_sigreturn: 214 case __NR_rt_sigreturn:
214 #if defined(__NR_sigreturn) 215 #if defined(__NR_sigreturn)
215 case __NR_sigreturn: 216 case __NR_sigreturn:
216 #endif 217 #endif
217 #if defined(__NR_socketpair) 218 #if defined(__NR_socketpair)
218 case __NR_socketpair: 219 case __NR_socketpair:
219 #endif 220 #endif
220 case __NR_time: 221 case __NR_time:
221 case __NR_uname: 222 case __NR_uname:
222 case __NR_write: case __NR_writev: 223 case __NR_write: case __NR_writev:
223 return Sandbox::SB_ALLOWED; 224 return ErrorCode::ERR_ALLOWED;
224 225
225 // The following system calls are temporarily permitted. This must be 226 // The following system calls are temporarily permitted. This must be
226 // tightened later. But we currently don't implement enough of the sandboxing 227 // tightened later. But we currently don't implement enough of the sandboxing
227 // API to do so. 228 // API to do so.
228 // As is, this sandbox isn't exactly safe :-/ 229 // As is, this sandbox isn't exactly safe :-/
229 #if defined(__NR_sendmsg) 230 #if defined(__NR_sendmsg)
230 case __NR_sendmsg: case __NR_sendto: 231 case __NR_sendmsg: case __NR_sendto:
231 case __NR_recvmsg: case __NR_recvfrom: 232 case __NR_recvmsg: case __NR_recvfrom:
232 case __NR_getsockopt: case __NR_setsockopt: 233 case __NR_getsockopt: case __NR_setsockopt:
233 #elif defined(__NR_socketcall) 234 #elif defined(__NR_socketcall)
(...skipping 11 matching lines...) Expand all
245 #endif 246 #endif
246 #if defined(__NR_ugetrlimit) 247 #if defined(__NR_ugetrlimit)
247 case __NR_ugetrlimit: 248 case __NR_ugetrlimit:
248 #endif 249 #endif
249 case __NR_getrlimit: 250 case __NR_getrlimit:
250 case __NR_ioctl: 251 case __NR_ioctl:
251 case __NR_prctl: 252 case __NR_prctl:
252 case __NR_clone: 253 case __NR_clone:
253 case __NR_munmap: case __NR_mprotect: case __NR_madvise: 254 case __NR_munmap: case __NR_mprotect: case __NR_madvise:
254 case __NR_remap_file_pages: 255 case __NR_remap_file_pages:
255 return Sandbox::SB_ALLOWED; 256 return ErrorCode::ERR_ALLOWED;
256 257
257 // Everything that isn't explicitly allowed is denied. 258 // Everything that isn't explicitly allowed is denied.
258 default: 259 default:
259 return Sandbox::ErrorCode(defaultHandler, NULL); 260 return Sandbox::Trap(defaultHandler, NULL);
260 } 261 }
261 } 262 }
262 263
263 static void *threadFnc(void *arg) { 264 static void *threadFnc(void *arg) {
264 return arg; 265 return arg;
265 } 266 }
266 267
267 static void *sendmsgStressThreadFnc(void *arg) { 268 static void *sendmsgStressThreadFnc(void *arg) {
268 if (arg) { } 269 if (arg) { }
269 static const int repetitions = 100; 270 static const int repetitions = 100;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 perror("pthread_create"); 404 perror("pthread_create");
404 _exit(1); 405 _exit(1);
405 } 406 }
406 } 407 }
407 for (int i = 0; i < kSendmsgStressNumThreads; ++i) { 408 for (int i = 0; i < kSendmsgStressNumThreads; ++i) {
408 pthread_join(sendmsgStressThreads[i], NULL); 409 pthread_join(sendmsgStressThreads[i], NULL);
409 } 410 }
410 411
411 return 0; 412 return 0;
412 } 413 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698