| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "services/service_manager/runner/host/service_process_launcher.h" | 5 #include "services/service_manager/runner/host/service_process_launcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 123 |
| 124 void ServiceProcessLauncher::DoLaunch( | 124 void ServiceProcessLauncher::DoLaunch( |
| 125 std::unique_ptr<base::CommandLine> child_command_line) { | 125 std::unique_ptr<base::CommandLine> child_command_line) { |
| 126 if (delegate_) { | 126 if (delegate_) { |
| 127 delegate_->AdjustCommandLineArgumentsForTarget(target_, | 127 delegate_->AdjustCommandLineArgumentsForTarget(target_, |
| 128 child_command_line.get()); | 128 child_command_line.get()); |
| 129 } | 129 } |
| 130 | 130 |
| 131 base::LaunchOptions options; | 131 base::LaunchOptions options; |
| 132 #if defined(OS_WIN) | 132 #if defined(OS_WIN) |
| 133 options.handles_to_inherit = &handle_passing_info_; | 133 options.handles_to_inherit = handle_passing_info_; |
| 134 #if defined(OFFICIAL_BUILD) | |
| 135 CHECK(false) << "Launching mojo process with inherit_handles is insecure!"; | |
| 136 #endif | |
| 137 options.inherit_handles = true; | |
| 138 options.stdin_handle = INVALID_HANDLE_VALUE; | 134 options.stdin_handle = INVALID_HANDLE_VALUE; |
| 139 options.stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); | 135 options.stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); |
| 140 options.stderr_handle = GetStdHandle(STD_ERROR_HANDLE); | 136 options.stderr_handle = GetStdHandle(STD_ERROR_HANDLE); |
| 141 // Always inherit stdout/stderr as a pair. | 137 // Always inherit stdout/stderr as a pair. |
| 142 if (!options.stdout_handle || !options.stdin_handle) | 138 if (!options.stdout_handle || !options.stdin_handle) |
| 143 options.stdin_handle = options.stdout_handle = nullptr; | 139 options.stdin_handle = options.stdout_handle = nullptr; |
| 144 | 140 |
| 145 // Pseudo handles are used when stdout and stderr redirect to the console. In | 141 // Pseudo handles are used when stdout and stderr redirect to the console. In |
| 146 // that case, they're automatically inherited by child processes. See | 142 // that case, they're automatically inherited by child processes. See |
| 147 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms682075.aspx | 143 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms682075.aspx |
| 148 // Trying to add them to the list of handles to inherit causes CreateProcess | 144 // Trying to add them to the list of handles to inherit causes CreateProcess |
| 149 // to fail. When this process is launched from Python then a real handle is | 145 // to fail. When this process is launched from Python then a real handle is |
| 150 // used. In that case, we do want to add it to the list of handles that is | 146 // used. In that case, we do want to add it to the list of handles that is |
| 151 // inherited. | 147 // inherited. |
| 152 if (options.stdout_handle && | 148 if (options.stdout_handle && |
| 153 GetFileType(options.stdout_handle) != FILE_TYPE_CHAR) { | 149 GetFileType(options.stdout_handle) != FILE_TYPE_CHAR) { |
| 154 handle_passing_info_.push_back(options.stdout_handle); | 150 options.handles_to_inherit.push_back(options.stdout_handle); |
| 155 } | 151 } |
| 156 if (options.stderr_handle && | 152 if (options.stderr_handle && |
| 157 GetFileType(options.stderr_handle) != FILE_TYPE_CHAR && | 153 GetFileType(options.stderr_handle) != FILE_TYPE_CHAR && |
| 158 options.stdout_handle != options.stderr_handle) { | 154 options.stdout_handle != options.stderr_handle) { |
| 159 handle_passing_info_.push_back(options.stderr_handle); | 155 options.handles_to_inherit.push_back(options.stderr_handle); |
| 160 } | 156 } |
| 161 #elif defined(OS_POSIX) | 157 #elif defined(OS_POSIX) |
| 162 handle_passing_info_.push_back(std::make_pair(STDIN_FILENO, STDIN_FILENO)); | 158 handle_passing_info_.push_back(std::make_pair(STDIN_FILENO, STDIN_FILENO)); |
| 163 handle_passing_info_.push_back(std::make_pair(STDOUT_FILENO, STDOUT_FILENO)); | 159 handle_passing_info_.push_back(std::make_pair(STDOUT_FILENO, STDOUT_FILENO)); |
| 164 handle_passing_info_.push_back(std::make_pair(STDERR_FILENO, STDERR_FILENO)); | 160 handle_passing_info_.push_back(std::make_pair(STDERR_FILENO, STDERR_FILENO)); |
| 165 options.fds_to_remap = &handle_passing_info_; | 161 options.fds_to_remap = handle_passing_info_; |
| 166 #endif | 162 #endif |
| 167 DVLOG(2) << "Launching child with command line: " | 163 DVLOG(2) << "Launching child with command line: " |
| 168 << child_command_line->GetCommandLineString(); | 164 << child_command_line->GetCommandLineString(); |
| 169 #if defined(OS_LINUX) | 165 #if defined(OS_LINUX) |
| 170 if (start_sandboxed_) { | 166 if (start_sandboxed_) { |
| 171 child_process_ = | 167 child_process_ = |
| 172 sandbox::NamespaceSandbox::LaunchProcess(*child_command_line, options); | 168 sandbox::NamespaceSandbox::LaunchProcess(*child_command_line, options); |
| 173 if (!child_process_.IsValid()) { | 169 if (!child_process_.IsValid()) { |
| 174 LOG(ERROR) << "Starting the process with a sandbox failed. Missing kernel" | 170 LOG(ERROR) << "Starting the process with a sandbox failed. Missing kernel" |
| 175 << " support."; | 171 << " support."; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 205 broker_client_invitation_.Send( | 201 broker_client_invitation_.Send( |
| 206 child_process_.Handle(), | 202 child_process_.Handle(), |
| 207 mojo::edk::ConnectionParams(mojo::edk::TransportProtocol::kLegacy, | 203 mojo::edk::ConnectionParams(mojo::edk::TransportProtocol::kLegacy, |
| 208 mojo_ipc_channel_->PassServerHandle())); | 204 mojo_ipc_channel_->PassServerHandle())); |
| 209 } | 205 } |
| 210 } | 206 } |
| 211 start_child_process_event_.Signal(); | 207 start_child_process_event_.Signal(); |
| 212 } | 208 } |
| 213 | 209 |
| 214 } // namespace service_manager | 210 } // namespace service_manager |
| OLD | NEW |