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

Side by Side Diff: components/nacl/loader/nacl_helper_linux.cc

Issue 269543014: Use RecvMsgWithPid to find real PID for zygote children (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweak PID discovery to handle crashing child processes Created 6 years, 7 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
OLDNEW
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 listener.Listen(); 107 listener.Listen();
108 _exit(0); 108 _exit(0);
109 } 109 }
110 110
111 // Start the NaCl loader in a child created by the NaCl loader Zygote. 111 // Start the NaCl loader in a child created by the NaCl loader Zygote.
112 void ChildNaClLoaderInit(ScopedVector<base::ScopedFD> child_fds, 112 void ChildNaClLoaderInit(ScopedVector<base::ScopedFD> child_fds,
113 const NaClLoaderSystemInfo& system_info, 113 const NaClLoaderSystemInfo& system_info,
114 bool uses_nonsfi_mode, 114 bool uses_nonsfi_mode,
115 nacl::NaClSandbox* nacl_sandbox, 115 nacl::NaClSandbox* nacl_sandbox,
116 const std::string& channel_id) { 116 const std::string& channel_id) {
117 bool validack = false; 117 // Ping the PID oracle socket.
118 base::ProcessId real_pid; 118 CHECK(UnixDomainSocket::SendMsg(
119 // Wait until the parent process has discovered our PID. We 119 child_fds[content::ZygoteForkDelegate::kPIDOracleFDIndex]->get(),
120 // should not fork any child processes (which the seccomp 120 "x",
jln (very slow on Chromium) 2014/05/02 18:25:00 Let's make this a defined constant and check for i
mdempsky 2014/05/02 20:23:09 Yep, I just used a dummy string constant for proof
mdempsky 2014/05/02 23:36:01 Done.
121 // sandbox does) until then, because that can interfere with the 121 1,
122 // parent's discovery of our PID. 122 std::vector<int>()));
123 const ssize_t nread = HANDLE_EINTR(
124 read(child_fds[content::ZygoteForkDelegate::kParentFDIndex]->get(),
125 &real_pid,
126 sizeof(real_pid)));
127 if (static_cast<size_t>(nread) == sizeof(real_pid)) {
128 // Make sure the parent didn't accidentally send us our real PID.
129 // We don't want it to be discoverable anywhere in our address space
130 // when we start running untrusted code.
131 CHECK(real_pid == 0);
132 123
133 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 124 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
134 switches::kProcessChannelID, channel_id); 125 switches::kProcessChannelID, channel_id);
135 validack = true;
136 } else {
137 if (nread < 0)
138 perror("read");
139 LOG(ERROR) << "read returned " << nread;
140 }
141 126
127 // Save the browser socket and close the rest.
142 base::ScopedFD browser_fd( 128 base::ScopedFD browser_fd(
143 child_fds[content::ZygoteForkDelegate::kBrowserFDIndex]->Pass()); 129 child_fds[content::ZygoteForkDelegate::kBrowserFDIndex]->Pass());
144 child_fds.clear(); 130 child_fds.clear();
145 131
146 if (validack) { 132 BecomeNaClLoader(
147 BecomeNaClLoader( 133 browser_fd.Pass(), system_info, uses_nonsfi_mode, nacl_sandbox);
148 browser_fd.Pass(), system_info, uses_nonsfi_mode, nacl_sandbox);
149 } else {
150 LOG(ERROR) << "Failed to synch with zygote";
151 }
152 _exit(1); 134 _exit(1);
153 } 135 }
154 136
155 // Handle a fork request from the Zygote. 137 // Handle a fork request from the Zygote.
156 // Some of this code was lifted from 138 // Some of this code was lifted from
157 // content/browser/zygote_main_linux.cc:ForkWithRealPid() 139 // content/browser/zygote_main_linux.cc:ForkWithRealPid()
158 bool HandleForkRequest(ScopedVector<base::ScopedFD> child_fds, 140 bool HandleForkRequest(ScopedVector<base::ScopedFD> child_fds,
159 const NaClLoaderSystemInfo& system_info, 141 const NaClLoaderSystemInfo& system_info,
160 nacl::NaClSandbox* nacl_sandbox, 142 nacl::NaClSandbox* nacl_sandbox,
161 PickleIterator* input_iter, 143 PickleIterator* input_iter,
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 // Now handle requests from the Zygote. 431 // Now handle requests from the Zygote.
450 while (true) { 432 while (true) {
451 bool request_handled = HandleZygoteRequest( 433 bool request_handled = HandleZygoteRequest(
452 kNaClZygoteDescriptor, system_info, nacl_sandbox.get()); 434 kNaClZygoteDescriptor, system_info, nacl_sandbox.get());
453 // Do not turn this into a CHECK() without thinking about robustness 435 // Do not turn this into a CHECK() without thinking about robustness
454 // against malicious IPC requests. 436 // against malicious IPC requests.
455 DCHECK(request_handled); 437 DCHECK(request_handled);
456 } 438 }
457 NOTREACHED(); 439 NOTREACHED();
458 } 440 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698