OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // A mini-zygote specifically for Native Client. | 5 // A mini-zygote specifically for Native Client. |
6 | 6 |
7 #include "components/nacl/loader/nacl_helper_linux.h" | 7 #include "components/nacl/loader/nacl_helper_linux.h" |
8 | 8 |
9 #include <errno.h> | 9 #include <errno.h> |
10 #include <fcntl.h> | 10 #include <fcntl.h> |
(...skipping 25 matching lines...) Expand all Loading... | |
36 #include "ipc/ipc_switches.h" | 36 #include "ipc/ipc_switches.h" |
37 #include "sandbox/linux/services/libc_urandom_override.h" | 37 #include "sandbox/linux/services/libc_urandom_override.h" |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 struct NaClLoaderSystemInfo { | 41 struct NaClLoaderSystemInfo { |
42 size_t prereserved_sandbox_size; | 42 size_t prereserved_sandbox_size; |
43 long number_of_cores; | 43 long number_of_cores; |
44 }; | 44 }; |
45 | 45 |
46 // This is a poor man's check on whether we are sandboxed. | |
47 bool IsSandboxed() { | |
48 int proc_fd = open("/proc/self/exe", O_RDONLY); | |
49 if (proc_fd >= 0) { | |
50 close(proc_fd); | |
51 return false; | |
52 } | |
53 return true; | |
54 } | |
55 | |
56 void InitializeSandbox(bool uses_nonsfi_mode) { | |
57 if (uses_nonsfi_mode) { | |
58 if (getenv("NACL_DANGEROUS_DISABLE_NONSFI_SANDBOX")) { | |
hamaji
2014/04/04 14:36:58
We need to whitelist this (and other NACL-prefixed
Mark Seaborn
2014/04/04 15:45:37
Is there anything specific you want it for?
I'll
hamaji
2014/04/04 18:57:48
Yes. Our app has a hack to attach GDB appropriatel
| |
59 LOG(ERROR) << "DANGEROUS: Running non-SFI NaCl without sandbox!"; | |
60 return; | |
61 } | |
62 const bool setuid_sandbox_enabled = IsSandboxed(); | |
63 CHECK(setuid_sandbox_enabled) | |
64 << "SUID sandbox is mandatory for non-SFI NaCl"; | |
65 // TODO(hamaji): Add a strict seccomp sandbox for non-SFI NaCl. | |
Mark Seaborn
2014/04/04 15:45:37
Nit: I suspect you wouldn't be changing this part
hamaji
2014/04/04 18:57:48
I was planning to change this to nacl::nonsfi::Ini
| |
66 // https://code.google.com/p/chromium/issues/detail?id=359285 | |
67 bool bpf_sandbox_initialized = InitializeBPFSandbox(); | |
Mark Seaborn
2014/04/04 15:45:37
When I talked with Julien yesterday, he pointed ou
hamaji
2014/04/04 18:57:48
It seems the sandbox is enabled even with --disabl
| |
68 CHECK(bpf_sandbox_initialized) | |
69 << "Could not initialize NaCl's second " | |
70 << "layer sandbox (seccomp-bpf) for non-SFI mode."; | |
71 } else { | |
72 bool bpf_sandbox_initialized = InitializeBPFSandbox(); | |
73 if (!bpf_sandbox_initialized) { | |
74 LOG(ERROR) << "Could not initialize NaCl's second " | |
75 << "layer sandbox (seccomp-bpf) for SFI mode."; | |
76 } | |
77 } | |
78 } | |
79 | |
46 // The child must mimic the behavior of zygote_main_linux.cc on the child | 80 // The child must mimic the behavior of zygote_main_linux.cc on the child |
47 // side of the fork. See zygote_main_linux.cc:HandleForkRequest from | 81 // side of the fork. See zygote_main_linux.cc:HandleForkRequest from |
48 // if (!child) { | 82 // if (!child) { |
49 void BecomeNaClLoader(const std::vector<int>& child_fds, | 83 void BecomeNaClLoader(const std::vector<int>& child_fds, |
50 const NaClLoaderSystemInfo& system_info, | 84 const NaClLoaderSystemInfo& system_info, |
51 bool uses_nonsfi_mode) { | 85 bool uses_nonsfi_mode) { |
52 VLOG(1) << "NaCl loader: setting up IPC descriptor"; | 86 VLOG(1) << "NaCl loader: setting up IPC descriptor"; |
53 // don't need zygote FD any more | 87 // don't need zygote FD any more |
54 if (IGNORE_EINTR(close(kNaClZygoteDescriptor)) != 0) | 88 if (IGNORE_EINTR(close(kNaClZygoteDescriptor)) != 0) |
55 LOG(ERROR) << "close(kNaClZygoteDescriptor) failed."; | 89 LOG(ERROR) << "close(kNaClZygoteDescriptor) failed."; |
56 bool sandbox_initialized = InitializeBPFSandbox(); | 90 InitializeSandbox(uses_nonsfi_mode); |
57 if (!sandbox_initialized) { | |
58 LOG(ERROR) << "Could not initialize NaCl's second " | |
59 << "layer sandbox (seccomp-bpf)."; | |
60 } | |
61 base::GlobalDescriptors::GetInstance()->Set( | 91 base::GlobalDescriptors::GetInstance()->Set( |
62 kPrimaryIPCChannel, | 92 kPrimaryIPCChannel, |
63 child_fds[content::ZygoteForkDelegate::kBrowserFDIndex]); | 93 child_fds[content::ZygoteForkDelegate::kBrowserFDIndex]); |
64 | 94 |
65 base::MessageLoopForIO main_message_loop; | 95 base::MessageLoopForIO main_message_loop; |
66 NaClListener listener; | 96 NaClListener listener; |
67 listener.set_uses_nonsfi_mode(uses_nonsfi_mode); | 97 listener.set_uses_nonsfi_mode(uses_nonsfi_mode); |
68 listener.set_prereserved_sandbox_size(system_info.prereserved_sandbox_size); | 98 listener.set_prereserved_sandbox_size(system_info.prereserved_sandbox_size); |
69 listener.set_number_of_cores(system_info.number_of_cores); | 99 listener.set_number_of_cores(system_info.number_of_cores); |
70 listener.Listen(); | 100 listener.Listen(); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 base::TerminationStatus status; | 209 base::TerminationStatus status; |
180 if (known_dead) | 210 if (known_dead) |
181 status = base::GetKnownDeadTerminationStatus(child_to_wait, &exit_code); | 211 status = base::GetKnownDeadTerminationStatus(child_to_wait, &exit_code); |
182 else | 212 else |
183 status = base::GetTerminationStatus(child_to_wait, &exit_code); | 213 status = base::GetTerminationStatus(child_to_wait, &exit_code); |
184 output_pickle->WriteInt(static_cast<int>(status)); | 214 output_pickle->WriteInt(static_cast<int>(status)); |
185 output_pickle->WriteInt(exit_code); | 215 output_pickle->WriteInt(exit_code); |
186 return true; | 216 return true; |
187 } | 217 } |
188 | 218 |
189 // This is a poor man's check on whether we are sandboxed. | |
190 bool IsSandboxed() { | |
191 int proc_fd = open("/proc/self/exe", O_RDONLY); | |
192 if (proc_fd >= 0) { | |
193 close(proc_fd); | |
194 return false; | |
195 } | |
196 return true; | |
197 } | |
198 | |
199 // Honor a command |command_type|. Eventual command parameters are | 219 // Honor a command |command_type|. Eventual command parameters are |
200 // available in |input_iter| and eventual file descriptors attached to | 220 // available in |input_iter| and eventual file descriptors attached to |
201 // the command are in |attached_fds|. | 221 // the command are in |attached_fds|. |
202 // Reply to the command on |reply_fds|. | 222 // Reply to the command on |reply_fds|. |
203 bool HonorRequestAndReply(int reply_fd, | 223 bool HonorRequestAndReply(int reply_fd, |
204 int command_type, | 224 int command_type, |
205 const std::vector<int>& attached_fds, | 225 const std::vector<int>& attached_fds, |
206 const NaClLoaderSystemInfo& system_info, | 226 const NaClLoaderSystemInfo& system_info, |
207 PickleIterator* input_iter) { | 227 PickleIterator* input_iter) { |
208 Pickle write_pickle; | 228 Pickle write_pickle; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 // Now handle requests from the Zygote. | 415 // Now handle requests from the Zygote. |
396 while (true) { | 416 while (true) { |
397 bool request_handled = HandleZygoteRequest(kNaClZygoteDescriptor, | 417 bool request_handled = HandleZygoteRequest(kNaClZygoteDescriptor, |
398 system_info); | 418 system_info); |
399 // Do not turn this into a CHECK() without thinking about robustness | 419 // Do not turn this into a CHECK() without thinking about robustness |
400 // against malicious IPC requests. | 420 // against malicious IPC requests. |
401 DCHECK(request_handled); | 421 DCHECK(request_handled); |
402 } | 422 } |
403 NOTREACHED(); | 423 NOTREACHED(); |
404 } | 424 } |
OLD | NEW |