| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 L"ssldivx.dll", // DivX. | 105 L"ssldivx.dll", // DivX. |
| 106 L"syncor11.dll", // SynthCore Midi interface. | 106 L"syncor11.dll", // SynthCore Midi interface. |
| 107 L"systools.dll", // Panda Antivirus. | 107 L"systools.dll", // Panda Antivirus. |
| 108 L"tfwah.dll", // Threatfire (PC tools). | 108 L"tfwah.dll", // Threatfire (PC tools). |
| 109 L"wblind.dll", // Stardock Object desktop. | 109 L"wblind.dll", // Stardock Object desktop. |
| 110 L"wbhelp.dll", // Stardock Object desktop. | 110 L"wbhelp.dll", // Stardock Object desktop. |
| 111 L"winstylerthemehelper.dll" // Tuneup utilities 2006. | 111 L"winstylerthemehelper.dll" // Tuneup utilities 2006. |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 // The DLLs listed here are known (or under strong suspicion) of causing crashes | 114 // The DLLs listed here are known (or under strong suspicion) of causing crashes |
| 115 // when they are loaded in the plugin process. | |
| 116 const wchar_t* const kTroublesomePluginDlls[] = { | |
| 117 L"rpmainbrowserrecordplugin.dll", // RealPlayer. | |
| 118 L"rpchromebrowserrecordhelper.dll", // RealPlayer. | |
| 119 L"rpchrome10browserrecordhelper.dll", // RealPlayer. | |
| 120 L"ycwebcamerasource.ax" // Cyberlink Camera helper. | |
| 121 L"CLRGL.ax" // Cyberlink Camera helper. | |
| 122 }; | |
| 123 | |
| 124 // The DLLs listed here are known (or under strong suspicion) of causing crashes | |
| 125 // when they are loaded in the GPU process. | 115 // when they are loaded in the GPU process. |
| 126 const wchar_t* const kTroublesomeGpuDlls[] = { | 116 const wchar_t* const kTroublesomeGpuDlls[] = { |
| 127 L"cmsetac.dll", // Unknown (suspected malware). | 117 L"cmsetac.dll", // Unknown (suspected malware). |
| 128 }; | 118 }; |
| 129 | 119 |
| 130 // Adds the policy rules for the path and path\ with the semantic |access|. | 120 // Adds the policy rules for the path and path\ with the semantic |access|. |
| 131 // If |children| is set to true, we need to add the wildcard rules to also | 121 // If |children| is set to true, we need to add the wildcard rules to also |
| 132 // apply the rule to the subfiles and subfolders. | 122 // apply the rule to the subfiles and subfolders. |
| 133 bool AddDirectory(int path, const wchar_t* sub_dir, bool children, | 123 bool AddDirectory(int path, const wchar_t* sub_dir, bool children, |
| 134 sandbox::TargetPolicy::Semantics access, | 124 sandbox::TargetPolicy::Semantics access, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 } | 225 } |
| 236 | 226 |
| 237 // Adds policy rules for unloaded the known dlls that cause chrome to crash. | 227 // 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 | 228 // Eviction of injected DLLs is done by the sandbox so that the injected module |
| 239 // does not get a chance to execute any code. | 229 // does not get a chance to execute any code. |
| 240 void AddGenericDllEvictionPolicy(sandbox::TargetPolicy* policy) { | 230 void AddGenericDllEvictionPolicy(sandbox::TargetPolicy* policy) { |
| 241 for (int ix = 0; ix != arraysize(kTroublesomeDlls); ++ix) | 231 for (int ix = 0; ix != arraysize(kTroublesomeDlls); ++ix) |
| 242 BlacklistAddOneDll(kTroublesomeDlls[ix], true, policy); | 232 BlacklistAddOneDll(kTroublesomeDlls[ix], true, policy); |
| 243 } | 233 } |
| 244 | 234 |
| 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. | |
| 247 void AddPluginDllEvictionPolicy(sandbox::TargetPolicy* policy) { | |
| 248 for (int ix = 0; ix != arraysize(kTroublesomePluginDlls); ++ix) | |
| 249 BlacklistAddOneDll(kTroublesomePluginDlls[ix], false, policy); | |
| 250 } | |
| 251 | |
| 252 // Same as AddGenericDllEvictionPolicy but specifically for the GPU process. | 235 // 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 | 236 // In this we add the blacklisted dlls even if they are not loaded in this |
| 254 // process. | 237 // process. |
| 255 void AddGpuDllEvictionPolicy(sandbox::TargetPolicy* policy) { | 238 void AddGpuDllEvictionPolicy(sandbox::TargetPolicy* policy) { |
| 256 for (int ix = 0; ix != arraysize(kTroublesomeGpuDlls); ++ix) | 239 for (int ix = 0; ix != arraysize(kTroublesomeGpuDlls); ++ix) |
| 257 BlacklistAddOneDll(kTroublesomeGpuDlls[ix], false, policy); | 240 BlacklistAddOneDll(kTroublesomeGpuDlls[ix], false, policy); |
| 258 } | 241 } |
| 259 | 242 |
| 260 // Returns the object path prepended with the current logon session. | 243 // Returns the object path prepended with the current logon session. |
| 261 string16 PrependWindowsSessionPath(const char16* object) { | 244 string16 PrependWindowsSessionPath(const char16* object) { |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 } | 730 } |
| 748 | 731 |
| 749 bool child_needs_help = | 732 bool child_needs_help = |
| 750 DebugFlags::ProcessDebugFlags(cmd_line, type, in_sandbox); | 733 DebugFlags::ProcessDebugFlags(cmd_line, type, in_sandbox); |
| 751 | 734 |
| 752 // Prefetch hints on windows: | 735 // Prefetch hints on windows: |
| 753 // Using a different prefetch profile per process type will allow Windows | 736 // Using a different prefetch profile per process type will allow Windows |
| 754 // to create separate pretetch settings for browser, renderer etc. | 737 // to create separate pretetch settings for browser, renderer etc. |
| 755 cmd_line->AppendArg(base::StringPrintf("/prefetch:%d", type)); | 738 cmd_line->AppendArg(base::StringPrintf("/prefetch:%d", type)); |
| 756 | 739 |
| 757 sandbox::ResultCode result; | |
| 758 base::win::ScopedProcessInformation target; | |
| 759 sandbox::TargetPolicy* policy = g_broker_services->CreatePolicy(); | |
| 760 | |
| 761 #if !defined(NACL_WIN64) // We don't need this code on win nacl64. | |
| 762 if (type == content::PROCESS_TYPE_PLUGIN && | |
| 763 !browser_command_line.HasSwitch(switches::kNoSandbox) && | |
| 764 content::GetContentClient()->SandboxPlugin(cmd_line, policy)) { | |
| 765 in_sandbox = true; | |
| 766 } | |
| 767 #endif | |
| 768 | |
| 769 if (!in_sandbox) { | 740 if (!in_sandbox) { |
| 770 policy->Release(); | |
| 771 base::ProcessHandle process = 0; | 741 base::ProcessHandle process = 0; |
| 772 base::LaunchProcess(*cmd_line, base::LaunchOptions(), &process); | 742 base::LaunchProcess(*cmd_line, base::LaunchOptions(), &process); |
| 773 g_broker_services->AddTargetPeer(process); | 743 g_broker_services->AddTargetPeer(process); |
| 774 return process; | 744 return process; |
| 775 } | 745 } |
| 776 | 746 |
| 747 base::win::ScopedProcessInformation target; |
| 748 sandbox::TargetPolicy* policy = g_broker_services->CreatePolicy(); |
| 749 |
| 777 // TODO(jschuh): Make NaCl work with DEP and SEHOP. crbug.com/147752 | 750 // TODO(jschuh): Make NaCl work with DEP and SEHOP. crbug.com/147752 |
| 778 sandbox::MitigationFlags mitigations = MITIGATION_HEAP_TERMINATE | | 751 sandbox::MitigationFlags mitigations = MITIGATION_HEAP_TERMINATE | |
| 779 MITIGATION_BOTTOM_UP_ASLR | | 752 MITIGATION_BOTTOM_UP_ASLR | |
| 780 MITIGATION_HIGH_ENTROPY_ASLR; | 753 MITIGATION_HIGH_ENTROPY_ASLR; |
| 781 #if !defined(NACL_WIN64) | 754 #if !defined(NACL_WIN64) |
| 782 mitigations |= MITIGATION_DEP | | 755 mitigations |= MITIGATION_DEP | |
| 783 MITIGATION_DEP_NO_ATL_THUNK | | 756 MITIGATION_DEP_NO_ATL_THUNK | |
| 784 MITIGATION_SEHOP; | 757 MITIGATION_SEHOP; |
| 785 #if defined(NDEBUG) | 758 #if defined(NDEBUG) |
| 786 mitigations |= MITIGATION_RELOCATE_IMAGE | | 759 mitigations |= MITIGATION_RELOCATE_IMAGE | |
| (...skipping 10 matching lines...) Expand all Loading... |
| 797 #if defined(NACL_WIN64) | 770 #if defined(NACL_WIN64) |
| 798 mitigations |= MITIGATION_DEP | | 771 mitigations |= MITIGATION_DEP | |
| 799 MITIGATION_DEP_NO_ATL_THUNK; | 772 MITIGATION_DEP_NO_ATL_THUNK; |
| 800 #endif | 773 #endif |
| 801 | 774 |
| 802 if (policy->SetDelayedProcessMitigations(mitigations) != sandbox::SBOX_ALL_OK) | 775 if (policy->SetDelayedProcessMitigations(mitigations) != sandbox::SBOX_ALL_OK) |
| 803 return 0; | 776 return 0; |
| 804 | 777 |
| 805 SetJobLevel(*cmd_line, JOB_LOCKDOWN, 0, policy); | 778 SetJobLevel(*cmd_line, JOB_LOCKDOWN, 0, policy); |
| 806 | 779 |
| 807 if (type == content::PROCESS_TYPE_PLUGIN) { | 780 if (type == content::PROCESS_TYPE_GPU) { |
| 808 AddGenericDllEvictionPolicy(policy); | |
| 809 AddPluginDllEvictionPolicy(policy); | |
| 810 } else if (type == content::PROCESS_TYPE_GPU) { | |
| 811 if (!AddPolicyForGPU(cmd_line, policy)) | 781 if (!AddPolicyForGPU(cmd_line, policy)) |
| 812 return 0; | 782 return 0; |
| 813 } else { | 783 } else { |
| 814 if (!AddPolicyForRenderer(policy)) | 784 if (!AddPolicyForRenderer(policy)) |
| 815 return 0; | 785 return 0; |
| 816 // TODO(jschuh): Need get these restrictions applied to NaCl and Pepper. | 786 // TODO(jschuh): Need get these restrictions applied to NaCl and Pepper. |
| 817 // Just have to figure out what needs to be warmed up first. | 787 // Just have to figure out what needs to be warmed up first. |
| 818 if (type == content::PROCESS_TYPE_RENDERER || | 788 if (type == content::PROCESS_TYPE_RENDERER || |
| 819 type == content::PROCESS_TYPE_WORKER) { | 789 type == content::PROCESS_TYPE_WORKER) { |
| 820 AddBaseHandleClosePolicy(policy); | 790 AddBaseHandleClosePolicy(policy); |
| 821 } | 791 } |
| 822 | 792 |
| 823 // Pepper uses the renderer's policy, whith some tweaks. | 793 // Pepper uses the renderer's policy, whith some tweaks. |
| 824 if (cmd_line->HasSwitch(switches::kGuestRenderer) || | 794 if (cmd_line->HasSwitch(switches::kGuestRenderer) || |
| 825 type == content::PROCESS_TYPE_PPAPI_PLUGIN) { | 795 type == content::PROCESS_TYPE_PPAPI_PLUGIN) { |
| 826 if (!AddPolicyForPepperPlugin(policy)) | 796 if (!AddPolicyForPepperPlugin(policy)) |
| 827 return 0; | 797 return 0; |
| 828 } | 798 } |
| 829 | 799 |
| 830 | 800 |
| 831 if (type_str != switches::kRendererProcess) { | 801 if (type_str != switches::kRendererProcess) { |
| 832 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into | 802 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into |
| 833 // this subprocess. See | 803 // this subprocess. See |
| 834 // http://code.google.com/p/chromium/issues/detail?id=25580 | 804 // http://code.google.com/p/chromium/issues/detail?id=25580 |
| 835 cmd_line->AppendSwitchASCII("ignored", " --type=renderer "); | 805 cmd_line->AppendSwitchASCII("ignored", " --type=renderer "); |
| 836 } | 806 } |
| 837 } | 807 } |
| 838 | 808 |
| 809 sandbox::ResultCode result; |
| 839 if (!exposed_dir.empty()) { | 810 if (!exposed_dir.empty()) { |
| 840 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, | 811 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, |
| 841 sandbox::TargetPolicy::FILES_ALLOW_ANY, | 812 sandbox::TargetPolicy::FILES_ALLOW_ANY, |
| 842 exposed_dir.value().c_str()); | 813 exposed_dir.value().c_str()); |
| 843 if (result != sandbox::SBOX_ALL_OK) | 814 if (result != sandbox::SBOX_ALL_OK) |
| 844 return 0; | 815 return 0; |
| 845 | 816 |
| 846 FilePath exposed_files = exposed_dir.AppendASCII("*"); | 817 FilePath exposed_files = exposed_dir.AppendASCII("*"); |
| 847 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, | 818 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, |
| 848 sandbox::TargetPolicy::FILES_ALLOW_ANY, | 819 sandbox::TargetPolicy::FILES_ALLOW_ANY, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 return g_broker_services->AddTargetPeer(peer_process) == sandbox::SBOX_ALL_OK; | 914 return g_broker_services->AddTargetPeer(peer_process) == sandbox::SBOX_ALL_OK; |
| 944 } | 915 } |
| 945 | 916 |
| 946 base::ProcessHandle StartProcessWithAccess( | 917 base::ProcessHandle StartProcessWithAccess( |
| 947 CommandLine* cmd_line, | 918 CommandLine* cmd_line, |
| 948 const FilePath& exposed_dir) { | 919 const FilePath& exposed_dir) { |
| 949 return sandbox::StartProcessWithAccess(cmd_line, exposed_dir); | 920 return sandbox::StartProcessWithAccess(cmd_line, exposed_dir); |
| 950 } | 921 } |
| 951 | 922 |
| 952 } // namespace content | 923 } // namespace content |
| OLD | NEW |