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

Side by Side Diff: content/common/sandbox_init_linux.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, 4 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
« no previous file with comments | « no previous file | sandbox/linux/sandbox_linux.gypi » ('j') | sandbox/linux/seccomp-bpf/errorcode.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/public/common/sandbox_init.h" 5 #include "content/public/common/sandbox_init.h"
6 6
7 #if defined(__i386__) || defined(__x86_64__) 7 #if defined(__i386__) || defined(__x86_64__)
8 8
9 // This is an assert for GYP 9 // This is an assert for GYP
10 #if !defined(OS_LINUX) 10 #if !defined(OS_LINUX)
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 if (strcmp(pathname, kDriRcPath) == 0) { 209 if (strcmp(pathname, kDriRcPath) == 0) {
210 int ret = OpenWithCache(pathname, flags); 210 int ret = OpenWithCache(pathname, flags);
211 return (ret == -1) ? -errno : ret; 211 return (ret == -1) ? -errno : ret;
212 } else { 212 } else {
213 return -ENOENT; 213 return -ENOENT;
214 } 214 }
215 } 215 }
216 216
217 #if defined(__x86_64__) 217 #if defined(__x86_64__)
218 // x86_64 only because it references system calls that are multiplexed on IA32. 218 // x86_64 only because it references system calls that are multiplexed on IA32.
219 playground2::Sandbox::ErrorCode GpuProcessPolicy_x86_64(int sysno) { 219 playground2::ErrorCode GpuProcessPolicy_x86_64(int sysno) {
220 switch(sysno) { 220 switch(sysno) {
221 case __NR_read: 221 case __NR_read:
222 case __NR_ioctl: 222 case __NR_ioctl:
223 case __NR_poll: 223 case __NR_poll:
224 case __NR_epoll_wait: 224 case __NR_epoll_wait:
225 case __NR_recvfrom: 225 case __NR_recvfrom:
226 case __NR_write: 226 case __NR_write:
227 case __NR_writev: 227 case __NR_writev:
228 case __NR_gettid: 228 case __NR_gettid:
229 case __NR_sched_yield: // Nvidia binary driver. 229 case __NR_sched_yield: // Nvidia binary driver.
(...skipping 27 matching lines...) Expand all
257 case __NR_dup: 257 case __NR_dup:
258 case __NR_mlock: 258 case __NR_mlock:
259 case __NR_munlock: 259 case __NR_munlock:
260 case __NR_exit: 260 case __NR_exit:
261 case __NR_exit_group: 261 case __NR_exit_group:
262 case __NR_lseek: 262 case __NR_lseek:
263 case __NR_getpid: // Nvidia binary driver. 263 case __NR_getpid: // Nvidia binary driver.
264 case __NR_getppid: // ATI binary driver. 264 case __NR_getppid: // ATI binary driver.
265 case __NR_shutdown: // Virtual driver. 265 case __NR_shutdown: // Virtual driver.
266 case __NR_rt_sigaction: // Breakpad signal handler. 266 case __NR_rt_sigaction: // Breakpad signal handler.
267 return playground2::Sandbox::SB_ALLOWED; 267 return playground2::ErrorCode::ERR_ALLOWED;
268 case __NR_socket: 268 case __NR_socket:
269 return EACCES; // Nvidia binary driver. 269 return EACCES; // Nvidia binary driver.
270 case __NR_fchmod: 270 case __NR_fchmod:
271 return EPERM; // ATI binary driver. 271 return EPERM; // ATI binary driver.
272 case __NR_open: 272 case __NR_open:
273 // Hook open() in the GPU process to allow opening /etc/drirc, 273 // Hook open() in the GPU process to allow opening /etc/drirc,
274 // needed by Mesa. 274 // needed by Mesa.
275 // The hook needs dup(), lseek(), and close() to be allowed. 275 // The hook needs dup(), lseek(), and close() to be allowed.
276 return playground2::Sandbox::ErrorCode(GpuOpenSIGSYS_Handler, NULL); 276 return playground2::Sandbox::Trap(GpuOpenSIGSYS_Handler, NULL);
277 default: 277 default:
278 if (IsGettimeSyscall(sysno) || 278 if (IsGettimeSyscall(sysno) ||
279 IsKillSyscall(sysno)) { // GPU watchdog. 279 IsKillSyscall(sysno)) { // GPU watchdog.
280 return playground2::Sandbox::SB_ALLOWED; 280 return playground2::ErrorCode::ERR_ALLOWED;
281 } 281 }
282 // Generally, filename-based syscalls will fail with ENOENT to behave 282 // Generally, filename-based syscalls will fail with ENOENT to behave
283 // similarly to a possible future setuid sandbox. 283 // similarly to a possible future setuid sandbox.
284 if (IsFileSystemSyscall(sysno)) { 284 if (IsFileSystemSyscall(sysno)) {
285 return ENOENT; 285 return ENOENT;
286 } 286 }
287 // In any other case crash the program with our SIGSYS handler 287 // In any other case crash the program with our SIGSYS handler
288 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); 288 return playground2::Sandbox::Trap(CrashSIGSYS_Handler, NULL);
289 } 289 }
290 } 290 }
291 291
292 // x86_64 only because it references system calls that are multiplexed on IA32. 292 // x86_64 only because it references system calls that are multiplexed on IA32.
293 playground2::Sandbox::ErrorCode FlashProcessPolicy_x86_64(int sysno) { 293 playground2::ErrorCode FlashProcessPolicy_x86_64(int sysno) {
294 switch (sysno) { 294 switch (sysno) {
295 case __NR_futex: 295 case __NR_futex:
296 case __NR_write: 296 case __NR_write:
297 case __NR_epoll_wait: 297 case __NR_epoll_wait:
298 case __NR_read: 298 case __NR_read:
299 case __NR_times: 299 case __NR_times:
300 case __NR_clone: // TODO(jln): restrict flags. 300 case __NR_clone: // TODO(jln): restrict flags.
301 case __NR_set_robust_list: 301 case __NR_set_robust_list:
302 case __NR_getuid: 302 case __NR_getuid:
303 case __NR_geteuid: 303 case __NR_geteuid:
(...skipping 25 matching lines...) Expand all
329 case __NR_brk: 329 case __NR_brk:
330 case __NR_sched_yield: 330 case __NR_sched_yield:
331 case __NR_shutdown: 331 case __NR_shutdown:
332 case __NR_sched_getaffinity: 332 case __NR_sched_getaffinity:
333 case __NR_sched_setscheduler: 333 case __NR_sched_setscheduler:
334 case __NR_dup: // Flash Access. 334 case __NR_dup: // Flash Access.
335 // These are under investigation, and hopefully not here for the long term. 335 // These are under investigation, and hopefully not here for the long term.
336 case __NR_shmctl: 336 case __NR_shmctl:
337 case __NR_shmat: 337 case __NR_shmat:
338 case __NR_shmdt: 338 case __NR_shmdt:
339 return playground2::Sandbox::SB_ALLOWED; 339 return playground2::ErrorCode::ERR_ALLOWED;
340 case __NR_ioctl: 340 case __NR_ioctl:
341 return ENOTTY; // Flash Access. 341 return ENOTTY; // Flash Access.
342 case __NR_socket: 342 case __NR_socket:
343 return EACCES; 343 return EACCES;
344 344
345 default: 345 default:
346 if (IsGettimeSyscall(sysno) || 346 if (IsGettimeSyscall(sysno) ||
347 IsKillSyscall(sysno)) { 347 IsKillSyscall(sysno)) {
348 return playground2::Sandbox::SB_ALLOWED; 348 return playground2::ErrorCode::ERR_ALLOWED;
349 } 349 }
350 if (IsFileSystemSyscall(sysno)) { 350 if (IsFileSystemSyscall(sysno)) {
351 return ENOENT; 351 return ENOENT;
352 } 352 }
353 // In any other case crash the program with our SIGSYS handler. 353 // In any other case crash the program with our SIGSYS handler.
354 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); 354 return playground2::Sandbox::Trap(CrashSIGSYS_Handler, NULL);
355 } 355 }
356 } 356 }
357 #endif 357 #endif
358 358
359 playground2::Sandbox::ErrorCode BlacklistPtracePolicy(int sysno) { 359 playground2::ErrorCode BlacklistPtracePolicy(int sysno) {
360 if (sysno < static_cast<int>(MIN_SYSCALL) || 360 if (sysno < static_cast<int>(MIN_SYSCALL) ||
361 sysno > static_cast<int>(MAX_SYSCALL)) { 361 sysno > static_cast<int>(MAX_SYSCALL)) {
362 // TODO(jln) we should not have to do that in a trivial policy. 362 // TODO(jln) we should not have to do that in a trivial policy.
363 return ENOSYS; 363 return ENOSYS;
364 } 364 }
365 switch (sysno) { 365 switch (sysno) {
366 case __NR_ptrace: 366 case __NR_ptrace:
367 case __NR_process_vm_readv: 367 case __NR_process_vm_readv:
368 case __NR_process_vm_writev: 368 case __NR_process_vm_writev:
369 case __NR_migrate_pages: 369 case __NR_migrate_pages:
370 case __NR_move_pages: 370 case __NR_move_pages:
371 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); 371 return playground2::Sandbox::Trap(CrashSIGSYS_Handler, NULL);
372 default: 372 default:
373 return playground2::Sandbox::SB_ALLOWED; 373 return playground2::ErrorCode::ERR_ALLOWED;
374 } 374 }
375 } 375 }
376 376
377 // Allow all syscalls. 377 // Allow all syscalls.
378 // This will still deny x32 or IA32 calls in 64 bits mode or 378 // This will still deny x32 or IA32 calls in 64 bits mode or
379 // 64 bits system calls in compatibility mode. 379 // 64 bits system calls in compatibility mode.
380 playground2::Sandbox::ErrorCode AllowAllPolicy(int sysno) { 380 playground2::ErrorCode AllowAllPolicy(int sysno) {
381 if (sysno < static_cast<int>(MIN_SYSCALL) || 381 if (sysno < static_cast<int>(MIN_SYSCALL) ||
382 sysno > static_cast<int>(MAX_SYSCALL)) { 382 sysno > static_cast<int>(MAX_SYSCALL)) {
383 // TODO(jln) we should not have to do that in a trivial policy. 383 // TODO(jln) we should not have to do that in a trivial policy.
384 return ENOSYS; 384 return ENOSYS;
385 } else { 385 } else {
386 return playground2::Sandbox::SB_ALLOWED; 386 return playground2::ErrorCode::ERR_ALLOWED;
387 } 387 }
388 } 388 }
389 389
390 // Warms up/preloads resources needed by the policies. 390 // Warms up/preloads resources needed by the policies.
391 void WarmupPolicy(playground2::Sandbox::EvaluateSyscall policy) { 391 void WarmupPolicy(playground2::Sandbox::EvaluateSyscall policy) {
392 #if defined(__x86_64__) 392 #if defined(__x86_64__)
393 if (policy == GpuProcessPolicy_x86_64) 393 if (policy == GpuProcessPolicy_x86_64)
394 OpenWithCache(kDriRcPath, O_RDONLY); 394 OpenWithCache(kDriRcPath, O_RDONLY);
395 #endif 395 #endif
396 } 396 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 526
527 namespace content { 527 namespace content {
528 528
529 void InitializeSandbox() { 529 void InitializeSandbox() {
530 #if defined(__i386__) || defined(__x86_64__) 530 #if defined(__i386__) || defined(__x86_64__)
531 InitializeSandbox_x86(); 531 InitializeSandbox_x86();
532 #endif 532 #endif
533 } 533 }
534 534
535 } // namespace content 535 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | sandbox/linux/sandbox_linux.gypi » ('j') | sandbox/linux/seccomp-bpf/errorcode.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698