Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: content/common/sandbox_win.cc

Issue 12805004: Remove mention of the nacl process in content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_win.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"
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/lazy_instance.h"
14 #include "base/logging.h"
15 #include "base/path_service.h" 13 #include "base/path_service.h"
16 #include "base/process_util.h" 14 #include "base/process_util.h"
17 #include "base/string_util.h" 15 #include "base/string_util.h"
18 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
19 #include "base/win/iat_patch_function.h" 17 #include "base/win/iat_patch_function.h"
20 #include "base/win/scoped_handle.h" 18 #include "base/win/scoped_handle.h"
21 #include "base/win/scoped_process_information.h" 19 #include "base/win/scoped_process_information.h"
22 #include "base/win/windows_version.h" 20 #include "base/win/windows_version.h"
23 #include "content/common/debug_flags.h" 21 #include "content/common/debug_flags.h"
24 #include "content/public/common/content_client.h" 22 #include "content/public/common/content_client.h"
25 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
26 #include "content/public/common/process_type.h" 24 #include "content/public/common/process_type.h"
27 #include "content/public/common/sandbox_init.h" 25 #include "content/public/common/sandbox_init.h"
26 #include "content/public/common/sandboxed_process_launcher_delegate.h"
28 #include "sandbox/win/src/process_mitigations.h" 27 #include "sandbox/win/src/process_mitigations.h"
29 #include "sandbox/win/src/sandbox.h" 28 #include "sandbox/win/src/sandbox.h"
30 #include "sandbox/win/src/sandbox_nt_util.h" 29 #include "sandbox/win/src/sandbox_nt_util.h"
31 #include "sandbox/win/src/win_utils.h" 30 #include "sandbox/win/src/win_utils.h"
32 #include "ui/gl/gl_switches.h"
33 31
34 static sandbox::BrokerServices* g_broker_services = NULL; 32 static sandbox::BrokerServices* g_broker_services = NULL;
35 static sandbox::TargetServices* g_target_services = NULL; 33 static sandbox::TargetServices* g_target_services = NULL;
36 34
35 namespace content {
37 namespace { 36 namespace {
38 37
39 // The DLLs listed here are known (or under strong suspicion) of causing crashes 38 // The DLLs listed here are known (or under strong suspicion) of causing crashes
40 // when they are loaded in the renderer. Note: at runtime we generate short 39 // when they are loaded in the renderer. Note: at runtime we generate short
41 // versions of the dll name only if the dll has an extension. 40 // versions of the dll name only if the dll has an extension.
42 const wchar_t* const kTroublesomeDlls[] = { 41 const wchar_t* const kTroublesomeDlls[] = {
43 L"adialhk.dll", // Kaspersky Internet Security. 42 L"adialhk.dll", // Kaspersky Internet Security.
44 L"acpiz.dll", // Unknown. 43 L"acpiz.dll", // Unknown.
45 L"avgrsstx.dll", // AVG 8. 44 L"avgrsstx.dll", // AVG 8.
46 L"babylonchromepi.dll", // Babylon translator. 45 L"babylonchromepi.dll", // Babylon translator.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 L"smumhook.dll", // Spyware Doctor version 5. 103 L"smumhook.dll", // Spyware Doctor version 5.
105 L"ssldivx.dll", // DivX. 104 L"ssldivx.dll", // DivX.
106 L"syncor11.dll", // SynthCore Midi interface. 105 L"syncor11.dll", // SynthCore Midi interface.
107 L"systools.dll", // Panda Antivirus. 106 L"systools.dll", // Panda Antivirus.
108 L"tfwah.dll", // Threatfire (PC tools). 107 L"tfwah.dll", // Threatfire (PC tools).
109 L"wblind.dll", // Stardock Object desktop. 108 L"wblind.dll", // Stardock Object desktop.
110 L"wbhelp.dll", // Stardock Object desktop. 109 L"wbhelp.dll", // Stardock Object desktop.
111 L"winstylerthemehelper.dll" // Tuneup utilities 2006. 110 L"winstylerthemehelper.dll" // Tuneup utilities 2006.
112 }; 111 };
113 112
114 // The DLLs listed here are known (or under strong suspicion) of causing crashes
115 // when they are loaded in the GPU process.
116 const wchar_t* const kTroublesomeGpuDlls[] = {
117 L"cmsetac.dll", // Unknown (suspected malware).
118 };
119
120 // Adds the policy rules for the path and path\ with the semantic |access|. 113 // Adds the policy rules for the path and path\ with the semantic |access|.
121 // If |children| is set to true, we need to add the wildcard rules to also 114 // If |children| is set to true, we need to add the wildcard rules to also
122 // apply the rule to the subfiles and subfolders. 115 // apply the rule to the subfiles and subfolders.
123 bool AddDirectory(int path, const wchar_t* sub_dir, bool children, 116 bool AddDirectory(int path, const wchar_t* sub_dir, bool children,
124 sandbox::TargetPolicy::Semantics access, 117 sandbox::TargetPolicy::Semantics access,
125 sandbox::TargetPolicy* policy) { 118 sandbox::TargetPolicy* policy) {
126 base::FilePath directory; 119 base::FilePath directory;
127 if (!PathService::Get(path, &directory)) 120 if (!PathService::Get(path, &directory))
128 return false; 121 return false;
129 122
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 218 }
226 219
227 // Adds policy rules for unloaded the known dlls that cause chrome to crash. 220 // Adds policy rules for unloaded the known dlls that cause chrome to crash.
228 // Eviction of injected DLLs is done by the sandbox so that the injected module 221 // Eviction of injected DLLs is done by the sandbox so that the injected module
229 // does not get a chance to execute any code. 222 // does not get a chance to execute any code.
230 void AddGenericDllEvictionPolicy(sandbox::TargetPolicy* policy) { 223 void AddGenericDllEvictionPolicy(sandbox::TargetPolicy* policy) {
231 for (int ix = 0; ix != arraysize(kTroublesomeDlls); ++ix) 224 for (int ix = 0; ix != arraysize(kTroublesomeDlls); ++ix)
232 BlacklistAddOneDll(kTroublesomeDlls[ix], true, policy); 225 BlacklistAddOneDll(kTroublesomeDlls[ix], true, policy);
233 } 226 }
234 227
235 // Same as AddGenericDllEvictionPolicy but specifically for the GPU process.
236 // In this we add the blacklisted dlls even if they are not loaded in this
237 // process.
238 void AddGpuDllEvictionPolicy(sandbox::TargetPolicy* policy) {
239 for (int ix = 0; ix != arraysize(kTroublesomeGpuDlls); ++ix)
240 BlacklistAddOneDll(kTroublesomeGpuDlls[ix], false, policy);
241 }
242
243 // Returns the object path prepended with the current logon session. 228 // Returns the object path prepended with the current logon session.
244 string16 PrependWindowsSessionPath(const char16* object) { 229 string16 PrependWindowsSessionPath(const char16* object) {
245 // Cache this because it can't change after process creation. 230 // Cache this because it can't change after process creation.
246 static uintptr_t s_session_id = 0; 231 static uintptr_t s_session_id = 0;
247 if (s_session_id == 0) { 232 if (s_session_id == 0) {
248 HANDLE token; 233 HANDLE token;
249 DWORD session_id_length; 234 DWORD session_id_length;
250 DWORD session_id = 0; 235 DWORD session_id = 0;
251 236
252 CHECK(::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token)); 237 CHECK(::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 sizeof(job_info), NULL)) { 269 sizeof(job_info), NULL)) {
285 NOTREACHED() << "QueryInformationJobObject failed. " << GetLastError(); 270 NOTREACHED() << "QueryInformationJobObject failed. " << GetLastError();
286 return true; 271 return true;
287 } 272 }
288 if (job_info.BasicLimitInformation.LimitFlags & JOB_OBJECT_LIMIT_BREAKAWAY_OK) 273 if (job_info.BasicLimitInformation.LimitFlags & JOB_OBJECT_LIMIT_BREAKAWAY_OK)
289 return true; 274 return true;
290 275
291 return false; 276 return false;
292 } 277 }
293 278
294 void SetJobLevel(const CommandLine& cmd_line,
295 sandbox::JobLevel job_level,
296 uint32 ui_exceptions,
297 sandbox::TargetPolicy* policy) {
298 if (ShouldSetJobLevel(cmd_line))
299 policy->SetJobLevel(job_level, ui_exceptions);
300 else
301 policy->SetJobLevel(sandbox::JOB_NONE, 0);
302 }
303
304 // Closes handles that are opened at process creation and initialization.
305 void AddBaseHandleClosePolicy(sandbox::TargetPolicy* policy) {
306 // Being able to manipulate anything BaseNamedObjects is bad.
307 string16 object_path = PrependWindowsSessionPath(L"\\BaseNamedObjects");
308 policy->AddKernelObjectToClose(L"Directory", object_path.data());
309 object_path = PrependWindowsSessionPath(
310 L"\\BaseNamedObjects\\windows_shell_global_counters");
311 policy->AddKernelObjectToClose(L"Section", object_path.data());
312 }
313
314 // Adds the generic policy rules to a sandbox TargetPolicy. 279 // Adds the generic policy rules to a sandbox TargetPolicy.
315 bool AddGenericPolicy(sandbox::TargetPolicy* policy) { 280 bool AddGenericPolicy(sandbox::TargetPolicy* policy) {
316 sandbox::ResultCode result; 281 sandbox::ResultCode result;
317 282
283 // Renderers need to copy sections for plugin DIBs and GPU.
284 // GPU needs to copy sections to renderers.
285 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
jam 2013/03/19 16:06:27 this same code was in AddPolicyForGPU and AddPolic
286 sandbox::TargetPolicy::HANDLES_DUP_ANY,
287 L"Section");
288 if (result != sandbox::SBOX_ALL_OK)
289 return false;
290
318 // Add the policy for the client side of a pipe. It is just a file 291 // Add the policy for the client side of a pipe. It is just a file
319 // in the \pipe\ namespace. We restrict it to pipes that start with 292 // in the \pipe\ namespace. We restrict it to pipes that start with
320 // "chrome." so the sandboxed process cannot connect to system services. 293 // "chrome." so the sandboxed process cannot connect to system services.
321 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, 294 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES,
322 sandbox::TargetPolicy::FILES_ALLOW_ANY, 295 sandbox::TargetPolicy::FILES_ALLOW_ANY,
323 L"\\??\\pipe\\chrome.*"); 296 L"\\??\\pipe\\chrome.*");
324 if (result != sandbox::SBOX_ALL_OK) 297 if (result != sandbox::SBOX_ALL_OK)
325 return false; 298 return false;
326 // Allow the server side of a pipe restricted to the "chrome.nacl." 299
327 // namespace so that it cannot impersonate other system or other chrome
328 // service pipes.
329 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
330 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
331 L"\\\\.\\pipe\\chrome.nacl.*");
332 if (result != sandbox::SBOX_ALL_OK)
333 return false;
334 // Allow the server side of sync sockets, which are pipes that have 300 // Allow the server side of sync sockets, which are pipes that have
335 // the "chrome.sync" namespace and a randomly generated suffix. 301 // the "chrome.sync" namespace and a randomly generated suffix.
336 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_NAMED_PIPES, 302 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
337 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY, 303 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
338 L"\\\\.\\pipe\\chrome.sync.*"); 304 L"\\\\.\\pipe\\chrome.sync.*");
339 if (result != sandbox::SBOX_ALL_OK) 305 if (result != sandbox::SBOX_ALL_OK)
340 return false; 306 return false;
341 307
342 // Add the policy for debug message only in debug 308 // Add the policy for debug message only in debug
343 #ifndef NDEBUG 309 #ifndef NDEBUG
344 base::FilePath app_dir; 310 base::FilePath app_dir;
345 if (!PathService::Get(base::DIR_MODULE, &app_dir)) 311 if (!PathService::Get(base::DIR_MODULE, &app_dir))
346 return false; 312 return false;
347 313
348 wchar_t long_path_buf[MAX_PATH]; 314 wchar_t long_path_buf[MAX_PATH];
349 DWORD long_path_return_value = GetLongPathName(app_dir.value().c_str(), 315 DWORD long_path_return_value = GetLongPathName(app_dir.value().c_str(),
350 long_path_buf, 316 long_path_buf,
351 MAX_PATH); 317 MAX_PATH);
352 if (long_path_return_value == 0 || long_path_return_value >= MAX_PATH) 318 if (long_path_return_value == 0 || long_path_return_value >= MAX_PATH)
353 return false; 319 return false;
354 320
355 base::FilePath debug_message(long_path_buf); 321 base::FilePath debug_message(long_path_buf);
356 debug_message = debug_message.AppendASCII("debug_message.exe"); 322 debug_message = debug_message.AppendASCII("debug_message.exe");
357 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_PROCESS, 323 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_PROCESS,
358 sandbox::TargetPolicy::PROCESS_MIN_EXEC, 324 sandbox::TargetPolicy::PROCESS_MIN_EXEC,
359 debug_message.value().c_str()); 325 debug_message.value().c_str());
360 if (result != sandbox::SBOX_ALL_OK) 326 if (result != sandbox::SBOX_ALL_OK)
361 return false; 327 return false;
362 #endif // NDEBUG 328 #endif // NDEBUG
329
330 AddGenericDllEvictionPolicy(policy);
331
363 return true; 332 return true;
364 } 333 }
365 334
366 // For the GPU process we gotten as far as USER_LIMITED. The next level 335 bool AddPolicyForSandboxedProcess(sandbox::TargetPolicy* policy) {
jam 2013/03/19 16:06:27 (I renamed this to something more generic since it
367 // which is USER_RESTRICTED breaks both the DirectX backend and the OpenGL
368 // backend. Note that the GPU process is connected to the interactive
369 // desktop.
370 // TODO(cpu): Lock down the sandbox more if possible.
371 bool AddPolicyForGPU(CommandLine* cmd_line, sandbox::TargetPolicy* policy) {
372 #if !defined(NACL_WIN64) // We don't need this code on win nacl64.
373 if (base::win::GetVersion() > base::win::VERSION_XP) {
374 if (cmd_line->GetSwitchValueASCII(switches::kUseGL) ==
375 gfx::kGLImplementationDesktopName) {
376 // Open GL path.
377 policy->SetTokenLevel(sandbox::USER_RESTRICTED_SAME_ACCESS,
378 sandbox::USER_LIMITED);
379 SetJobLevel(*cmd_line, sandbox::JOB_UNPROTECTED, 0, policy);
380 policy->SetDelayedIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW);
381 } else {
382 if (cmd_line->GetSwitchValueASCII(switches::kUseGL) ==
383 gfx::kGLImplementationSwiftShaderName ||
384 cmd_line->HasSwitch(switches::kReduceGpuSandbox) ||
385 cmd_line->HasSwitch(switches::kDisableImageTransportSurface)) {
386 // Swiftshader path.
387 policy->SetTokenLevel(sandbox::USER_RESTRICTED_SAME_ACCESS,
388 sandbox::USER_LIMITED);
389 } else {
390 // Angle + DirectX path.
391 policy->SetTokenLevel(sandbox::USER_RESTRICTED_SAME_ACCESS,
392 sandbox::USER_RESTRICTED);
393 // This is a trick to keep the GPU out of low-integrity processes. It
394 // starts at low-integrity for UIPI to work, then drops below
395 // low-integrity after warm-up.
396 policy->SetDelayedIntegrityLevel(sandbox::INTEGRITY_LEVEL_UNTRUSTED);
397 }
398
399 // UI restrictions break when we access Windows from outside our job.
400 // However, we don't want a proxy window in this process because it can
401 // introduce deadlocks where the renderer blocks on the gpu, which in
402 // turn blocks on the browser UI thread. So, instead we forgo a window
403 // message pump entirely and just add job restrictions to prevent child
404 // processes.
405 SetJobLevel(*cmd_line,
406 sandbox::JOB_LIMITED_USER,
407 JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS |
408 JOB_OBJECT_UILIMIT_DESKTOP |
409 JOB_OBJECT_UILIMIT_EXITWINDOWS |
410 JOB_OBJECT_UILIMIT_DISPLAYSETTINGS,
411 policy);
412
413 policy->SetIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW);
414 }
415 } else {
416 SetJobLevel(*cmd_line, sandbox::JOB_UNPROTECTED, 0, policy);
417 policy->SetTokenLevel(sandbox::USER_UNPROTECTED,
418 sandbox::USER_LIMITED);
419 }
420
421 // Allow the server side of GPU sockets, which are pipes that have
422 // the "chrome.gpu" namespace and an arbitrary suffix.
423 sandbox::ResultCode result = policy->AddRule(
424 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
425 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
426 L"\\\\.\\pipe\\chrome.gpu.*");
427 if (result != sandbox::SBOX_ALL_OK)
428 return false;
429
430 // GPU needs to copy sections to renderers.
431 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
432 sandbox::TargetPolicy::HANDLES_DUP_ANY,
433 L"Section");
434 if (result != sandbox::SBOX_ALL_OK)
435 return false;
436
437 #ifdef USE_AURA
438 // GPU also needs to add sections to the browser for aura
439 // TODO(jschuh): refactor the GPU channel to remove this. crbug.com/128786
440 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
441 sandbox::TargetPolicy::HANDLES_DUP_BROKER,
442 L"Section");
443 if (result != sandbox::SBOX_ALL_OK)
444 return false;
445 #endif
446
447 AddGenericDllEvictionPolicy(policy);
448 AddGpuDllEvictionPolicy(policy);
449
450 if (cmd_line->HasSwitch(switches::kEnableLogging)) {
451 string16 log_file_path = logging::GetLogFileFullPath();
452 if (!log_file_path.empty()) {
453 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES,
454 sandbox::TargetPolicy::FILES_ALLOW_ANY,
455 log_file_path.c_str());
456 if (result != sandbox::SBOX_ALL_OK)
457 return false;
458 }
459 }
460 #endif
461 return true;
462 }
463
464 bool AddPolicyForRenderer(sandbox::TargetPolicy* policy) {
465 // Renderers need to copy sections for plugin DIBs and GPU.
466 sandbox::ResultCode result; 336 sandbox::ResultCode result;
467 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
468 sandbox::TargetPolicy::HANDLES_DUP_ANY,
469 L"Section");
470 if (result != sandbox::SBOX_ALL_OK)
471 return false;
472
473 // Renderers need to share events with plugins. 337 // Renderers need to share events with plugins.
474 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES, 338 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
475 sandbox::TargetPolicy::HANDLES_DUP_ANY, 339 sandbox::TargetPolicy::HANDLES_DUP_ANY,
476 L"Event"); 340 L"Event");
477 if (result != sandbox::SBOX_ALL_OK) 341 if (result != sandbox::SBOX_ALL_OK)
478 return false; 342 return false;
479 343
480 // Renderers need to send named pipe handles and shared memory
481 // segment handles to NaCl loader processes.
482 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
483 sandbox::TargetPolicy::HANDLES_DUP_ANY,
484 L"File");
485 if (result != sandbox::SBOX_ALL_OK)
486 return false;
487
488 sandbox::TokenLevel initial_token = sandbox::USER_UNPROTECTED; 344 sandbox::TokenLevel initial_token = sandbox::USER_UNPROTECTED;
489 if (base::win::GetVersion() > base::win::VERSION_XP) { 345 if (base::win::GetVersion() > base::win::VERSION_XP) {
490 // On 2003/Vista the initial token has to be restricted if the main 346 // On 2003/Vista the initial token has to be restricted if the main
491 // token is restricted. 347 // token is restricted.
492 initial_token = sandbox::USER_RESTRICTED_SAME_ACCESS; 348 initial_token = sandbox::USER_RESTRICTED_SAME_ACCESS;
493 } 349 }
494 350
495 policy->SetTokenLevel(initial_token, sandbox::USER_LOCKDOWN); 351 policy->SetTokenLevel(initial_token, sandbox::USER_LOCKDOWN);
496 // Prevents the renderers from manipulating low-integrity processes. 352 // Prevents the renderers from manipulating low-integrity processes.
497 policy->SetDelayedIntegrityLevel(sandbox::INTEGRITY_LEVEL_UNTRUSTED); 353 policy->SetDelayedIntegrityLevel(sandbox::INTEGRITY_LEVEL_UNTRUSTED);
498 354
499 bool use_winsta = !CommandLine::ForCurrentProcess()->HasSwitch( 355 bool use_winsta = !CommandLine::ForCurrentProcess()->HasSwitch(
500 switches::kDisableAltWinstation); 356 switches::kDisableAltWinstation);
501 357
502 if (sandbox::SBOX_ALL_OK != policy->SetAlternateDesktop(use_winsta)) { 358 if (sandbox::SBOX_ALL_OK != policy->SetAlternateDesktop(use_winsta)) {
503 DLOG(WARNING) << "Failed to apply desktop security to the renderer"; 359 DLOG(WARNING) << "Failed to apply desktop security to the renderer";
504 } 360 }
505 361
506 AddGenericDllEvictionPolicy(policy);
507
508 return true; 362 return true;
509 } 363 }
510 364
511 // The Pepper process as locked-down as a renderer execpt that it can
512 // create the server side of chrome pipes.
513 bool AddPolicyForPepperPlugin(sandbox::TargetPolicy* policy) {
514 sandbox::ResultCode result;
515 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
516 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
517 L"\\\\.\\pipe\\chrome.*");
518 return result == sandbox::SBOX_ALL_OK;
519 }
520
521 // This code is test only, and attempts to catch unsafe uses of 365 // This code is test only, and attempts to catch unsafe uses of
522 // DuplicateHandle() that copy privileged handles into sandboxed processes. 366 // DuplicateHandle() that copy privileged handles into sandboxed processes.
523 #ifndef OFFICIAL_BUILD 367 #ifndef OFFICIAL_BUILD
524 base::win::IATPatchFunction g_iat_patch_duplicate_handle; 368 base::win::IATPatchFunction g_iat_patch_duplicate_handle;
525 369
526 BOOL (WINAPI *g_iat_orig_duplicate_handle)(HANDLE source_process_handle, 370 BOOL (WINAPI *g_iat_orig_duplicate_handle)(HANDLE source_process_handle,
527 HANDLE source_handle, 371 HANDLE source_handle,
528 HANDLE target_process_handle, 372 HANDLE target_process_handle,
529 LPHANDLE target_handle, 373 LPHANDLE target_handle,
530 DWORD desired_access, 374 DWORD desired_access,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 // Callers use CHECK macro to make sure we get the right stack. 455 // Callers use CHECK macro to make sure we get the right stack.
612 CheckDuplicateHandle(handle); 456 CheckDuplicateHandle(handle);
613 } 457 }
614 458
615 return TRUE; 459 return TRUE;
616 } 460 }
617 #endif 461 #endif
618 462
619 } // namespace 463 } // namespace
620 464
621 namespace content { 465 void SetJobLevel(const CommandLine& cmd_line,
466 sandbox::JobLevel job_level,
467 uint32 ui_exceptions,
468 sandbox::TargetPolicy* policy) {
469 if (ShouldSetJobLevel(cmd_line))
470 policy->SetJobLevel(job_level, ui_exceptions);
471 else
472 policy->SetJobLevel(sandbox::JOB_NONE, 0);
473 }
474
475 // TODO(jschuh): Need get these restrictions applied to NaCl and Pepper.
476 // Just have to figure out what needs to be warmed up first.
477 void AddBaseHandleClosePolicy(sandbox::TargetPolicy* policy) {
478 // Being able to manipulate anything BaseNamedObjects is bad.
479 string16 object_path = PrependWindowsSessionPath(L"\\BaseNamedObjects");
480 policy->AddKernelObjectToClose(L"Directory", object_path.data());
481 object_path = PrependWindowsSessionPath(
482 L"\\BaseNamedObjects\\windows_shell_global_counters");
483 policy->AddKernelObjectToClose(L"Section", object_path.data());
484 }
622 485
623 bool InitBrokerServices(sandbox::BrokerServices* broker_services) { 486 bool InitBrokerServices(sandbox::BrokerServices* broker_services) {
624 // TODO(abarth): DCHECK(CalledOnValidThread()); 487 // TODO(abarth): DCHECK(CalledOnValidThread());
625 // See <http://b/1287166>. 488 // See <http://b/1287166>.
626 DCHECK(broker_services); 489 DCHECK(broker_services);
627 DCHECK(!g_broker_services); 490 DCHECK(!g_broker_services);
628 sandbox::ResultCode result = broker_services->Init(); 491 sandbox::ResultCode result = broker_services->Init();
629 g_broker_services = broker_services; 492 g_broker_services = broker_services;
630 493
631 // In non-official builds warn about dangerous uses of DuplicateHandle. 494 // In non-official builds warn about dangerous uses of DuplicateHandle.
632 BOOL is_in_job = FALSE; 495 BOOL is_in_job = FALSE;
633 #ifdef NACL_WIN64 496 #ifdef NACL_WIN64
634 CHECK(::IsProcessInJob(::GetCurrentProcess(), NULL, &is_in_job)); 497 CHECK(::IsProcessInJob(::GetCurrentProcess(), NULL, &is_in_job));
635 #endif 498 #endif
636 #ifndef OFFICIAL_BUILD 499 #ifndef OFFICIAL_BUILD
637 if (!is_in_job && !g_iat_patch_duplicate_handle.is_patched()) { 500 if (!is_in_job && !g_iat_patch_duplicate_handle.is_patched()) {
638 HMODULE module = NULL; 501 HMODULE module = NULL;
639 wchar_t module_name[MAX_PATH]; 502 wchar_t module_name[MAX_PATH];
640 CHECK(::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, 503 CHECK(::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
641 reinterpret_cast<LPCWSTR>(InitBrokerServices), 504 reinterpret_cast<LPCWSTR>(InitBrokerServices),
(...skipping 13 matching lines...) Expand all
655 } 518 }
656 519
657 bool InitTargetServices(sandbox::TargetServices* target_services) { 520 bool InitTargetServices(sandbox::TargetServices* target_services) {
658 DCHECK(target_services); 521 DCHECK(target_services);
659 DCHECK(!g_target_services); 522 DCHECK(!g_target_services);
660 sandbox::ResultCode result = target_services->Init(); 523 sandbox::ResultCode result = target_services->Init();
661 g_target_services = target_services; 524 g_target_services = target_services;
662 return sandbox::SBOX_ALL_OK == result; 525 return sandbox::SBOX_ALL_OK == result;
663 } 526 }
664 527
665 base::ProcessHandle StartProcessWithAccess(CommandLine* cmd_line, 528 base::ProcessHandle StartSandboxedProcess(
666 const base::FilePath& exposed_dir) { 529 SandboxedProcessLauncherDelegate* delegate,
530 CommandLine* cmd_line) {
667 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 531 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
668 ProcessType type; 532 ProcessType type;
669 std::string type_str = cmd_line->GetSwitchValueASCII(switches::kProcessType); 533 std::string type_str = cmd_line->GetSwitchValueASCII(switches::kProcessType);
670 if (type_str == switches::kRendererProcess) { 534 if (type_str == switches::kRendererProcess) {
671 type = PROCESS_TYPE_RENDERER; 535 type = PROCESS_TYPE_RENDERER;
672 } else if (type_str == switches::kPluginProcess) { 536 } else if (type_str == switches::kPluginProcess) {
673 type = PROCESS_TYPE_PLUGIN; 537 type = PROCESS_TYPE_PLUGIN;
674 } else if (type_str == switches::kWorkerProcess) { 538 } else if (type_str == switches::kWorkerProcess) {
675 type = PROCESS_TYPE_WORKER; 539 type = PROCESS_TYPE_WORKER;
676 } else if (type_str == switches::kNaClLoaderProcess) { 540 } else if (type_str == switches::kNaClLoaderProcess) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 return 0; 630 return 0;
767 631
768 mitigations = sandbox::MITIGATION_STRICT_HANDLE_CHECKS | 632 mitigations = sandbox::MITIGATION_STRICT_HANDLE_CHECKS |
769 sandbox::MITIGATION_DLL_SEARCH_ORDER; 633 sandbox::MITIGATION_DLL_SEARCH_ORDER;
770 634
771 if (policy->SetDelayedProcessMitigations(mitigations) != sandbox::SBOX_ALL_OK) 635 if (policy->SetDelayedProcessMitigations(mitigations) != sandbox::SBOX_ALL_OK)
772 return 0; 636 return 0;
773 637
774 SetJobLevel(*cmd_line, sandbox::JOB_LOCKDOWN, 0, policy); 638 SetJobLevel(*cmd_line, sandbox::JOB_LOCKDOWN, 0, policy);
775 639
776 if (type == PROCESS_TYPE_GPU) { 640 bool disable_default_policy = false;
777 if (!AddPolicyForGPU(cmd_line, policy)) 641 base::FilePath exposed_dir;
778 return 0; 642 if (delegate)
779 } else { 643 delegate->PreSandbox(&disable_default_policy, &exposed_dir);
780 if (!AddPolicyForRenderer(policy))
781 return 0;
782 // TODO(jschuh): Need get these restrictions applied to NaCl and Pepper.
783 // Just have to figure out what needs to be warmed up first.
784 if (type == PROCESS_TYPE_RENDERER ||
785 type == PROCESS_TYPE_WORKER) {
786 AddBaseHandleClosePolicy(policy);
787 // Pepper uses the renderer's policy, whith some tweaks.
788 } else if (type == PROCESS_TYPE_PPAPI_PLUGIN) {
789 if (!AddPolicyForPepperPlugin(policy))
790 return 0;
791 }
792 644
645 if (!disable_default_policy && !AddPolicyForSandboxedProcess(policy))
646 return 0;
793 647
794 if (type_str != switches::kRendererProcess) { 648 if (type_str != switches::kRendererProcess) {
795 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into 649 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into
796 // this subprocess. See 650 // this subprocess. See
797 // http://code.google.com/p/chromium/issues/detail?id=25580 651 // http://code.google.com/p/chromium/issues/detail?id=25580
798 cmd_line->AppendSwitchASCII("ignored", " --type=renderer "); 652 cmd_line->AppendSwitchASCII("ignored", " --type=renderer ");
799 }
800 } 653 }
801 654
802 sandbox::ResultCode result; 655 sandbox::ResultCode result;
803 if (!exposed_dir.empty()) { 656 if (!exposed_dir.empty()) {
804 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, 657 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES,
805 sandbox::TargetPolicy::FILES_ALLOW_ANY, 658 sandbox::TargetPolicy::FILES_ALLOW_ANY,
806 exposed_dir.value().c_str()); 659 exposed_dir.value().c_str());
807 if (result != sandbox::SBOX_ALL_OK) 660 if (result != sandbox::SBOX_ALL_OK)
808 return 0; 661 return 0;
809 662
(...skipping 10 matching lines...) Expand all
820 return 0; 673 return 0;
821 } 674 }
822 675
823 if (browser_command_line.HasSwitch(switches::kEnableLogging)) { 676 if (browser_command_line.HasSwitch(switches::kEnableLogging)) {
824 // If stdout/stderr point to a Windows console, these calls will 677 // If stdout/stderr point to a Windows console, these calls will
825 // have no effect. 678 // have no effect.
826 policy->SetStdoutHandle(GetStdHandle(STD_OUTPUT_HANDLE)); 679 policy->SetStdoutHandle(GetStdHandle(STD_OUTPUT_HANDLE));
827 policy->SetStderrHandle(GetStdHandle(STD_ERROR_HANDLE)); 680 policy->SetStderrHandle(GetStdHandle(STD_ERROR_HANDLE));
828 } 681 }
829 682
683 if (delegate) {
684 bool success = true;
685 delegate->PreSpawnTarget(policy, &success);
686 if (!success)
687 return 0;
688 }
689
830 TRACE_EVENT_BEGIN_ETW("StartProcessWithAccess::LAUNCHPROCESS", 0, 0); 690 TRACE_EVENT_BEGIN_ETW("StartProcessWithAccess::LAUNCHPROCESS", 0, 0);
831 691
832 result = g_broker_services->SpawnTarget( 692 result = g_broker_services->SpawnTarget(
833 cmd_line->GetProgram().value().c_str(), 693 cmd_line->GetProgram().value().c_str(),
834 cmd_line->GetCommandLineString().c_str(), 694 cmd_line->GetCommandLineString().c_str(),
835 policy, target.Receive()); 695 policy, target.Receive());
836 policy->Release(); 696 policy->Release();
837 697
838 TRACE_EVENT_END_ETW("StartProcessWithAccess::LAUNCHPROCESS", 0, 0); 698 TRACE_EVENT_END_ETW("StartProcessWithAccess::LAUNCHPROCESS", 0, 0);
839 699
840 if (sandbox::SBOX_ALL_OK != result) { 700 if (sandbox::SBOX_ALL_OK != result) {
841 DLOG(ERROR) << "Failed to launch process. Error: " << result; 701 DLOG(ERROR) << "Failed to launch process. Error: " << result;
842 return 0; 702 return 0;
843 } 703 }
844 704
845 #if !defined(NACL_WIN64) 705 if (delegate)
846 // For Native Client sel_ldr processes on 32-bit Windows, reserve 1 GB of 706 delegate->PostSpawnTarget(target.process_handle());
847 // address space to prevent later failure due to address space fragmentation 707
848 // from .dll loading. The NaCl process will attempt to locate this space by
849 // scanning the address space using VirtualQuery.
850 // TODO(bbudge) Handle the --no-sandbox case.
851 // http://code.google.com/p/nativeclient/issues/detail?id=2131
852 if (type == PROCESS_TYPE_NACL_LOADER) {
853 const SIZE_T kOneGigabyte = 1 << 30;
854 void* nacl_mem = VirtualAllocEx(target.process_handle(),
855 NULL,
856 kOneGigabyte,
857 MEM_RESERVE,
858 PAGE_NOACCESS);
859 if (!nacl_mem) {
860 DLOG(WARNING) << "Failed to reserve address space for Native Client";
861 }
862 }
863 #endif // !defined(NACL_WIN64)
864 708
865 ResumeThread(target.thread_handle()); 709 ResumeThread(target.thread_handle());
866 710
867 // Help the process a little. It can't start the debugger by itself if 711 // Help the process a little. It can't start the debugger by itself if
868 // the process is in a sandbox. 712 // the process is in a sandbox.
869 if (child_needs_help) 713 if (child_needs_help)
870 base::debug::SpawnDebuggerOnProcess(target.process_id()); 714 base::debug::SpawnDebuggerOnProcess(target.process_id());
871 715
872 return target.TakeProcessHandle(); 716 return target.TakeProcessHandle();
873 } 717 }
(...skipping 30 matching lines...) Expand all
904 } 748 }
905 749
906 return false; 750 return false;
907 } 751 }
908 752
909 bool BrokerAddTargetPeer(HANDLE peer_process) { 753 bool BrokerAddTargetPeer(HANDLE peer_process) {
910 return g_broker_services->AddTargetPeer(peer_process) == sandbox::SBOX_ALL_OK; 754 return g_broker_services->AddTargetPeer(peer_process) == sandbox::SBOX_ALL_OK;
911 } 755 }
912 756
913 } // namespace content 757 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698