OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sandbox/win/src/target_process.h" | 5 #include "sandbox/win/src/target_process.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/win/pe_image.h" | 9 #include "base/win/pe_image.h" |
| 10 #include "base/win/startup_information.h" |
10 #include "base/win/windows_version.h" | 11 #include "base/win/windows_version.h" |
11 #include "sandbox/win/src/crosscall_server.h" | 12 #include "sandbox/win/src/crosscall_server.h" |
12 #include "sandbox/win/src/crosscall_client.h" | 13 #include "sandbox/win/src/crosscall_client.h" |
13 #include "sandbox/win/src/policy_low_level.h" | 14 #include "sandbox/win/src/policy_low_level.h" |
14 #include "sandbox/win/src/sandbox_types.h" | 15 #include "sandbox/win/src/sandbox_types.h" |
15 #include "sandbox/win/src/sharedmem_ipc_server.h" | 16 #include "sandbox/win/src/sharedmem_ipc_server.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 void CopyPolicyToTarget(const void* source, size_t size, void* dest) { | 20 void CopyPolicyToTarget(const void* source, size_t size, void* dest) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 124 |
124 // ipc_server_ references our process handle, so make sure the former is shut | 125 // ipc_server_ references our process handle, so make sure the former is shut |
125 // down before the latter is closed (by ScopedProcessInformation). | 126 // down before the latter is closed (by ScopedProcessInformation). |
126 ipc_server_.reset(); | 127 ipc_server_.reset(); |
127 } | 128 } |
128 | 129 |
129 // Creates the target (child) process suspended and assigns it to the job | 130 // Creates the target (child) process suspended and assigns it to the job |
130 // object. | 131 // object. |
131 DWORD TargetProcess::Create(const wchar_t* exe_path, | 132 DWORD TargetProcess::Create(const wchar_t* exe_path, |
132 const wchar_t* command_line, | 133 const wchar_t* command_line, |
133 const wchar_t* desktop, | 134 const base::win::StartupInformation& startup_info, |
134 base::win::ScopedProcessInformation* target_info) { | 135 base::win::ScopedProcessInformation* target_info) { |
135 exe_name_.reset(_wcsdup(exe_path)); | 136 exe_name_.reset(_wcsdup(exe_path)); |
136 | 137 |
137 // the command line needs to be writable by CreateProcess(). | 138 // the command line needs to be writable by CreateProcess(). |
138 scoped_ptr_malloc<wchar_t> cmd_line(_wcsdup(command_line)); | 139 scoped_ptr_malloc<wchar_t> cmd_line(_wcsdup(command_line)); |
139 scoped_ptr_malloc<wchar_t> desktop_name(desktop ? _wcsdup(desktop) : NULL); | |
140 | 140 |
141 // Start the target process suspended. | 141 // Start the target process suspended. |
142 DWORD flags = | 142 DWORD flags = |
143 CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT | DETACHED_PROCESS; | 143 CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT | DETACHED_PROCESS; |
144 | 144 |
| 145 if (startup_info.has_extended_startup_info()) |
| 146 flags |= EXTENDED_STARTUPINFO_PRESENT; |
| 147 |
145 if (base::win::GetVersion() < base::win::VERSION_WIN8) { | 148 if (base::win::GetVersion() < base::win::VERSION_WIN8) { |
146 // Windows 8 implements nested jobs, but for older systems we need to | 149 // Windows 8 implements nested jobs, but for older systems we need to |
147 // break out of any job we're in to enforce our restrictions. | 150 // break out of any job we're in to enforce our restrictions. |
148 flags |= CREATE_BREAKAWAY_FROM_JOB; | 151 flags |= CREATE_BREAKAWAY_FROM_JOB; |
149 } | 152 } |
150 | 153 |
151 STARTUPINFO startup_info = {sizeof(STARTUPINFO)}; | |
152 if (desktop) { | |
153 startup_info.lpDesktop = desktop_name.get(); | |
154 } | |
155 | |
156 base::win::ScopedProcessInformation process_info; | 154 base::win::ScopedProcessInformation process_info; |
157 | 155 |
158 if (!::CreateProcessAsUserW(lockdown_token_, | 156 if (!::CreateProcessAsUserW(lockdown_token_, |
159 exe_path, | 157 exe_path, |
160 cmd_line.get(), | 158 cmd_line.get(), |
161 NULL, // No security attribute. | 159 NULL, // No security attribute. |
162 NULL, // No thread attribute. | 160 NULL, // No thread attribute. |
163 FALSE, // Do not inherit handles. | 161 FALSE, // Do not inherit handles. |
164 flags, | 162 flags, |
165 NULL, // Use the environment of the caller. | 163 NULL, // Use the environment of the caller. |
166 NULL, // Use current directory of the caller. | 164 NULL, // Use current directory of the caller. |
167 &startup_info, | 165 startup_info.startup_info(), |
168 process_info.Receive())) { | 166 process_info.Receive())) { |
169 return ::GetLastError(); | 167 return ::GetLastError(); |
170 } | 168 } |
171 lockdown_token_.Close(); | 169 lockdown_token_.Close(); |
172 | 170 |
173 PoisonLowerAddressRange(process_info.process_handle()); | 171 PoisonLowerAddressRange(process_info.process_handle()); |
174 | 172 |
175 DWORD win_result = ERROR_SUCCESS; | 173 DWORD win_result = ERROR_SUCCESS; |
176 | 174 |
177 // Assign the suspended target to the windows job object | 175 // Assign the suspended target to the windows job object |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 347 |
350 | 348 |
351 TargetProcess* MakeTestTargetProcess(HANDLE process, HMODULE base_address) { | 349 TargetProcess* MakeTestTargetProcess(HANDLE process, HMODULE base_address) { |
352 TargetProcess* target = new TargetProcess(NULL, NULL, NULL, NULL); | 350 TargetProcess* target = new TargetProcess(NULL, NULL, NULL, NULL); |
353 target->sandbox_process_info_.Receive()->hProcess = process; | 351 target->sandbox_process_info_.Receive()->hProcess = process; |
354 target->base_address_ = base_address; | 352 target->base_address_ = base_address; |
355 return target; | 353 return target; |
356 } | 354 } |
357 | 355 |
358 } // namespace sandbox | 356 } // namespace sandbox |
OLD | NEW |