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 16 matching lines...) Expand all Loading... |
27 #include "base/posix/eintr_wrapper.h" | 27 #include "base/posix/eintr_wrapper.h" |
28 #include "base/posix/global_descriptors.h" | 28 #include "base/posix/global_descriptors.h" |
29 #include "base/posix/unix_domain_socket_linux.h" | 29 #include "base/posix/unix_domain_socket_linux.h" |
30 #include "base/process/kill.h" | 30 #include "base/process/kill.h" |
31 #include "base/process/process_handle.h" | 31 #include "base/process/process_handle.h" |
32 #include "base/rand_util.h" | 32 #include "base/rand_util.h" |
33 #include "components/nacl/common/nacl_switches.h" | 33 #include "components/nacl/common/nacl_switches.h" |
34 #include "components/nacl/loader/nacl_listener.h" | 34 #include "components/nacl/loader/nacl_listener.h" |
35 #include "components/nacl/loader/nacl_sandbox_linux.h" | 35 #include "components/nacl/loader/nacl_sandbox_linux.h" |
36 #include "components/nacl/loader/nonsfi/nonsfi_sandbox.h" | 36 #include "components/nacl/loader/nonsfi/nonsfi_sandbox.h" |
| 37 #include "content/public/common/child_process_sandbox_support_linux.h" |
37 #include "content/public/common/zygote_fork_delegate_linux.h" | 38 #include "content/public/common/zygote_fork_delegate_linux.h" |
38 #include "crypto/nss_util.h" | 39 #include "crypto/nss_util.h" |
39 #include "ipc/ipc_descriptors.h" | 40 #include "ipc/ipc_descriptors.h" |
40 #include "ipc/ipc_switches.h" | 41 #include "ipc/ipc_switches.h" |
41 #include "sandbox/linux/services/credentials.h" | 42 #include "sandbox/linux/services/credentials.h" |
42 #include "sandbox/linux/services/libc_urandom_override.h" | 43 #include "sandbox/linux/services/libc_urandom_override.h" |
43 #include "sandbox/linux/services/thread_helpers.h" | 44 #include "sandbox/linux/services/thread_helpers.h" |
44 #include "sandbox/linux/suid/client/setuid_sandbox_client.h" | 45 #include "sandbox/linux/suid/client/setuid_sandbox_client.h" |
45 | 46 |
46 namespace { | 47 namespace { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 listener.Listen(); | 137 listener.Listen(); |
137 _exit(0); | 138 _exit(0); |
138 } | 139 } |
139 | 140 |
140 // Start the NaCl loader in a child created by the NaCl loader Zygote. | 141 // Start the NaCl loader in a child created by the NaCl loader Zygote. |
141 void ChildNaClLoaderInit(const std::vector<int>& child_fds, | 142 void ChildNaClLoaderInit(const std::vector<int>& child_fds, |
142 const NaClLoaderSystemInfo& system_info, | 143 const NaClLoaderSystemInfo& system_info, |
143 bool uses_nonsfi_mode, | 144 bool uses_nonsfi_mode, |
144 const std::string& channel_id) { | 145 const std::string& channel_id) { |
145 const int parent_fd = child_fds[content::ZygoteForkDelegate::kParentFDIndex]; | 146 const int parent_fd = child_fds[content::ZygoteForkDelegate::kParentFDIndex]; |
146 const int dummy_fd = child_fds[content::ZygoteForkDelegate::kDummyFDIndex]; | 147 if (!content::SendRealPidToZygote(parent_fd, NULL)) |
147 | 148 LOG(FATAL) << "Failed to synchronize with zygote"; |
148 bool validack = false; | |
149 base::ProcessId real_pid; | |
150 // Wait until the parent process has discovered our PID. We | |
151 // should not fork any child processes (which the seccomp | |
152 // sandbox does) until then, because that can interfere with the | |
153 // parent's discovery of our PID. | |
154 const ssize_t nread = | |
155 HANDLE_EINTR(read(parent_fd, &real_pid, sizeof(real_pid))); | |
156 if (static_cast<size_t>(nread) == sizeof(real_pid)) { | |
157 // Make sure the parent didn't accidentally send us our real PID. | |
158 // We don't want it to be discoverable anywhere in our address space | |
159 // when we start running untrusted code. | |
160 CHECK(real_pid == 0); | |
161 | |
162 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
163 switches::kProcessChannelID, channel_id); | |
164 validack = true; | |
165 } else { | |
166 if (nread < 0) | |
167 perror("read"); | |
168 LOG(ERROR) << "read returned " << nread; | |
169 } | |
170 | |
171 if (IGNORE_EINTR(close(dummy_fd)) != 0) | |
172 LOG(ERROR) << "close(dummy_fd) failed"; | |
173 if (IGNORE_EINTR(close(parent_fd)) != 0) | 149 if (IGNORE_EINTR(close(parent_fd)) != 0) |
174 LOG(ERROR) << "close(parent_fd) failed"; | 150 LOG(FATAL) << "close(parent_fd) failed"; |
175 if (validack) { | 151 BecomeNaClLoader(child_fds, system_info, uses_nonsfi_mode); |
176 BecomeNaClLoader(child_fds, system_info, uses_nonsfi_mode); | |
177 } else { | |
178 LOG(ERROR) << "Failed to synch with zygote"; | |
179 } | |
180 _exit(1); | 152 _exit(1); |
181 } | 153 } |
182 | 154 |
183 // Handle a fork request from the Zygote. | 155 // Handle a fork request from the Zygote. |
184 // Some of this code was lifted from | 156 // Some of this code was lifted from |
185 // content/browser/zygote_main_linux.cc:ForkWithRealPid() | 157 // content/browser/zygote_main_linux.cc:ForkWithRealPid() |
186 bool HandleForkRequest(const std::vector<int>& child_fds, | 158 bool HandleForkRequest(const std::vector<int>& child_fds, |
187 const NaClLoaderSystemInfo& system_info, | 159 const NaClLoaderSystemInfo& system_info, |
188 PickleIterator* input_iter, | 160 PickleIterator* input_iter, |
189 Pickle* output_pickle) { | 161 Pickle* output_pickle) { |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 // Now handle requests from the Zygote. | 435 // Now handle requests from the Zygote. |
464 while (true) { | 436 while (true) { |
465 bool request_handled = HandleZygoteRequest(kNaClZygoteDescriptor, | 437 bool request_handled = HandleZygoteRequest(kNaClZygoteDescriptor, |
466 system_info); | 438 system_info); |
467 // Do not turn this into a CHECK() without thinking about robustness | 439 // Do not turn this into a CHECK() without thinking about robustness |
468 // against malicious IPC requests. | 440 // against malicious IPC requests. |
469 DCHECK(request_handled); | 441 DCHECK(request_handled); |
470 } | 442 } |
471 NOTREACHED(); | 443 NOTREACHED(); |
472 } | 444 } |
OLD | NEW |