| 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 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 if (!handles_to_inherit.empty()) { | 701 if (!handles_to_inherit.empty()) { |
| 702 options.inherit_handles = true; | 702 options.inherit_handles = true; |
| 703 options.handles_to_inherit = &handles; | 703 options.handles_to_inherit = &handles; |
| 704 } | 704 } |
| 705 base::Process unsandboxed_process = base::LaunchProcess(*cmd_line, options); | 705 base::Process unsandboxed_process = base::LaunchProcess(*cmd_line, options); |
| 706 | 706 |
| 707 *process = std::move(unsandboxed_process); | 707 *process = std::move(unsandboxed_process); |
| 708 return sandbox::SBOX_ALL_OK; | 708 return sandbox::SBOX_ALL_OK; |
| 709 } | 709 } |
| 710 | 710 |
| 711 sandbox::TargetPolicy* policy = g_broker_services->CreatePolicy(); | 711 scoped_refptr<sandbox::TargetPolicy> policy = |
| 712 g_broker_services->CreatePolicy(); |
| 712 | 713 |
| 713 // Add any handles to be inherited to the policy. | 714 // Add any handles to be inherited to the policy. |
| 714 for (HANDLE handle : handles_to_inherit) | 715 for (HANDLE handle : handles_to_inherit) |
| 715 policy->AddHandleToShare(handle); | 716 policy->AddHandleToShare(handle); |
| 716 | 717 |
| 717 // Pre-startup mitigations. | 718 // Pre-startup mitigations. |
| 718 sandbox::MitigationFlags mitigations = | 719 sandbox::MitigationFlags mitigations = |
| 719 sandbox::MITIGATION_HEAP_TERMINATE | | 720 sandbox::MITIGATION_HEAP_TERMINATE | |
| 720 sandbox::MITIGATION_BOTTOM_UP_ASLR | | 721 sandbox::MITIGATION_BOTTOM_UP_ASLR | |
| 721 sandbox::MITIGATION_DEP | | 722 sandbox::MITIGATION_DEP | |
| 722 sandbox::MITIGATION_DEP_NO_ATL_THUNK | | 723 sandbox::MITIGATION_DEP_NO_ATL_THUNK | |
| 723 sandbox::MITIGATION_SEHOP | | 724 sandbox::MITIGATION_SEHOP | |
| 724 sandbox::MITIGATION_NONSYSTEM_FONT_DISABLE | | 725 sandbox::MITIGATION_NONSYSTEM_FONT_DISABLE | |
| 725 sandbox::MITIGATION_IMAGE_LOAD_NO_REMOTE | | 726 sandbox::MITIGATION_IMAGE_LOAD_NO_REMOTE | |
| 726 sandbox::MITIGATION_IMAGE_LOAD_NO_LOW_LABEL; | 727 sandbox::MITIGATION_IMAGE_LOAD_NO_LOW_LABEL; |
| 727 | 728 |
| 728 if (base::FeatureList::IsEnabled(features::kWinSboxDisableExtensionPoints)) | 729 if (base::FeatureList::IsEnabled(features::kWinSboxDisableExtensionPoints)) |
| 729 mitigations |= sandbox::MITIGATION_EXTENSION_POINT_DISABLE; | 730 mitigations |= sandbox::MITIGATION_EXTENSION_POINT_DISABLE; |
| 730 | 731 |
| 731 sandbox::ResultCode result = sandbox::SBOX_ERROR_GENERIC; | 732 sandbox::ResultCode result = sandbox::SBOX_ERROR_GENERIC; |
| 732 result = policy->SetProcessMitigations(mitigations); | 733 result = policy->SetProcessMitigations(mitigations); |
| 733 | 734 |
| 734 if (result != sandbox::SBOX_ALL_OK) | 735 if (result != sandbox::SBOX_ALL_OK) |
| 735 return result; | 736 return result; |
| 736 | 737 |
| 737 #if !defined(NACL_WIN64) | 738 #if !defined(NACL_WIN64) |
| 738 if (type_str == switches::kRendererProcess && IsWin32kLockdownEnabled()) { | 739 if (type_str == switches::kRendererProcess && IsWin32kLockdownEnabled()) { |
| 739 result = AddWin32kLockdownPolicy(policy, false); | 740 result = AddWin32kLockdownPolicy(policy.get(), false); |
| 740 if (result != sandbox::SBOX_ALL_OK) | 741 if (result != sandbox::SBOX_ALL_OK) |
| 741 return result; | 742 return result; |
| 742 } | 743 } |
| 743 #endif | 744 #endif |
| 744 | 745 |
| 745 // Post-startup mitigations. | 746 // Post-startup mitigations. |
| 746 mitigations = sandbox::MITIGATION_STRICT_HANDLE_CHECKS | | 747 mitigations = sandbox::MITIGATION_STRICT_HANDLE_CHECKS | |
| 747 sandbox::MITIGATION_DLL_SEARCH_ORDER; | 748 sandbox::MITIGATION_DLL_SEARCH_ORDER; |
| 748 | 749 |
| 749 result = policy->SetDelayedProcessMitigations(mitigations); | 750 result = policy->SetDelayedProcessMitigations(mitigations); |
| 750 if (result != sandbox::SBOX_ALL_OK) | 751 if (result != sandbox::SBOX_ALL_OK) |
| 751 return result; | 752 return result; |
| 752 | 753 |
| 753 result = SetJobLevel(*cmd_line, sandbox::JOB_LOCKDOWN, 0, policy); | 754 result = SetJobLevel(*cmd_line, sandbox::JOB_LOCKDOWN, 0, policy.get()); |
| 754 if (result != sandbox::SBOX_ALL_OK) | 755 if (result != sandbox::SBOX_ALL_OK) |
| 755 return result; | 756 return result; |
| 756 | 757 |
| 757 if (!delegate->DisableDefaultPolicy()) { | 758 if (!delegate->DisableDefaultPolicy()) { |
| 758 result = AddPolicyForSandboxedProcess(policy); | 759 result = AddPolicyForSandboxedProcess(policy.get()); |
| 759 if (result != sandbox::SBOX_ALL_OK) | 760 if (result != sandbox::SBOX_ALL_OK) |
| 760 return result; | 761 return result; |
| 761 } | 762 } |
| 762 | 763 |
| 763 #if !defined(NACL_WIN64) | 764 #if !defined(NACL_WIN64) |
| 764 if (type_str == switches::kRendererProcess || | 765 if (type_str == switches::kRendererProcess || |
| 765 type_str == switches::kPpapiPluginProcess) { | 766 type_str == switches::kPpapiPluginProcess) { |
| 766 AddDirectory(base::DIR_WINDOWS_FONTS, NULL, true, | 767 AddDirectory(base::DIR_WINDOWS_FONTS, NULL, true, |
| 767 sandbox::TargetPolicy::FILES_ALLOW_READONLY, policy); | 768 sandbox::TargetPolicy::FILES_ALLOW_READONLY, policy.get()); |
| 768 } | 769 } |
| 769 #endif | 770 #endif |
| 770 | 771 |
| 771 if (type_str != switches::kRendererProcess) { | 772 if (type_str != switches::kRendererProcess) { |
| 772 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into | 773 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into |
| 773 // this subprocess. See | 774 // this subprocess. See |
| 774 // http://code.google.com/p/chromium/issues/detail?id=25580 | 775 // http://code.google.com/p/chromium/issues/detail?id=25580 |
| 775 cmd_line->AppendSwitchASCII("ignored", " --type=renderer "); | 776 cmd_line->AppendSwitchASCII("ignored", " --type=renderer "); |
| 776 } | 777 } |
| 777 | 778 |
| 778 result = AddGenericPolicy(policy); | 779 result = AddGenericPolicy(policy.get()); |
| 779 | 780 |
| 780 if (result != sandbox::SBOX_ALL_OK) { | 781 if (result != sandbox::SBOX_ALL_OK) { |
| 781 NOTREACHED(); | 782 NOTREACHED(); |
| 782 return result; | 783 return result; |
| 783 } | 784 } |
| 784 | 785 |
| 785 // Allow the renderer and gpu processes to access the log file. | 786 // Allow the renderer and gpu processes to access the log file. |
| 786 if (type_str == switches::kRendererProcess || | 787 if (type_str == switches::kRendererProcess || |
| 787 type_str == switches::kGpuProcess) { | 788 type_str == switches::kGpuProcess) { |
| 788 if (logging::IsLoggingToFileEnabled()) { | 789 if (logging::IsLoggingToFileEnabled()) { |
| 789 DCHECK(base::FilePath(logging::GetLogFileFullPath()).IsAbsolute()); | 790 DCHECK(base::FilePath(logging::GetLogFileFullPath()).IsAbsolute()); |
| 790 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, | 791 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, |
| 791 sandbox::TargetPolicy::FILES_ALLOW_ANY, | 792 sandbox::TargetPolicy::FILES_ALLOW_ANY, |
| 792 logging::GetLogFileFullPath().c_str()); | 793 logging::GetLogFileFullPath().c_str()); |
| 793 if (result != sandbox::SBOX_ALL_OK) | 794 if (result != sandbox::SBOX_ALL_OK) |
| 794 return result; | 795 return result; |
| 795 } | 796 } |
| 796 } | 797 } |
| 797 | 798 |
| 798 // If stdout/stderr point to a Windows console, these calls will | 799 // If stdout/stderr point to a Windows console, these calls will |
| 799 // have no effect. These calls can fail with SBOX_ERROR_BAD_PARAMS. | 800 // have no effect. These calls can fail with SBOX_ERROR_BAD_PARAMS. |
| 800 policy->SetStdoutHandle(GetStdHandle(STD_OUTPUT_HANDLE)); | 801 policy->SetStdoutHandle(GetStdHandle(STD_OUTPUT_HANDLE)); |
| 801 policy->SetStderrHandle(GetStdHandle(STD_ERROR_HANDLE)); | 802 policy->SetStderrHandle(GetStdHandle(STD_ERROR_HANDLE)); |
| 802 | 803 |
| 803 if (!delegate->PreSpawnTarget(policy)) | 804 if (!delegate->PreSpawnTarget(policy.get())) |
| 804 return sandbox::SBOX_ERROR_DELEGATE_PRE_SPAWN; | 805 return sandbox::SBOX_ERROR_DELEGATE_PRE_SPAWN; |
| 805 | 806 |
| 806 TRACE_EVENT_BEGIN0("startup", "StartProcessWithAccess::LAUNCHPROCESS"); | 807 TRACE_EVENT_BEGIN0("startup", "StartProcessWithAccess::LAUNCHPROCESS"); |
| 807 | 808 |
| 808 PROCESS_INFORMATION temp_process_info = {}; | 809 PROCESS_INFORMATION temp_process_info = {}; |
| 809 sandbox::ResultCode last_warning = sandbox::SBOX_ALL_OK; | 810 sandbox::ResultCode last_warning = sandbox::SBOX_ALL_OK; |
| 810 DWORD last_error = ERROR_SUCCESS; | 811 DWORD last_error = ERROR_SUCCESS; |
| 811 result = g_broker_services->SpawnTarget( | 812 result = g_broker_services->SpawnTarget( |
| 812 cmd_line->GetProgram().value().c_str(), | 813 cmd_line->GetProgram().value().c_str(), |
| 813 cmd_line->GetCommandLineString().c_str(), policy, &last_warning, | 814 cmd_line->GetCommandLineString().c_str(), policy, &last_warning, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 832 } | 833 } |
| 833 | 834 |
| 834 delegate->PostSpawnTarget(target.process_handle()); | 835 delegate->PostSpawnTarget(target.process_handle()); |
| 835 | 836 |
| 836 CHECK(ResumeThread(target.thread_handle()) != static_cast<DWORD>(-1)); | 837 CHECK(ResumeThread(target.thread_handle()) != static_cast<DWORD>(-1)); |
| 837 *process = base::Process(target.TakeProcessHandle()); | 838 *process = base::Process(target.TakeProcessHandle()); |
| 838 return sandbox::SBOX_ALL_OK; | 839 return sandbox::SBOX_ALL_OK; |
| 839 } | 840 } |
| 840 | 841 |
| 841 } // namespace content | 842 } // namespace content |
| OLD | NEW |