| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/debug/profiler.h" | 11 #include "base/debug/profiler.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/hash.h" | 13 #include "base/hash.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/shared_memory.h" | 16 #include "base/memory/shared_memory.h" |
| 16 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
| 17 #include "base/metrics/sparse_histogram.h" | 18 #include "base/metrics/sparse_histogram.h" |
| 18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 19 #include "base/process/launch.h" | 20 #include "base/process/launch.h" |
| 20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 22 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
| 23 #include "base/trace_event/trace_event.h" | 24 #include "base/trace_event/trace_event.h" |
| 24 #include "base/win/iat_patch_function.h" | 25 #include "base/win/iat_patch_function.h" |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 if ((!delegate->ShouldSandbox()) || | 685 if ((!delegate->ShouldSandbox()) || |
| 685 browser_command_line.HasSwitch(switches::kNoSandbox) || | 686 browser_command_line.HasSwitch(switches::kNoSandbox) || |
| 686 cmd_line->HasSwitch(switches::kNoSandbox)) { | 687 cmd_line->HasSwitch(switches::kNoSandbox)) { |
| 687 base::Process process = | 688 base::Process process = |
| 688 base::LaunchProcess(*cmd_line, base::LaunchOptions()); | 689 base::LaunchProcess(*cmd_line, base::LaunchOptions()); |
| 689 // TODO(rvargas) crbug.com/417532: Don't share a raw handle. | 690 // TODO(rvargas) crbug.com/417532: Don't share a raw handle. |
| 690 g_broker_services->AddTargetPeer(process.Handle()); | 691 g_broker_services->AddTargetPeer(process.Handle()); |
| 691 return process.Pass(); | 692 return process.Pass(); |
| 692 } | 693 } |
| 693 | 694 |
| 694 sandbox::TargetPolicy* policy = g_broker_services->CreatePolicy(); | 695 scoped_refptr<sandbox::TargetPolicy> policy = |
| 696 g_broker_services->CreatePolicy(); |
| 695 | 697 |
| 696 sandbox::MitigationFlags mitigations = sandbox::MITIGATION_HEAP_TERMINATE | | 698 sandbox::MitigationFlags mitigations = sandbox::MITIGATION_HEAP_TERMINATE | |
| 697 sandbox::MITIGATION_BOTTOM_UP_ASLR | | 699 sandbox::MITIGATION_BOTTOM_UP_ASLR | |
| 698 sandbox::MITIGATION_DEP | | 700 sandbox::MITIGATION_DEP | |
| 699 sandbox::MITIGATION_DEP_NO_ATL_THUNK | | 701 sandbox::MITIGATION_DEP_NO_ATL_THUNK | |
| 700 sandbox::MITIGATION_SEHOP; | 702 sandbox::MITIGATION_SEHOP; |
| 701 | 703 |
| 702 if (policy->SetProcessMitigations(mitigations) != sandbox::SBOX_ALL_OK) | 704 if (policy->SetProcessMitigations(mitigations) != sandbox::SBOX_ALL_OK) |
| 703 return base::Process(); | 705 return base::Process(); |
| 704 | 706 |
| 705 #if !defined(NACL_WIN64) | 707 #if !defined(NACL_WIN64) |
| 706 if (type_str == switches::kRendererProcess && | 708 if (type_str == switches::kRendererProcess && |
| 707 IsWin32kRendererLockdownEnabled()) { | 709 IsWin32kRendererLockdownEnabled()) { |
| 708 if (!AddWin32kLockdownPolicy(policy)) | 710 if (!AddWin32kLockdownPolicy(policy.get())) |
| 709 return base::Process(); | 711 return base::Process(); |
| 710 } | 712 } |
| 711 #endif | 713 #endif |
| 712 | 714 |
| 713 mitigations = sandbox::MITIGATION_STRICT_HANDLE_CHECKS | | 715 mitigations = sandbox::MITIGATION_STRICT_HANDLE_CHECKS | |
| 714 sandbox::MITIGATION_DLL_SEARCH_ORDER; | 716 sandbox::MITIGATION_DLL_SEARCH_ORDER; |
| 715 | 717 |
| 716 if (policy->SetDelayedProcessMitigations(mitigations) != sandbox::SBOX_ALL_OK) | 718 if (policy->SetDelayedProcessMitigations(mitigations) != sandbox::SBOX_ALL_OK) |
| 717 return base::Process(); | 719 return base::Process(); |
| 718 | 720 |
| 719 SetJobLevel(*cmd_line, sandbox::JOB_LOCKDOWN, 0, policy); | 721 SetJobLevel(*cmd_line, sandbox::JOB_LOCKDOWN, 0, policy.get()); |
| 720 | 722 |
| 721 if (!delegate->DisableDefaultPolicy()) { | 723 if (!delegate->DisableDefaultPolicy()) { |
| 722 if (!AddPolicyForSandboxedProcess(policy)) | 724 if (!AddPolicyForSandboxedProcess(policy.get())) |
| 723 return base::Process(); | 725 return base::Process(); |
| 724 } | 726 } |
| 725 | 727 |
| 726 #if !defined(NACL_WIN64) | 728 #if !defined(NACL_WIN64) |
| 727 if (type_str == switches::kRendererProcess || | 729 if (type_str == switches::kRendererProcess || |
| 728 type_str == switches::kPpapiPluginProcess) { | 730 type_str == switches::kPpapiPluginProcess) { |
| 729 if (gfx::win::ShouldUseDirectWrite()) { | 731 if (gfx::win::ShouldUseDirectWrite()) { |
| 730 AddDirectory(base::DIR_WINDOWS_FONTS, | 732 AddDirectory(base::DIR_WINDOWS_FONTS, |
| 731 NULL, | 733 NULL, |
| 732 true, | 734 true, |
| 733 sandbox::TargetPolicy::FILES_ALLOW_READONLY, | 735 sandbox::TargetPolicy::FILES_ALLOW_READONLY, |
| 734 policy); | 736 policy.get()); |
| 735 | 737 |
| 736 // If DirectWrite is enabled for font rendering then open the font cache | 738 // If DirectWrite is enabled for font rendering then open the font cache |
| 737 // section which is created by the browser and pass the handle to the | 739 // section which is created by the browser and pass the handle to the |
| 738 // renderer process. This is needed because renderer processes on | 740 // renderer process. This is needed because renderer processes on |
| 739 // Windows 8+ may be running in an AppContainer sandbox and hence their | 741 // Windows 8+ may be running in an AppContainer sandbox and hence their |
| 740 // kernel object namespace may be partitioned. | 742 // kernel object namespace may be partitioned. |
| 741 std::string name(content::kFontCacheSharedSectionName); | 743 std::string name(content::kFontCacheSharedSectionName); |
| 742 name.append(base::UintToString(base::GetCurrentProcId())); | 744 name.append(base::UintToString(base::GetCurrentProcId())); |
| 743 | 745 |
| 744 base::SharedMemory direct_write_font_cache_section; | 746 base::SharedMemory direct_write_font_cache_section; |
| 745 if (direct_write_font_cache_section.Open(name, true)) { | 747 if (direct_write_font_cache_section.Open(name, true)) { |
| 746 void* shared_handle = policy->AddHandleToShare( | 748 void* shared_handle = policy->AddHandleToShare( |
| 747 direct_write_font_cache_section.handle().GetHandle()); | 749 direct_write_font_cache_section.handle().GetHandle()); |
| 748 cmd_line->AppendSwitchASCII(switches::kFontCacheSharedHandle, | 750 cmd_line->AppendSwitchASCII(switches::kFontCacheSharedHandle, |
| 749 base::UintToString(reinterpret_cast<unsigned int>(shared_handle))); | 751 base::UintToString(reinterpret_cast<unsigned int>(shared_handle))); |
| 750 } | 752 } |
| 751 } | 753 } |
| 752 } | 754 } |
| 753 #endif | 755 #endif |
| 754 | 756 |
| 755 if (type_str != switches::kRendererProcess) { | 757 if (type_str != switches::kRendererProcess) { |
| 756 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into | 758 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into |
| 757 // this subprocess. See | 759 // this subprocess. See |
| 758 // http://code.google.com/p/chromium/issues/detail?id=25580 | 760 // http://code.google.com/p/chromium/issues/detail?id=25580 |
| 759 cmd_line->AppendSwitchASCII("ignored", " --type=renderer "); | 761 cmd_line->AppendSwitchASCII("ignored", " --type=renderer "); |
| 760 } | 762 } |
| 761 | 763 |
| 762 if (!AddGenericPolicy(policy)) { | 764 if (!AddGenericPolicy(policy.get())) { |
| 763 NOTREACHED(); | 765 NOTREACHED(); |
| 764 return base::Process(); | 766 return base::Process(); |
| 765 } | 767 } |
| 766 | 768 |
| 767 // Allow the renderer and gpu processes to access the log file. | 769 // Allow the renderer and gpu processes to access the log file. |
| 768 if (type_str == switches::kRendererProcess || | 770 if (type_str == switches::kRendererProcess || |
| 769 type_str == switches::kGpuProcess) { | 771 type_str == switches::kGpuProcess) { |
| 770 if (logging::IsLoggingToFileEnabled()) { | 772 if (logging::IsLoggingToFileEnabled()) { |
| 771 DCHECK(base::FilePath(logging::GetLogFileFullPath()).IsAbsolute()); | 773 DCHECK(base::FilePath(logging::GetLogFileFullPath()).IsAbsolute()); |
| 772 policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, | 774 policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, |
| 773 sandbox::TargetPolicy::FILES_ALLOW_ANY, | 775 sandbox::TargetPolicy::FILES_ALLOW_ANY, |
| 774 logging::GetLogFileFullPath().c_str()); | 776 logging::GetLogFileFullPath().c_str()); |
| 775 } | 777 } |
| 776 } | 778 } |
| 777 | 779 |
| 778 #if !defined(OFFICIAL_BUILD) | 780 #if !defined(OFFICIAL_BUILD) |
| 779 // If stdout/stderr point to a Windows console, these calls will | 781 // If stdout/stderr point to a Windows console, these calls will |
| 780 // have no effect. | 782 // have no effect. |
| 781 policy->SetStdoutHandle(GetStdHandle(STD_OUTPUT_HANDLE)); | 783 policy->SetStdoutHandle(GetStdHandle(STD_OUTPUT_HANDLE)); |
| 782 policy->SetStderrHandle(GetStdHandle(STD_ERROR_HANDLE)); | 784 policy->SetStderrHandle(GetStdHandle(STD_ERROR_HANDLE)); |
| 783 #endif | 785 #endif |
| 784 | 786 |
| 785 if (!delegate->PreSpawnTarget(policy)) | 787 if (!delegate->PreSpawnTarget(policy.get())) |
| 786 return base::Process(); | 788 return base::Process(); |
| 787 | 789 |
| 788 TRACE_EVENT_BEGIN0("startup", "StartProcessWithAccess::LAUNCHPROCESS"); | 790 TRACE_EVENT_BEGIN0("startup", "StartProcessWithAccess::LAUNCHPROCESS"); |
| 789 | 791 |
| 790 PROCESS_INFORMATION temp_process_info = {}; | 792 PROCESS_INFORMATION temp_process_info = {}; |
| 791 sandbox::ResultCode result = g_broker_services->SpawnTarget( | 793 sandbox::ResultCode result = g_broker_services->SpawnTarget( |
| 792 cmd_line->GetProgram().value().c_str(), | 794 cmd_line->GetProgram().value().c_str(), |
| 793 cmd_line->GetCommandLineString().c_str(), policy, &temp_process_info); | 795 cmd_line->GetCommandLineString().c_str(), policy, &temp_process_info); |
| 794 DWORD last_error = ::GetLastError(); | 796 DWORD last_error = ::GetLastError(); |
| 795 base::win::ScopedProcessInformation target(temp_process_info); | 797 base::win::ScopedProcessInformation target(temp_process_info); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 } | 851 } |
| 850 | 852 |
| 851 return false; | 853 return false; |
| 852 } | 854 } |
| 853 | 855 |
| 854 bool BrokerAddTargetPeer(HANDLE peer_process) { | 856 bool BrokerAddTargetPeer(HANDLE peer_process) { |
| 855 return g_broker_services->AddTargetPeer(peer_process) == sandbox::SBOX_ALL_OK; | 857 return g_broker_services->AddTargetPeer(peer_process) == sandbox::SBOX_ALL_OK; |
| 856 } | 858 } |
| 857 | 859 |
| 858 } // namespace content | 860 } // namespace content |
| OLD | NEW |