| 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 "content/common/sandbox_win.h" | 5 #include "content/common/sandbox_win.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 CHECK(NT_SUCCESS(error)); | 477 CHECK(NT_SUCCESS(error)); |
| 478 type_info->Name.Buffer[type_info->Name.Length / sizeof(wchar_t)] = L'\0'; | 478 type_info->Name.Buffer[type_info->Name.Length / sizeof(wchar_t)] = L'\0'; |
| 479 | 479 |
| 480 // Get the object basic information. | 480 // Get the object basic information. |
| 481 OBJECT_BASIC_INFORMATION basic_info; | 481 OBJECT_BASIC_INFORMATION basic_info; |
| 482 size = sizeof(basic_info); | 482 size = sizeof(basic_info); |
| 483 error = g_QueryObject(handle, ObjectBasicInformation, &basic_info, size, | 483 error = g_QueryObject(handle, ObjectBasicInformation, &basic_info, size, |
| 484 &size); | 484 &size); |
| 485 CHECK(NT_SUCCESS(error)); | 485 CHECK(NT_SUCCESS(error)); |
| 486 | 486 |
| 487 CHECK(!(basic_info.GrantedAccess & WRITE_DAC)) << | 487 CHECK(!(basic_info.GrantedAccess & WRITE_DAC)); |
| 488 kDuplicateHandleWarning; | |
| 489 | 488 |
| 490 if (0 == _wcsicmp(type_info->Name.Buffer, L"Process")) { | 489 if (0 == _wcsicmp(type_info->Name.Buffer, L"Process")) { |
| 491 const ACCESS_MASK kDangerousMask = | 490 const ACCESS_MASK kDangerousMask = |
| 492 ~static_cast<DWORD>(PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE); | 491 ~static_cast<DWORD>(PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE); |
| 493 CHECK(!(basic_info.GrantedAccess & kDangerousMask)) << | 492 CHECK(!(basic_info.GrantedAccess & kDangerousMask)); |
| 494 kDuplicateHandleWarning; | |
| 495 } | 493 } |
| 496 } | 494 } |
| 497 | 495 |
| 498 BOOL WINAPI DuplicateHandlePatch(HANDLE source_process_handle, | 496 BOOL WINAPI DuplicateHandlePatch(HANDLE source_process_handle, |
| 499 HANDLE source_handle, | 497 HANDLE source_handle, |
| 500 HANDLE target_process_handle, | 498 HANDLE target_process_handle, |
| 501 LPHANDLE target_handle, | 499 LPHANDLE target_handle, |
| 502 DWORD desired_access, | 500 DWORD desired_access, |
| 503 BOOL inherit_handle, | 501 BOOL inherit_handle, |
| 504 DWORD options) { | 502 DWORD options) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 525 &temp_handle, | 523 &temp_handle, |
| 526 PROCESS_QUERY_INFORMATION, | 524 PROCESS_QUERY_INFORMATION, |
| 527 FALSE, 0)); | 525 FALSE, 0)); |
| 528 base::win::ScopedHandle process(temp_handle); | 526 base::win::ScopedHandle process(temp_handle); |
| 529 CHECK(::IsProcessInJob(process.Get(), NULL, &is_in_job)); | 527 CHECK(::IsProcessInJob(process.Get(), NULL, &is_in_job)); |
| 530 } | 528 } |
| 531 } | 529 } |
| 532 | 530 |
| 533 if (is_in_job) { | 531 if (is_in_job) { |
| 534 // We never allow inheritable child handles. | 532 // We never allow inheritable child handles. |
| 535 CHECK(!inherit_handle) << kDuplicateHandleWarning; | 533 CHECK(!inherit_handle); |
| 536 | 534 |
| 537 // Duplicate the handle again, to get the final permissions. | 535 // Duplicate the handle again, to get the final permissions. |
| 538 HANDLE temp_handle; | 536 HANDLE temp_handle; |
| 539 CHECK(g_iat_orig_duplicate_handle(target_process_handle, *target_handle, | 537 CHECK(g_iat_orig_duplicate_handle(target_process_handle, *target_handle, |
| 540 ::GetCurrentProcess(), &temp_handle, | 538 ::GetCurrentProcess(), &temp_handle, |
| 541 0, FALSE, DUPLICATE_SAME_ACCESS)); | 539 0, FALSE, DUPLICATE_SAME_ACCESS)); |
| 542 base::win::ScopedHandle handle(temp_handle); | 540 base::win::ScopedHandle handle(temp_handle); |
| 543 | 541 |
| 544 // Callers use CHECK macro to make sure we get the right stack. | 542 // Callers use CHECK macro to make sure we get the right stack. |
| 545 CheckDuplicateHandle(handle.Get()); | 543 CheckDuplicateHandle(handle.Get()); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 } | 830 } |
| 833 | 831 |
| 834 delegate->PostSpawnTarget(target.process_handle()); | 832 delegate->PostSpawnTarget(target.process_handle()); |
| 835 | 833 |
| 836 CHECK(ResumeThread(target.thread_handle()) != static_cast<DWORD>(-1)); | 834 CHECK(ResumeThread(target.thread_handle()) != static_cast<DWORD>(-1)); |
| 837 *process = base::Process(target.TakeProcessHandle()); | 835 *process = base::Process(target.TakeProcessHandle()); |
| 838 return sandbox::SBOX_ALL_OK; | 836 return sandbox::SBOX_ALL_OK; |
| 839 } | 837 } |
| 840 | 838 |
| 841 } // namespace content | 839 } // namespace content |
| OLD | NEW |