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/broker_services.h" | 5 #include "sandbox/win/src/broker_services.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
10 #include "base/win/scoped_handle.h" | 10 #include "base/win/scoped_handle.h" |
11 #include "base/win/scoped_process_information.h" | 11 #include "base/win/scoped_process_information.h" |
12 #include "base/win/startup_information.h" | 12 #include "base/win/startup_information.h" |
13 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
14 #include "sandbox/win/src/app_container.h" | 14 #include "sandbox/win/src/app_container.h" |
| 15 #include "sandbox/win/src/process_mitigations.h" |
15 #include "sandbox/win/src/sandbox_policy_base.h" | 16 #include "sandbox/win/src/sandbox_policy_base.h" |
16 #include "sandbox/win/src/sandbox.h" | 17 #include "sandbox/win/src/sandbox.h" |
17 #include "sandbox/win/src/target_process.h" | 18 #include "sandbox/win/src/target_process.h" |
18 #include "sandbox/win/src/win2k_threadpool.h" | 19 #include "sandbox/win/src/win2k_threadpool.h" |
19 #include "sandbox/win/src/win_utils.h" | 20 #include "sandbox/win/src/win_utils.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // Utility function to associate a completion port to a job object. | 24 // Utility function to associate a completion port to a job object. |
24 bool AssociateCompletionPort(HANDLE job, HANDLE port, void* key) { | 25 bool AssociateCompletionPort(HANDLE job, HANDLE port, void* key) { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 return result; | 314 return result; |
314 | 315 |
315 // Initialize the startup information from the policy. | 316 // Initialize the startup information from the policy. |
316 base::win::StartupInformation startup_info; | 317 base::win::StartupInformation startup_info; |
317 string16 desktop = policy_base->GetAlternateDesktop(); | 318 string16 desktop = policy_base->GetAlternateDesktop(); |
318 if (!desktop.empty()) { | 319 if (!desktop.empty()) { |
319 startup_info.startup_info()->lpDesktop = | 320 startup_info.startup_info()->lpDesktop = |
320 const_cast<wchar_t*>(desktop.c_str()); | 321 const_cast<wchar_t*>(desktop.c_str()); |
321 } | 322 } |
322 | 323 |
| 324 int attribute_count = 0; |
323 const AppContainerAttributes* app_container = policy_base->GetAppContainer(); | 325 const AppContainerAttributes* app_container = policy_base->GetAppContainer(); |
| 326 if (app_container) |
| 327 ++attribute_count; |
| 328 |
| 329 DWORD64 mitigations = GetProcessMitigationPolicyFlags( |
| 330 policy->GetProcessMitigations()); |
| 331 if (mitigations) |
| 332 ++attribute_count; |
| 333 |
| 334 if (!startup_info.InitializeProcThreadAttributeList(attribute_count)) |
| 335 return SBOX_ERROR_GENERIC; |
| 336 |
324 if (app_container) { | 337 if (app_container) { |
325 startup_info.InitializeProcThreadAttributeList(1); | |
326 result = app_container->ShareForStartup(&startup_info); | 338 result = app_container->ShareForStartup(&startup_info); |
327 if (SBOX_ALL_OK != result) | 339 if (SBOX_ALL_OK != result) |
328 return result; | 340 return result; |
329 } | 341 } |
330 | 342 |
| 343 if (mitigations) { |
| 344 #ifndef _WIN64 |
| 345 // A 64-bit flags attribute is illegal on 32-bit Win 7 and below. |
| 346 if (base::win::GetVersion() < base::win::VERSION_WIN8) { |
| 347 DWORD mitigations32 = static_cast<DWORD>(mitigations); |
| 348 if (!startup_info.UpdateProcThreadAttribute( |
| 349 PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY, &mitigations32, |
| 350 sizeof(mitigations32))) { |
| 351 return SBOX_ERROR_GENERIC; |
| 352 } |
| 353 } else { |
| 354 if (!startup_info.UpdateProcThreadAttribute( |
| 355 PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY, &mitigations, |
| 356 sizeof(mitigations))) { |
| 357 return SBOX_ERROR_GENERIC; |
| 358 } |
| 359 } |
| 360 #else |
| 361 if (!startup_info.UpdateProcThreadAttribute( |
| 362 PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY, &mitigations, |
| 363 sizeof(mitigations))) { |
| 364 return SBOX_ERROR_GENERIC; |
| 365 } |
| 366 #endif |
| 367 } |
| 368 |
331 // Construct the thread pool here in case it is expensive. | 369 // Construct the thread pool here in case it is expensive. |
332 // The thread pool is shared by all the targets | 370 // The thread pool is shared by all the targets |
333 if (NULL == thread_pool_) | 371 if (NULL == thread_pool_) |
334 thread_pool_ = new Win2kThreadPool(); | 372 thread_pool_ = new Win2kThreadPool(); |
335 | 373 |
336 // Create the TargetProces object and spawn the target suspended. Note that | 374 // Create the TargetProces object and spawn the target suspended. Note that |
337 // Brokerservices does not own the target object. It is owned by the Policy. | 375 // Brokerservices does not own the target object. It is owned by the Policy. |
338 base::win::ScopedProcessInformation process_info; | 376 base::win::ScopedProcessInformation process_info; |
339 TargetProcess* target = new TargetProcess(initial_token.Take(), | 377 TargetProcess* target = new TargetProcess(initial_token.Take(), |
340 lockdown_token.Take(), | 378 lockdown_token.Take(), |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 return SBOX_ERROR_UNSUPPORTED; | 473 return SBOX_ERROR_UNSUPPORTED; |
436 | 474 |
437 string16 name = LookupAppContainer(sid); | 475 string16 name = LookupAppContainer(sid); |
438 if (name.empty()) | 476 if (name.empty()) |
439 return SBOX_ERROR_INVALID_APP_CONTAINER; | 477 return SBOX_ERROR_INVALID_APP_CONTAINER; |
440 | 478 |
441 return DeleteAppContainer(sid); | 479 return DeleteAppContainer(sid); |
442 } | 480 } |
443 | 481 |
444 } // namespace sandbox | 482 } // namespace sandbox |
OLD | NEW |