Chromium Code Reviews| 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 #ifndef CONTENT_COMMON_SANDBOX_LINUX_H_ | 5 #ifndef CONTENT_COMMON_SANDBOX_LINUX_H_ |
| 6 #define CONTENT_COMMON_SANDBOX_LINUX_H_ | 6 #define CONTENT_COMMON_SANDBOX_LINUX_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 METHOD_GET_CHILD_WITH_INODE = 34, | 30 METHOD_GET_CHILD_WITH_INODE = 34, |
| 31 METHOD_GET_STYLE_FOR_STRIKE = 35, | 31 METHOD_GET_STYLE_FOR_STRIKE = 35, |
| 32 METHOD_MAKE_SHARED_MEMORY_SEGMENT = 36, | 32 METHOD_MAKE_SHARED_MEMORY_SEGMENT = 36, |
| 33 METHOD_MATCH_WITH_FALLBACK = 37, | 33 METHOD_MATCH_WITH_FALLBACK = 37, |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 // Get our singleton instance. | 36 // Get our singleton instance. |
| 37 static LinuxSandbox* GetInstance(); | 37 static LinuxSandbox* GetInstance(); |
| 38 | 38 |
| 39 // Do some initialization that can only be done before any of the sandboxes | 39 // Do some initialization that can only be done before any of the sandboxes |
| 40 // is enabled. | 40 // is enabled. If using the setuid sandbox, this should be called manually |
|
palmer
2013/04/30 21:21:59
Typo: "are enabled".
jln (very slow on Chromium)
2013/04/30 22:09:51
Done.
| |
| 41 // | 41 // before the setuid sandbox is engaged. |
| 42 // There are two versions of this function. One takes a process_type | 42 void PreinitializeSandbox(); |
| 43 // as an argument, the other doesn't. | |
| 44 // It may be necessary to call PreinitializeSandboxBegin before knowing the | |
| 45 // process type (this is for instance the case with the Zygote). | |
| 46 // In that case, it is crucial that PreinitializeSandboxFinish() gets | |
| 47 // called for every child process. | |
| 48 // TODO(markus, jln) we know this is not always done at the moment | |
| 49 // (crbug.com/139877). | |
| 50 void PreinitializeSandbox(const std::string& process_type); | |
| 51 // These should be called together. | |
| 52 void PreinitializeSandboxBegin(); | |
| 53 void PreinitializeSandboxFinish(const std::string& process_type); | |
| 54 | 43 |
| 55 // Initialize the sandbox with the given pre-built configuration. Currently | 44 // Initialize the sandbox with the given pre-built configuration. Currently |
| 56 // seccomp-bpf and address space limitations (the setuid sandbox works | 45 // seccomp-bpf and address space limitations (the setuid sandbox works |
| 57 // differently and is set-up in the Zygote). This will instantiate the | 46 // differently and is set-up in the Zygote). This will instantiate the |
| 58 // LinuxSandbox singleton if it doesn't already exist. | 47 // LinuxSandbox singleton if it doesn't already exist. |
| 59 static bool InitializeSandbox(); | 48 static bool InitializeSandbox(); |
| 60 | 49 |
| 61 // Returns the Status of the renderers' sandbox. Can only be queried if we | 50 // Returns the Status of the renderers' sandbox. Can only be queried after |
| 62 // went through PreinitializeSandbox() or PreinitializeSandboxBegin(). This | 51 // going through PreinitializeSandbox(). This is a bitmask and uses the |
| 63 // is a bitmask and uses the constants defined in "enum LinuxSandboxStatus". | 52 // constants defined in "enum LinuxSandboxStatus". Since the status needs to |
|
palmer
2013/04/30 21:21:59
It would therefore be better to declare this funct
jln (very slow on Chromium)
2013/04/30 22:09:51
No, unfortunately it has to return an int. It's a
| |
| 64 // Since we need to provide the status before the sandboxes are actually | 53 // be provided before the sandboxes are actually started, this returns what |
| 65 // started, this returns what will actually happen once the various Start* | 54 // will actually happen once the various Start* functions are called from |
| 66 // functions are called from inside a renderer. | 55 // inside a renderer. |
| 67 int GetStatus() const; | 56 int GetStatus() const; |
| 68 // Is the current process single threaded? | 57 // Is the current process single threaded? Will return "true" if it cannot be |
|
palmer
2013/04/30 21:21:59
NIT: Blank lines between each declaration.
palmer
2013/04/30 21:21:59
NIT: Simplify this documentation:
Returns true if
jln (very slow on Chromium)
2013/04/30 22:09:51
Vertical space is only required between different
jln (very slow on Chromium)
2013/04/30 22:09:51
Done.
| |
| 58 // determined. | |
| 69 bool IsSingleThreaded() const; | 59 bool IsSingleThreaded() const; |
| 70 // Did we start Seccomp BPF? | 60 // Did we start Seccomp BPF? |
| 71 bool seccomp_bpf_started() const; | 61 bool seccomp_bpf_started() const; |
| 72 | 62 |
| 73 // Simple accessor for our instance of the setuid sandbox. Will never return | 63 // Simple accessor for our instance of the setuid sandbox. Will never return |
| 74 // NULL. | 64 // NULL. |
| 75 // There is no StartSetuidSandbox(), the SetuidSandboxClient instance should | 65 // There is no StartSetuidSandbox(), the SetuidSandboxClient instance should |
| 76 // be used directly. | 66 // be used directly. |
| 77 sandbox::SetuidSandboxClient* setuid_sandbox_client() const; | 67 sandbox::SetuidSandboxClient* setuid_sandbox_client() const; |
| 78 | 68 |
| 79 // Check the policy and eventually start the seccomp-bpf sandbox. This should | 69 // Check the policy and eventually start the seccomp-bpf sandbox. This should |
| 80 // never be called with threads started. If we detect that thread have | 70 // never be called with threads started. If we detect that thread have |
|
palmer
2013/04/30 21:21:59
Typo: "...detect that threads have..."
jln (very slow on Chromium)
2013/04/30 22:09:51
Done.
| |
| 81 // started we will crash. | 71 // started we will crash. |
| 82 bool StartSeccompBpf(const std::string& process_type); | 72 bool StartSeccompBpf(const std::string& process_type); |
| 83 | 73 |
| 84 // Limit the address space of the current process (and its children). | 74 // Limit the address space of the current process (and its children). |
| 85 // to make some vulnerabilities harder to exploit. | 75 // to make some vulnerabilities harder to exploit. |
| 86 bool LimitAddressSpace(const std::string& process_type); | 76 bool LimitAddressSpace(const std::string& process_type); |
| 87 | 77 |
| 88 private: | 78 private: |
| 89 friend struct DefaultSingletonTraits<LinuxSandbox>; | 79 friend struct DefaultSingletonTraits<LinuxSandbox>; |
| 90 | 80 |
| 91 // We must have been pre_initialized_ before using this. | 81 // We must have been pre_initialized_ before using this. |
| 92 bool seccomp_bpf_supported() const; | 82 bool seccomp_bpf_supported() const; |
| 83 // The last part of the initialization is to make sure any temporary "hole" | |
| 84 // in the sandbox is closed. For now, this consists of closing proc_fd_. | |
| 85 void SealSandbox(); | |
| 93 | 86 |
| 94 int proc_fd_; | 87 int proc_fd_; // A file descriptor to /proc. It's dangerous to have it |
|
palmer
2013/04/30 21:21:59
NIT: Put multi-line documentation above the declar
jln (very slow on Chromium)
2013/04/30 22:09:51
Done.
| |
| 88 // around as it could allow for sandbox bypasses. It needs | |
| 89 // to be closed before we consider ourselves sandboxed. | |
| 95 bool seccomp_bpf_started_; | 90 bool seccomp_bpf_started_; |
| 96 // Have we been through PreinitializeSandbox or PreinitializeSandboxBegin? | 91 // Did PreinitializeSandbox() run? |
| 97 bool pre_initialized_; | 92 bool pre_initialized_; |
| 98 bool seccomp_bpf_supported_; // Accurate if pre_initialized_. | 93 bool seccomp_bpf_supported_; // Accurate if pre_initialized_. |
| 99 scoped_ptr<sandbox::SetuidSandboxClient> setuid_sandbox_client_; | 94 scoped_ptr<sandbox::SetuidSandboxClient> setuid_sandbox_client_; |
| 100 | 95 |
| 101 ~LinuxSandbox(); | 96 ~LinuxSandbox(); |
| 102 DISALLOW_IMPLICIT_CONSTRUCTORS(LinuxSandbox); | 97 DISALLOW_IMPLICIT_CONSTRUCTORS(LinuxSandbox); |
| 103 }; | 98 }; |
| 104 | 99 |
| 105 } // namespace content | 100 } // namespace content |
| 106 | 101 |
| 107 #endif // CONTENT_COMMON_SANDBOX_LINUX_H_ | 102 #endif // CONTENT_COMMON_SANDBOX_LINUX_H_ |
| 108 | 103 |
| OLD | NEW |