OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef SANDBOX_IMPL_H__ | 5 #ifndef SANDBOX_IMPL_H__ |
6 #define SANDBOX_IMPL_H__ | 6 #define SANDBOX_IMPL_H__ |
7 | 7 |
8 #include <asm/ldt.h> | 8 #include <asm/ldt.h> |
9 #include <errno.h> | 9 #include <errno.h> |
10 #include <fcntl.h> | 10 #include <fcntl.h> |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 class Sandbox { | 65 class Sandbox { |
66 // TODO(markus): restrict access to our private file handles | 66 // TODO(markus): restrict access to our private file handles |
67 public: | 67 public: |
68 enum { kMaxThreads = 100 }; | 68 enum { kMaxThreads = 100 }; |
69 | 69 |
70 | 70 |
71 // There are a lot of reasons why the Seccomp sandbox might not be available. | 71 // There are a lot of reasons why the Seccomp sandbox might not be available. |
72 // This could be because the kernel does not support Seccomp mode, or it | 72 // This could be because the kernel does not support Seccomp mode, or it |
73 // could be because we fail to successfully rewrite all system call entry | 73 // could be because we fail to successfully rewrite all system call entry |
74 // points. | 74 // points. |
75 // "proc_fd" should be a file descriptor for "/proc", or -1 if not provided | 75 // "proc_self" should be a file descriptor for "/proc/self", or -1 if not |
76 // by the caller. | 76 // provided by the caller. |
77 static int supportsSeccompSandbox(int proc_fd) | 77 static int supportsSeccompSandbox(int proc_self) |
78 asm("SupportsSeccompSandbox"); | 78 asm("SupportsSeccompSandbox"); |
79 | 79 |
80 // The sandbox needs to be able to access "/proc/self/maps". If this file | 80 // The sandbox needs to be able to access "/proc/self/maps". If this file |
81 // is not accessible when "startSandbox()" gets called, the caller can | 81 // is not accessible when "startSandbox()" gets called, the caller can |
82 // provide an already opened file descriptor by calling "setProcSelfMaps()". | 82 // provide an already opened file descriptor by calling "setProcSelf()". |
83 // The sandbox becomes the newer owner of this file descriptor and will | 83 // The sandbox becomes the newer owner of this file descriptor and will |
84 // eventually close it when "startSandbox()" executes. | 84 // eventually close it when "startSandbox()" executes. But if the caller |
85 static void setProcSelfMaps(int proc_self_maps) | 85 // never ends up calling startSandbox(), then the caller must close the |
86 asm("SeccompSandboxSetProcSelfMaps"); | 86 // file descriptor. |
| 87 static void setProcSelf(int proc_self) asm("SeccompSandboxSetProcSelf"); |
87 | 88 |
88 // This is the main public entry point. It finds all system calls that | 89 // This is the main public entry point. It finds all system calls that |
89 // need rewriting, sets up the resources needed by the sandbox, and | 90 // need rewriting, sets up the resources needed by the sandbox, and |
90 // enters Seccomp mode. | 91 // enters Seccomp mode. |
91 static void startSandbox() asm("StartSeccompSandbox"); | 92 static void startSandbox() asm("StartSeccompSandbox"); |
92 | 93 |
93 // TODO(mseaborn): Consider re-instating this declaration. | 94 // TODO(mseaborn): Consider re-instating this declaration. |
94 // private: | 95 // private: |
95 | 96 |
96 struct RequestHeader { | 97 struct RequestHeader { |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 __attribute__((noreturn)); | 636 __attribute__((noreturn)); |
636 | 637 |
637 // Fork()s of the trusted process. | 638 // Fork()s of the trusted process. |
638 static SecureMem::Args* createTrustedProcess(int processFdPub, int sandboxFd, | 639 static SecureMem::Args* createTrustedProcess(int processFdPub, int sandboxFd, |
639 int cloneFdPub, int cloneFd); | 640 int cloneFdPub, int cloneFd); |
640 | 641 |
641 // Creates the trusted thread for the initial thread, then enables | 642 // Creates the trusted thread for the initial thread, then enables |
642 // Seccomp mode. | 643 // Seccomp mode. |
643 static void createTrustedThread(SecureMem::Args* secureMem); | 644 static void createTrustedThread(SecureMem::Args* secureMem); |
644 | 645 |
| 646 static int proc_self_; |
645 static int proc_self_maps_; | 647 static int proc_self_maps_; |
646 static enum SandboxStatus { | 648 static enum SandboxStatus { |
647 STATUS_UNKNOWN, STATUS_UNSUPPORTED, STATUS_AVAILABLE, STATUS_ENABLED | 649 STATUS_UNKNOWN, STATUS_UNSUPPORTED, STATUS_AVAILABLE, STATUS_ENABLED |
648 } status_; | 650 } status_; |
649 static int pid_; | 651 static int pid_; |
650 static int processFdPub_; | 652 static int processFdPub_; |
651 static int cloneFdPub_ asm("playground$cloneFdPub") INTERNAL; | 653 static int cloneFdPub_ asm("playground$cloneFdPub") INTERNAL; |
652 | 654 |
653 #ifdef __i386__ | 655 #ifdef __i386__ |
654 struct SocketCallArgInfo; | 656 struct SocketCallArgInfo; |
(...skipping 25 matching lines...) Expand all Loading... |
680 extern struct SandboxPolicy g_policy; | 682 extern struct SandboxPolicy g_policy; |
681 | 683 |
682 typedef void (*CreateTrustedThreadFunc)(SecureMem::Args* secureMem); | 684 typedef void (*CreateTrustedThreadFunc)(SecureMem::Args* secureMem); |
683 extern CreateTrustedThreadFunc g_create_trusted_thread; | 685 extern CreateTrustedThreadFunc g_create_trusted_thread; |
684 | 686 |
685 } // namespace | 687 } // namespace |
686 | 688 |
687 using playground::Sandbox; | 689 using playground::Sandbox; |
688 | 690 |
689 #endif // SANDBOX_IMPL_H__ | 691 #endif // SANDBOX_IMPL_H__ |
OLD | NEW |