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_policy.h" | 5 #include "content/common/sandbox_policy.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/debugger.h" | 10 #include "base/debug/debugger.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 // Adds policy rules for unloaded the known dlls that cause chrome to crash. | 237 // Adds policy rules for unloaded the known dlls that cause chrome to crash. |
238 // Eviction of injected DLLs is done by the sandbox so that the injected module | 238 // Eviction of injected DLLs is done by the sandbox so that the injected module |
239 // does not get a chance to execute any code. | 239 // does not get a chance to execute any code. |
240 void AddGenericDllEvictionPolicy(sandbox::TargetPolicy* policy) { | 240 void AddGenericDllEvictionPolicy(sandbox::TargetPolicy* policy) { |
241 for (int ix = 0; ix != arraysize(kTroublesomeDlls); ++ix) | 241 for (int ix = 0; ix != arraysize(kTroublesomeDlls); ++ix) |
242 BlacklistAddOneDll(kTroublesomeDlls[ix], true, policy); | 242 BlacklistAddOneDll(kTroublesomeDlls[ix], true, policy); |
243 } | 243 } |
244 | 244 |
245 // Same as AddGenericDllEvictionPolicy but specifically for plugins. In this | 245 // Same as AddGenericDllEvictionPolicy but specifically for plugins. In this |
246 // case we add the blacklisted dlls even if they are not loaded in this process. | 246 // case we add the blacklisted dlls even if they are not loaded in this process. |
247 void AddPluginDllEvictionPolicy(sandbox::TargetPolicy* policy) { | 247 void AddPluginDllEvictionPolicy(sandbox::TargetPolicy* policy) { |
cpu_(ooo_6.6-7.5)
2012/10/04 17:46:40
It seems the pepper plugin does not use this code
jschuh
2012/10/04 22:14:53
Done.
| |
248 for (int ix = 0; ix != arraysize(kTroublesomePluginDlls); ++ix) | 248 for (int ix = 0; ix != arraysize(kTroublesomePluginDlls); ++ix) |
249 BlacklistAddOneDll(kTroublesomePluginDlls[ix], false, policy); | 249 BlacklistAddOneDll(kTroublesomePluginDlls[ix], false, policy); |
250 } | 250 } |
251 | 251 |
252 // Same as AddGenericDllEvictionPolicy but specifically for the GPU process. | 252 // Same as AddGenericDllEvictionPolicy but specifically for the GPU process. |
253 // In this we add the blacklisted dlls even if they are not loaded in this | 253 // In this we add the blacklisted dlls even if they are not loaded in this |
254 // process. | 254 // process. |
255 void AddGpuDllEvictionPolicy(sandbox::TargetPolicy* policy) { | 255 void AddGpuDllEvictionPolicy(sandbox::TargetPolicy* policy) { |
256 for (int ix = 0; ix != arraysize(kTroublesomeGpuDlls); ++ix) | 256 for (int ix = 0; ix != arraysize(kTroublesomeGpuDlls); ++ix) |
257 BlacklistAddOneDll(kTroublesomeGpuDlls[ix], false, policy); | 257 BlacklistAddOneDll(kTroublesomeGpuDlls[ix], false, policy); |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
700 } | 700 } |
701 | 701 |
702 bool child_needs_help = | 702 bool child_needs_help = |
703 DebugFlags::ProcessDebugFlags(cmd_line, type, in_sandbox); | 703 DebugFlags::ProcessDebugFlags(cmd_line, type, in_sandbox); |
704 | 704 |
705 // Prefetch hints on windows: | 705 // Prefetch hints on windows: |
706 // Using a different prefetch profile per process type will allow Windows | 706 // Using a different prefetch profile per process type will allow Windows |
707 // to create separate pretetch settings for browser, renderer etc. | 707 // to create separate pretetch settings for browser, renderer etc. |
708 cmd_line->AppendArg(base::StringPrintf("/prefetch:%d", type)); | 708 cmd_line->AppendArg(base::StringPrintf("/prefetch:%d", type)); |
709 | 709 |
710 sandbox::ResultCode result; | |
711 base::win::ScopedProcessInformation target; | 710 base::win::ScopedProcessInformation target; |
712 sandbox::TargetPolicy* policy = g_broker_services->CreatePolicy(); | 711 sandbox::TargetPolicy* policy = g_broker_services->CreatePolicy(); |
713 | 712 |
714 #if !defined(NACL_WIN64) // We don't need this code on win nacl64. | |
715 if (type == content::PROCESS_TYPE_PLUGIN && | |
716 !browser_command_line.HasSwitch(switches::kNoSandbox) && | |
717 content::GetContentClient()->SandboxPlugin(cmd_line, policy)) { | |
718 in_sandbox = true; | |
719 } | |
720 #endif | |
721 | |
722 if (!in_sandbox) { | 713 if (!in_sandbox) { |
cpu_(ooo_6.6-7.5)
2012/10/04 17:46:40
we don't need to create policy (line 711) and then
jschuh
2012/10/04 22:14:53
Done.
| |
723 policy->Release(); | 714 policy->Release(); |
724 base::ProcessHandle process = 0; | 715 base::ProcessHandle process = 0; |
725 base::LaunchProcess(*cmd_line, base::LaunchOptions(), &process); | 716 base::LaunchProcess(*cmd_line, base::LaunchOptions(), &process); |
726 g_broker_services->AddTargetPeer(process); | 717 g_broker_services->AddTargetPeer(process); |
727 return process; | 718 return process; |
728 } | 719 } |
729 | 720 |
730 // TODO(jschuh): Make NaCl work with DEP and SEHOP. crbug.com/147752 | 721 // TODO(jschuh): Make NaCl work with DEP and SEHOP. crbug.com/147752 |
731 sandbox::MitigationFlags mitigations = MITIGATION_HEAP_TERMINATE | | 722 sandbox::MitigationFlags mitigations = MITIGATION_HEAP_TERMINATE | |
732 MITIGATION_BOTTOM_UP_ASLR | | 723 MITIGATION_BOTTOM_UP_ASLR | |
(...skipping 15 matching lines...) Expand all Loading... | |
748 MITIGATION_EXTENSION_DLL_DISABLE | | 739 MITIGATION_EXTENSION_DLL_DISABLE | |
749 MITIGATION_DLL_SEARCH_ORDER; | 740 MITIGATION_DLL_SEARCH_ORDER; |
750 #if defined(NACL_WIN64) | 741 #if defined(NACL_WIN64) |
751 mitigations |= MITIGATION_DEP | | 742 mitigations |= MITIGATION_DEP | |
752 MITIGATION_DEP_NO_ATL_THUNK; | 743 MITIGATION_DEP_NO_ATL_THUNK; |
753 #endif | 744 #endif |
754 | 745 |
755 if (policy->SetDelayedProcessMitigations(mitigations) != sandbox::SBOX_ALL_OK) | 746 if (policy->SetDelayedProcessMitigations(mitigations) != sandbox::SBOX_ALL_OK) |
756 return 0; | 747 return 0; |
757 | 748 |
758 if (type == content::PROCESS_TYPE_PLUGIN) { | 749 if (type == content::PROCESS_TYPE_GPU) { |
759 AddGenericDllEvictionPolicy(policy); | |
760 AddPluginDllEvictionPolicy(policy); | |
761 } else if (type == content::PROCESS_TYPE_GPU) { | |
762 if (!AddPolicyForGPU(cmd_line, policy)) | 750 if (!AddPolicyForGPU(cmd_line, policy)) |
763 return 0; | 751 return 0; |
764 } else { | 752 } else { |
765 if (!AddPolicyForRenderer(policy)) | 753 if (!AddPolicyForRenderer(policy)) |
766 return 0; | 754 return 0; |
767 // TODO(jschuh): Need get these restrictions applied to NaCl and Pepper. | 755 // TODO(jschuh): Need get these restrictions applied to NaCl and Pepper. |
768 // Just have to figure out what needs to be warmed up first. | 756 // Just have to figure out what needs to be warmed up first. |
769 if (type == content::PROCESS_TYPE_RENDERER || | 757 if (type == content::PROCESS_TYPE_RENDERER || |
770 type == content::PROCESS_TYPE_WORKER) { | 758 type == content::PROCESS_TYPE_WORKER) { |
771 AddBaseHandleClosePolicy(policy); | 759 AddBaseHandleClosePolicy(policy); |
772 } | 760 } |
773 | 761 |
774 // Pepper uses the renderer's policy, whith some tweaks. | 762 // Pepper uses the renderer's policy, whith some tweaks. |
775 if (cmd_line->HasSwitch(switches::kGuestRenderer) || | 763 if (cmd_line->HasSwitch(switches::kGuestRenderer) || |
776 type == content::PROCESS_TYPE_PPAPI_PLUGIN) { | 764 type == content::PROCESS_TYPE_PPAPI_PLUGIN) { |
777 if (!AddPolicyForPepperPlugin(policy)) | 765 if (!AddPolicyForPepperPlugin(policy)) |
778 return 0; | 766 return 0; |
779 } | 767 } |
780 | 768 |
781 | 769 |
782 if (type_str != switches::kRendererProcess) { | 770 if (type_str != switches::kRendererProcess) { |
783 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into | 771 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into |
784 // this subprocess. See | 772 // this subprocess. See |
785 // http://code.google.com/p/chromium/issues/detail?id=25580 | 773 // http://code.google.com/p/chromium/issues/detail?id=25580 |
786 cmd_line->AppendSwitchASCII("ignored", " --type=renderer "); | 774 cmd_line->AppendSwitchASCII("ignored", " --type=renderer "); |
787 } | 775 } |
788 } | 776 } |
789 | 777 |
778 sandbox::ResultCode result; | |
790 if (!exposed_dir.empty()) { | 779 if (!exposed_dir.empty()) { |
791 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, | 780 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, |
792 sandbox::TargetPolicy::FILES_ALLOW_ANY, | 781 sandbox::TargetPolicy::FILES_ALLOW_ANY, |
793 exposed_dir.value().c_str()); | 782 exposed_dir.value().c_str()); |
794 if (result != sandbox::SBOX_ALL_OK) | 783 if (result != sandbox::SBOX_ALL_OK) |
795 return 0; | 784 return 0; |
796 | 785 |
797 FilePath exposed_files = exposed_dir.AppendASCII("*"); | 786 FilePath exposed_files = exposed_dir.AppendASCII("*"); |
798 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, | 787 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, |
799 sandbox::TargetPolicy::FILES_ALLOW_ANY, | 788 sandbox::TargetPolicy::FILES_ALLOW_ANY, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
894 return g_broker_services->AddTargetPeer(peer_process) == sandbox::SBOX_ALL_OK; | 883 return g_broker_services->AddTargetPeer(peer_process) == sandbox::SBOX_ALL_OK; |
895 } | 884 } |
896 | 885 |
897 base::ProcessHandle StartProcessWithAccess( | 886 base::ProcessHandle StartProcessWithAccess( |
898 CommandLine* cmd_line, | 887 CommandLine* cmd_line, |
899 const FilePath& exposed_dir) { | 888 const FilePath& exposed_dir) { |
900 return sandbox::StartProcessWithAccess(cmd_line, exposed_dir); | 889 return sandbox::StartProcessWithAccess(cmd_line, exposed_dir); |
901 } | 890 } |
902 | 891 |
903 } // namespace content | 892 } // namespace content |
OLD | NEW |