Chromium Code Reviews| 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 size_t mitigation_size = sizeof(mitigations); | |
| 345 void* mitigation_ptr = &mitigations; | |
| 346 | |
| 347 #ifndef _WIN64 | |
| 348 // A 64-bit flags attribute is illegal on 32-bit Win 7 and below. | |
| 349 DWORD mitigations32 = static_cast<DWORD>(mitigations); | |
| 350 if (base::win::GetVersion() < base::win::VERSION_WIN8) { | |
| 351 mitigation_size = sizeof(mitigations32); | |
| 352 mitigation_ptr = &mitigations32; | |
| 353 } | |
| 354 #endif | |
|
cpu_(ooo_6.6-7.5)
2012/09/06 19:46:15
this would be clearer to me if instead you have so
jschuh
2012/09/07 01:14:22
Done.
| |
| 355 | |
| 356 if (!startup_info.UpdateProcThreadAttribute( | |
| 357 PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY, mitigation_ptr, | |
| 358 mitigation_size)) { | |
| 359 return SBOX_ERROR_GENERIC; | |
| 360 } | |
| 361 } | |
| 362 | |
| 331 // Construct the thread pool here in case it is expensive. | 363 // Construct the thread pool here in case it is expensive. |
| 332 // The thread pool is shared by all the targets | 364 // The thread pool is shared by all the targets |
| 333 if (NULL == thread_pool_) | 365 if (NULL == thread_pool_) |
| 334 thread_pool_ = new Win2kThreadPool(); | 366 thread_pool_ = new Win2kThreadPool(); |
| 335 | 367 |
| 336 // Create the TargetProces object and spawn the target suspended. Note that | 368 // 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. | 369 // Brokerservices does not own the target object. It is owned by the Policy. |
| 338 base::win::ScopedProcessInformation process_info; | 370 base::win::ScopedProcessInformation process_info; |
| 339 TargetProcess* target = new TargetProcess(initial_token.Take(), | 371 TargetProcess* target = new TargetProcess(initial_token.Take(), |
| 340 lockdown_token.Take(), | 372 lockdown_token.Take(), |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 return SBOX_ERROR_UNSUPPORTED; | 467 return SBOX_ERROR_UNSUPPORTED; |
| 436 | 468 |
| 437 string16 name = LookupAppContainer(sid); | 469 string16 name = LookupAppContainer(sid); |
| 438 if (name.empty()) | 470 if (name.empty()) |
| 439 return SBOX_ERROR_INVALID_APP_CONTAINER; | 471 return SBOX_ERROR_INVALID_APP_CONTAINER; |
| 440 | 472 |
| 441 return DeleteAppContainer(sid); | 473 return DeleteAppContainer(sid); |
| 442 } | 474 } |
| 443 | 475 |
| 444 } // namespace sandbox | 476 } // namespace sandbox |
| OLD | NEW |