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 && | 739 if (type_str == switches::kRendererProcess && |
739 IsWin32kRendererLockdownEnabled()) { | 740 IsWin32kRendererLockdownEnabled()) { |
740 result = AddWin32kLockdownPolicy(policy, false); | 741 result = AddWin32kLockdownPolicy(policy.get(), false); |
741 if (result != sandbox::SBOX_ALL_OK) | 742 if (result != sandbox::SBOX_ALL_OK) |
742 return result; | 743 return result; |
743 } | 744 } |
744 #endif | 745 #endif |
745 | 746 |
746 // Post-startup mitigations. | 747 // Post-startup mitigations. |
747 mitigations = sandbox::MITIGATION_STRICT_HANDLE_CHECKS | | 748 mitigations = sandbox::MITIGATION_STRICT_HANDLE_CHECKS | |
748 sandbox::MITIGATION_DLL_SEARCH_ORDER; | 749 sandbox::MITIGATION_DLL_SEARCH_ORDER; |
749 | 750 |
750 result = policy->SetDelayedProcessMitigations(mitigations); | 751 result = policy->SetDelayedProcessMitigations(mitigations); |
751 if (result != sandbox::SBOX_ALL_OK) | 752 if (result != sandbox::SBOX_ALL_OK) |
752 return result; | 753 return result; |
753 | 754 |
754 result = SetJobLevel(*cmd_line, sandbox::JOB_LOCKDOWN, 0, policy); | 755 result = SetJobLevel(*cmd_line, sandbox::JOB_LOCKDOWN, 0, policy.get()); |
755 if (result != sandbox::SBOX_ALL_OK) | 756 if (result != sandbox::SBOX_ALL_OK) |
756 return result; | 757 return result; |
757 | 758 |
758 if (!delegate->DisableDefaultPolicy()) { | 759 if (!delegate->DisableDefaultPolicy()) { |
759 result = AddPolicyForSandboxedProcess(policy); | 760 result = AddPolicyForSandboxedProcess(policy.get()); |
760 if (result != sandbox::SBOX_ALL_OK) | 761 if (result != sandbox::SBOX_ALL_OK) |
761 return result; | 762 return result; |
762 } | 763 } |
763 | 764 |
764 #if !defined(NACL_WIN64) | 765 #if !defined(NACL_WIN64) |
765 if (type_str == switches::kRendererProcess || | 766 if (type_str == switches::kRendererProcess || |
766 type_str == switches::kPpapiPluginProcess) { | 767 type_str == switches::kPpapiPluginProcess) { |
767 AddDirectory(base::DIR_WINDOWS_FONTS, NULL, true, | 768 AddDirectory(base::DIR_WINDOWS_FONTS, NULL, true, |
768 sandbox::TargetPolicy::FILES_ALLOW_READONLY, policy); | 769 sandbox::TargetPolicy::FILES_ALLOW_READONLY, policy.get()); |
769 } | 770 } |
770 #endif | 771 #endif |
771 | 772 |
772 if (type_str != switches::kRendererProcess) { | 773 if (type_str != switches::kRendererProcess) { |
773 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into | 774 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into |
774 // this subprocess. See | 775 // this subprocess. See |
775 // http://code.google.com/p/chromium/issues/detail?id=25580 | 776 // http://code.google.com/p/chromium/issues/detail?id=25580 |
776 cmd_line->AppendSwitchASCII("ignored", " --type=renderer "); | 777 cmd_line->AppendSwitchASCII("ignored", " --type=renderer "); |
777 } | 778 } |
778 | 779 |
779 result = AddGenericPolicy(policy); | 780 result = AddGenericPolicy(policy.get()); |
780 | 781 |
781 if (result != sandbox::SBOX_ALL_OK) { | 782 if (result != sandbox::SBOX_ALL_OK) { |
782 NOTREACHED(); | 783 NOTREACHED(); |
783 return result; | 784 return result; |
784 } | 785 } |
785 | 786 |
786 // Allow the renderer and gpu processes to access the log file. | 787 // Allow the renderer and gpu processes to access the log file. |
787 if (type_str == switches::kRendererProcess || | 788 if (type_str == switches::kRendererProcess || |
788 type_str == switches::kGpuProcess) { | 789 type_str == switches::kGpuProcess) { |
789 if (logging::IsLoggingToFileEnabled()) { | 790 if (logging::IsLoggingToFileEnabled()) { |
790 DCHECK(base::FilePath(logging::GetLogFileFullPath()).IsAbsolute()); | 791 DCHECK(base::FilePath(logging::GetLogFileFullPath()).IsAbsolute()); |
791 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, | 792 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, |
792 sandbox::TargetPolicy::FILES_ALLOW_ANY, | 793 sandbox::TargetPolicy::FILES_ALLOW_ANY, |
793 logging::GetLogFileFullPath().c_str()); | 794 logging::GetLogFileFullPath().c_str()); |
794 if (result != sandbox::SBOX_ALL_OK) | 795 if (result != sandbox::SBOX_ALL_OK) |
795 return result; | 796 return result; |
796 } | 797 } |
797 } | 798 } |
798 | 799 |
799 // If stdout/stderr point to a Windows console, these calls will | 800 // If stdout/stderr point to a Windows console, these calls will |
800 // have no effect. These calls can fail with SBOX_ERROR_BAD_PARAMS. | 801 // have no effect. These calls can fail with SBOX_ERROR_BAD_PARAMS. |
801 policy->SetStdoutHandle(GetStdHandle(STD_OUTPUT_HANDLE)); | 802 policy->SetStdoutHandle(GetStdHandle(STD_OUTPUT_HANDLE)); |
802 policy->SetStderrHandle(GetStdHandle(STD_ERROR_HANDLE)); | 803 policy->SetStderrHandle(GetStdHandle(STD_ERROR_HANDLE)); |
803 | 804 |
804 if (!delegate->PreSpawnTarget(policy)) | 805 if (!delegate->PreSpawnTarget(policy.get())) |
805 return sandbox::SBOX_ERROR_DELEGATE_PRE_SPAWN; | 806 return sandbox::SBOX_ERROR_DELEGATE_PRE_SPAWN; |
806 | 807 |
807 TRACE_EVENT_BEGIN0("startup", "StartProcessWithAccess::LAUNCHPROCESS"); | 808 TRACE_EVENT_BEGIN0("startup", "StartProcessWithAccess::LAUNCHPROCESS"); |
808 | 809 |
809 PROCESS_INFORMATION temp_process_info = {}; | 810 PROCESS_INFORMATION temp_process_info = {}; |
810 sandbox::ResultCode last_warning = sandbox::SBOX_ALL_OK; | 811 sandbox::ResultCode last_warning = sandbox::SBOX_ALL_OK; |
811 DWORD last_error = ERROR_SUCCESS; | 812 DWORD last_error = ERROR_SUCCESS; |
812 result = g_broker_services->SpawnTarget( | 813 result = g_broker_services->SpawnTarget( |
813 cmd_line->GetProgram().value().c_str(), | 814 cmd_line->GetProgram().value().c_str(), |
814 cmd_line->GetCommandLineString().c_str(), policy, &last_warning, | 815 cmd_line->GetCommandLineString().c_str(), policy, &last_warning, |
(...skipping 18 matching lines...) Expand all Loading... |
833 } | 834 } |
834 | 835 |
835 delegate->PostSpawnTarget(target.process_handle()); | 836 delegate->PostSpawnTarget(target.process_handle()); |
836 | 837 |
837 CHECK(ResumeThread(target.thread_handle()) != static_cast<DWORD>(-1)); | 838 CHECK(ResumeThread(target.thread_handle()) != static_cast<DWORD>(-1)); |
838 *process = base::Process(target.TakeProcessHandle()); | 839 *process = base::Process(target.TakeProcessHandle()); |
839 return sandbox::SBOX_ALL_OK; | 840 return sandbox::SBOX_ALL_OK; |
840 } | 841 } |
841 | 842 |
842 } // namespace content | 843 } // namespace content |
OLD | NEW |