OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/common/sandbox_policy.h" | 5 #include "chrome/common/sandbox_policy.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "app/win_util.h" | 9 #include "app/win_util.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/debug_util.h" | 11 #include "base/debug_util.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
19 #include "base/trace_event.h" | 19 #include "base/trace_event.h" |
20 #include "base/win_util.h" | 20 #include "base/win/windows_version.h" |
21 #include "chrome/common/child_process_info.h" | 21 #include "chrome/common/child_process_info.h" |
22 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
23 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/debug_flags.h" | 25 #include "chrome/common/debug_flags.h" |
26 #include "sandbox/src/sandbox.h" | 26 #include "sandbox/src/sandbox.h" |
27 | 27 |
28 static sandbox::BrokerServices* g_broker_services = NULL; | 28 static sandbox::BrokerServices* g_broker_services = NULL; |
29 | 29 |
30 namespace { | 30 namespace { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 return true; | 221 return true; |
222 } | 222 } |
223 | 223 |
224 // Creates a sandbox with the plugin running in a restricted environment. | 224 // Creates a sandbox with the plugin running in a restricted environment. |
225 // Only the "Users" and "Everyone" groups are enabled in the token. The User SID | 225 // Only the "Users" and "Everyone" groups are enabled in the token. The User SID |
226 // is disabled. | 226 // is disabled. |
227 bool ApplyPolicyForUntrustedPlugin(sandbox::TargetPolicy* policy) { | 227 bool ApplyPolicyForUntrustedPlugin(sandbox::TargetPolicy* policy) { |
228 policy->SetJobLevel(sandbox::JOB_UNPROTECTED, 0); | 228 policy->SetJobLevel(sandbox::JOB_UNPROTECTED, 0); |
229 | 229 |
230 sandbox::TokenLevel initial_token = sandbox::USER_UNPROTECTED; | 230 sandbox::TokenLevel initial_token = sandbox::USER_UNPROTECTED; |
231 if (win_util::GetWinVersion() > win_util::WINVERSION_XP) { | 231 if (base::win::GetVersion() > base::win::VERSION_XP) { |
232 // On 2003/Vista the initial token has to be restricted if the main token | 232 // On 2003/Vista the initial token has to be restricted if the main token |
233 // is restricted. | 233 // is restricted. |
234 initial_token = sandbox::USER_RESTRICTED_SAME_ACCESS; | 234 initial_token = sandbox::USER_RESTRICTED_SAME_ACCESS; |
235 } | 235 } |
236 policy->SetTokenLevel(initial_token, sandbox::USER_LIMITED); | 236 policy->SetTokenLevel(initial_token, sandbox::USER_LIMITED); |
237 policy->SetDelayedIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW); | 237 policy->SetDelayedIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW); |
238 | 238 |
239 if (!AddDirectory(base::DIR_TEMP, NULL, true, | 239 if (!AddDirectory(base::DIR_TEMP, NULL, true, |
240 sandbox::TargetPolicy::FILES_ALLOW_ANY, policy)) | 240 sandbox::TargetPolicy::FILES_ALLOW_ANY, policy)) |
241 return false; | 241 return false; |
(...skipping 30 matching lines...) Expand all Loading... |
272 if (!AddKeyAndSubkeys(L"HKEY_CURRENT_USER\\SOFTWARE\\ADOBE", | 272 if (!AddKeyAndSubkeys(L"HKEY_CURRENT_USER\\SOFTWARE\\ADOBE", |
273 sandbox::TargetPolicy::REG_ALLOW_ANY, | 273 sandbox::TargetPolicy::REG_ALLOW_ANY, |
274 policy)) | 274 policy)) |
275 return false; | 275 return false; |
276 | 276 |
277 if (!AddKeyAndSubkeys(L"HKEY_CURRENT_USER\\SOFTWARE\\MACROMEDIA", | 277 if (!AddKeyAndSubkeys(L"HKEY_CURRENT_USER\\SOFTWARE\\MACROMEDIA", |
278 sandbox::TargetPolicy::REG_ALLOW_ANY, | 278 sandbox::TargetPolicy::REG_ALLOW_ANY, |
279 policy)) | 279 policy)) |
280 return false; | 280 return false; |
281 | 281 |
282 if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) { | 282 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
283 if (!AddKeyAndSubkeys(L"HKEY_CURRENT_USER\\SOFTWARE\\AppDataLow", | 283 if (!AddKeyAndSubkeys(L"HKEY_CURRENT_USER\\SOFTWARE\\AppDataLow", |
284 sandbox::TargetPolicy::REG_ALLOW_ANY, | 284 sandbox::TargetPolicy::REG_ALLOW_ANY, |
285 policy)) | 285 policy)) |
286 return false; | 286 return false; |
287 | 287 |
288 if (!AddDirectory(base::DIR_LOCAL_APP_DATA_LOW, NULL, true, | 288 if (!AddDirectory(base::DIR_LOCAL_APP_DATA_LOW, NULL, true, |
289 sandbox::TargetPolicy::FILES_ALLOW_ANY, | 289 sandbox::TargetPolicy::FILES_ALLOW_ANY, |
290 policy)) | 290 policy)) |
291 return false; | 291 return false; |
292 | 292 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // Creates a sandbox for the built-in flash plugin running in a restricted | 336 // Creates a sandbox for the built-in flash plugin running in a restricted |
337 // environment. This is a work in progress and for the time being do not | 337 // environment. This is a work in progress and for the time being do not |
338 // pay attention to the duplication between this function and the above | 338 // pay attention to the duplication between this function and the above |
339 // function. For more information see bug 50796. | 339 // function. For more information see bug 50796. |
340 bool ApplyPolicyForBuiltInFlashPlugin(sandbox::TargetPolicy* policy) { | 340 bool ApplyPolicyForBuiltInFlashPlugin(sandbox::TargetPolicy* policy) { |
341 // TODO(cpu): Lock down the job level more. | 341 // TODO(cpu): Lock down the job level more. |
342 policy->SetJobLevel(sandbox::JOB_UNPROTECTED, 0); | 342 policy->SetJobLevel(sandbox::JOB_UNPROTECTED, 0); |
343 | 343 |
344 sandbox::TokenLevel initial_token = sandbox::USER_UNPROTECTED; | 344 sandbox::TokenLevel initial_token = sandbox::USER_UNPROTECTED; |
345 | 345 |
346 if (win_util::GetWinVersion() > win_util::WINVERSION_XP) | 346 if (base::win::GetVersion() > base::win::VERSION_XP) |
347 initial_token = sandbox::USER_RESTRICTED_SAME_ACCESS; | 347 initial_token = sandbox::USER_RESTRICTED_SAME_ACCESS; |
348 | 348 |
349 policy->SetTokenLevel(initial_token, sandbox::USER_LIMITED); | 349 policy->SetTokenLevel(initial_token, sandbox::USER_LIMITED); |
350 | 350 |
351 policy->SetDelayedIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW); | 351 policy->SetDelayedIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW); |
352 | 352 |
353 // TODO(cpu): Proxy registry access and remove these policies. | 353 // TODO(cpu): Proxy registry access and remove these policies. |
354 if (!AddKeyAndSubkeys(L"HKEY_CURRENT_USER\\SOFTWARE\\ADOBE", | 354 if (!AddKeyAndSubkeys(L"HKEY_CURRENT_USER\\SOFTWARE\\ADOBE", |
355 sandbox::TargetPolicy::REG_ALLOW_ANY, | 355 sandbox::TargetPolicy::REG_ALLOW_ANY, |
356 policy)) | 356 policy)) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 } | 410 } |
411 | 411 |
412 return false; | 412 return false; |
413 } | 413 } |
414 | 414 |
415 void AddPolicyForRenderer(sandbox::TargetPolicy* policy, | 415 void AddPolicyForRenderer(sandbox::TargetPolicy* policy, |
416 bool* on_sandbox_desktop) { | 416 bool* on_sandbox_desktop) { |
417 policy->SetJobLevel(sandbox::JOB_LOCKDOWN, 0); | 417 policy->SetJobLevel(sandbox::JOB_LOCKDOWN, 0); |
418 | 418 |
419 sandbox::TokenLevel initial_token = sandbox::USER_UNPROTECTED; | 419 sandbox::TokenLevel initial_token = sandbox::USER_UNPROTECTED; |
420 if (win_util::GetWinVersion() > win_util::WINVERSION_XP) { | 420 if (base::win::GetVersion() > base::win::VERSION_XP) { |
421 // On 2003/Vista the initial token has to be restricted if the main | 421 // On 2003/Vista the initial token has to be restricted if the main |
422 // token is restricted. | 422 // token is restricted. |
423 initial_token = sandbox::USER_RESTRICTED_SAME_ACCESS; | 423 initial_token = sandbox::USER_RESTRICTED_SAME_ACCESS; |
424 } | 424 } |
425 | 425 |
426 policy->SetTokenLevel(initial_token, sandbox::USER_LOCKDOWN); | 426 policy->SetTokenLevel(initial_token, sandbox::USER_LOCKDOWN); |
427 policy->SetDelayedIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW); | 427 policy->SetDelayedIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW); |
428 | 428 |
429 bool use_winsta = !CommandLine::ForCurrentProcess()->HasSwitch( | 429 bool use_winsta = !CommandLine::ForCurrentProcess()->HasSwitch( |
430 switches::kDisableAltWinstation); | 430 switches::kDisableAltWinstation); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 | 578 |
579 // Help the process a little. It can't start the debugger by itself if | 579 // Help the process a little. It can't start the debugger by itself if |
580 // the process is in a sandbox. | 580 // the process is in a sandbox. |
581 if (child_needs_help) | 581 if (child_needs_help) |
582 DebugUtil::SpawnDebuggerOnProcess(target.dwProcessId); | 582 DebugUtil::SpawnDebuggerOnProcess(target.dwProcessId); |
583 | 583 |
584 return process; | 584 return process; |
585 } | 585 } |
586 | 586 |
587 } // namespace sandbox | 587 } // namespace sandbox |
OLD | NEW |