| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/feature_list.h" | 6 #include "base/feature_list.h" |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/posix/global_descriptors.h" | 9 #include "base/posix/global_descriptors.h" |
| 10 #include "content/browser/bootstrap_sandbox_manager_mac.h" | 10 #include "content/browser/bootstrap_sandbox_manager_mac.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 mojo::edk::ScopedPlatformHandle | 31 mojo::edk::ScopedPlatformHandle |
| 32 ChildProcessLauncherHelper::PrepareMojoPipeHandlesOnClientThread() { | 32 ChildProcessLauncherHelper::PrepareMojoPipeHandlesOnClientThread() { |
| 33 DCHECK_CURRENTLY_ON(client_thread_id_); | 33 DCHECK_CURRENTLY_ON(client_thread_id_); |
| 34 return mojo::edk::ScopedPlatformHandle(); | 34 return mojo::edk::ScopedPlatformHandle(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() { | 37 void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() { |
| 38 DCHECK_CURRENTLY_ON(client_thread_id_); | 38 DCHECK_CURRENTLY_ON(client_thread_id_); |
| 39 } | 39 } |
| 40 | 40 |
| 41 std::unique_ptr<FileDescriptorInfo> | 41 std::unique_ptr<PosixFileDescriptorInfo> |
| 42 ChildProcessLauncherHelper::GetFilesToMap() { | 42 ChildProcessLauncherHelper::GetFilesToMap() { |
| 43 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | 43 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| 44 return CreateDefaultPosixFilesToMap( | 44 return CreateDefaultPosixFilesToMap( |
| 45 child_process_id(), mojo_client_handle(), | 45 child_process_id(), mojo_client_handle(), |
| 46 false /* include_service_required_files */, GetProcessType(), | 46 false /* include_service_required_files */, GetProcessType(), |
| 47 command_line()); | 47 command_line()); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread( | 50 void ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread( |
| 51 const FileMappedForLaunch& files_to_register, | 51 const FileMappedForLaunch& files_to_register, |
| 52 base::LaunchOptions* options) { | 52 base::LaunchOptions* options) { |
| 53 // Convert FD mapping to FileHandleMappingVector. | 53 // Convert FD mapping to FileHandleMappingVector. |
| 54 std::unique_ptr<base::FileHandleMappingVector> fds_to_map = | 54 options->fds_to_remap = files_to_register.GetMappingWithIDAdjustment( |
| 55 files_to_register.GetMappingWithIDAdjustment( | 55 base::GlobalDescriptors::kBaseDescriptor); |
| 56 base::GlobalDescriptors::kBaseDescriptor); | |
| 57 | 56 |
| 58 options->environ = delegate_->GetEnvironment(); | 57 options->environ = delegate_->GetEnvironment(); |
| 59 | 58 |
| 60 if (base::FeatureList::IsEnabled(features::kMacV2Sandbox) && | 59 if (base::FeatureList::IsEnabled(features::kMacV2Sandbox) && |
| 61 GetProcessType() == switches::kRendererProcess) { | 60 GetProcessType() == switches::kRendererProcess) { |
| 62 seatbelt_exec_client_ = base::MakeUnique<sandbox::SeatbeltExecClient>(); | 61 seatbelt_exec_client_ = base::MakeUnique<sandbox::SeatbeltExecClient>(); |
| 63 base::StringPiece renderer_sb = GetContentClient()->GetDataResource( | 62 base::StringPiece renderer_sb = GetContentClient()->GetDataResource( |
| 64 IDR_RENDERER_SANDBOX_V2_PROFILE, ui::SCALE_FACTOR_NONE); | 63 IDR_RENDERER_SANDBOX_V2_PROFILE, ui::SCALE_FACTOR_NONE); |
| 65 std::string profile = renderer_sb.as_string(); | 64 std::string profile = renderer_sb.as_string(); |
| 66 | 65 |
| 67 seatbelt_exec_client_->SetProfile(profile); | 66 seatbelt_exec_client_->SetProfile(profile); |
| 68 | 67 |
| 69 SetupRendererSandboxParameters(seatbelt_exec_client_.get()); | 68 SetupRendererSandboxParameters(seatbelt_exec_client_.get()); |
| 70 | 69 |
| 71 int pipe = seatbelt_exec_client_->SendProfileAndGetFD(); | 70 int pipe = seatbelt_exec_client_->SendProfileAndGetFD(); |
| 72 | 71 |
| 73 base::FilePath helper_executable; | 72 base::FilePath helper_executable; |
| 74 CHECK(PathService::Get(content::CHILD_PROCESS_EXE, &helper_executable)); | 73 CHECK(PathService::Get(content::CHILD_PROCESS_EXE, &helper_executable)); |
| 75 | 74 |
| 76 fds_to_map->push_back(std::make_pair(pipe, pipe)); | 75 options->fds_to_remap.push_back(std::make_pair(pipe, pipe)); |
| 77 | 76 |
| 78 // Update the command line to enable the V2 sandbox and pass the | 77 // Update the command line to enable the V2 sandbox and pass the |
| 79 // communication FD to the helper executable. | 78 // communication FD to the helper executable. |
| 80 command_line_->AppendSwitch(switches::kEnableV2Sandbox); | 79 command_line_->AppendSwitch(switches::kEnableV2Sandbox); |
| 81 command_line_->AppendArg("--fd_mapping=" + std::to_string(pipe)); | 80 command_line_->AppendArg("--fd_mapping=" + std::to_string(pipe)); |
| 82 } | 81 } |
| 83 | 82 |
| 84 // fds_to_remap will de deleted in AfterLaunchOnLauncherThread() below. | |
| 85 options->fds_to_remap = fds_to_map.release(); | |
| 86 | |
| 87 // Hold the MachBroker lock for the duration of LaunchProcess. The child will | 83 // Hold the MachBroker lock for the duration of LaunchProcess. The child will |
| 88 // send its task port to the parent almost immediately after startup. The Mach | 84 // send its task port to the parent almost immediately after startup. The Mach |
| 89 // message will be delivered to the parent, but updating the record of the | 85 // message will be delivered to the parent, but updating the record of the |
| 90 // launch will wait until after the placeholder PID is inserted below. This | 86 // launch will wait until after the placeholder PID is inserted below. This |
| 91 // ensures that while the child process may send its port to the parent prior | 87 // ensures that while the child process may send its port to the parent prior |
| 92 // to the parent leaving LaunchProcess, the order in which the record in | 88 // to the parent leaving LaunchProcess, the order in which the record in |
| 93 // MachBroker is updated is correct. | 89 // MachBroker is updated is correct. |
| 94 MachBroker* broker = MachBroker::GetInstance(); | 90 MachBroker* broker = MachBroker::GetInstance(); |
| 95 broker->GetLock().Acquire(); | 91 broker->GetLock().Acquire(); |
| 96 | 92 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 108 } | 104 } |
| 109 } | 105 } |
| 110 // options now owns the pre_exec_delegate which will be delete on | 106 // options now owns the pre_exec_delegate which will be delete on |
| 111 // AfterLaunchOnLauncherThread below. | 107 // AfterLaunchOnLauncherThread below. |
| 112 options->pre_exec_delegate = pre_exec_delegate.release(); | 108 options->pre_exec_delegate = pre_exec_delegate.release(); |
| 113 } | 109 } |
| 114 | 110 |
| 115 ChildProcessLauncherHelper::Process | 111 ChildProcessLauncherHelper::Process |
| 116 ChildProcessLauncherHelper::LaunchProcessOnLauncherThread( | 112 ChildProcessLauncherHelper::LaunchProcessOnLauncherThread( |
| 117 const base::LaunchOptions& options, | 113 const base::LaunchOptions& options, |
| 118 std::unique_ptr<FileDescriptorInfo> files_to_register, | 114 std::unique_ptr<PosixFileDescriptorInfo> files_to_register, |
| 119 bool* is_synchronous_launch, | 115 bool* is_synchronous_launch, |
| 120 int* launch_result) { | 116 int* launch_result) { |
| 121 *is_synchronous_launch = true; | 117 *is_synchronous_launch = true; |
| 122 ChildProcessLauncherHelper::Process process; | 118 ChildProcessLauncherHelper::Process process; |
| 123 process.process = base::LaunchProcess(*command_line(), options); | 119 process.process = base::LaunchProcess(*command_line(), options); |
| 124 *launch_result = process.process.IsValid() ? LAUNCH_RESULT_SUCCESS | 120 *launch_result = process.process.IsValid() ? LAUNCH_RESULT_SUCCESS |
| 125 : LAUNCH_RESULT_FAILURE; | 121 : LAUNCH_RESULT_FAILURE; |
| 126 return process; | 122 return process; |
| 127 } | 123 } |
| 128 | 124 |
| 129 void ChildProcessLauncherHelper::AfterLaunchOnLauncherThread( | 125 void ChildProcessLauncherHelper::AfterLaunchOnLauncherThread( |
| 130 const ChildProcessLauncherHelper::Process& process, | 126 const ChildProcessLauncherHelper::Process& process, |
| 131 const base::LaunchOptions& options) { | 127 const base::LaunchOptions& options) { |
| 132 delete options.fds_to_remap; | |
| 133 | |
| 134 std::unique_ptr<sandbox::PreExecDelegate> pre_exec_delegate = | 128 std::unique_ptr<sandbox::PreExecDelegate> pre_exec_delegate = |
| 135 base::WrapUnique(static_cast<sandbox::PreExecDelegate*>( | 129 base::WrapUnique(static_cast<sandbox::PreExecDelegate*>( |
| 136 options.pre_exec_delegate)); | 130 options.pre_exec_delegate)); |
| 137 | 131 |
| 138 MachBroker* broker = MachBroker::GetInstance(); | 132 MachBroker* broker = MachBroker::GetInstance(); |
| 139 if (process.process.IsValid()) { | 133 if (process.process.IsValid()) { |
| 140 broker->AddPlaceholderForPid(process.process.Pid(), child_process_id()); | 134 broker->AddPlaceholderForPid(process.process.Pid(), child_process_id()); |
| 141 } else { | 135 } else { |
| 142 if (pre_exec_delegate) { | 136 if (pre_exec_delegate) { |
| 143 BootstrapSandboxManager::GetInstance()->sandbox()->RevokeToken( | 137 BootstrapSandboxManager::GetInstance()->sandbox()->RevokeToken( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 base::File OpenFileToShare(const base::FilePath& path, | 192 base::File OpenFileToShare(const base::FilePath& path, |
| 199 base::MemoryMappedFile::Region* region) { | 193 base::MemoryMappedFile::Region* region) { |
| 200 // Not used yet (until required files are described in the service manifest on | 194 // Not used yet (until required files are described in the service manifest on |
| 201 // Mac). | 195 // Mac). |
| 202 NOTREACHED(); | 196 NOTREACHED(); |
| 203 return base::File(); | 197 return base::File(); |
| 204 } | 198 } |
| 205 | 199 |
| 206 } // namespace internal | 200 } // namespace internal |
| 207 } // namespace content | 201 } // namespace content |
| OLD | NEW |