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

Side by Side Diff: sandbox/win/src/broker_services.cc

Issue 1227163008: Sandbox: Make PolicyBase::MakeTokens return ScopedHandes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
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 "sandbox/win/src/broker_services.h" 5 #include "sandbox/win/src/broker_services.h"
6 6
7 #include <AclAPI.h> 7 #include <AclAPI.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 AutoLock lock(&lock_); 350 AutoLock lock(&lock_);
351 351
352 // This downcast is safe as long as we control CreatePolicy() 352 // This downcast is safe as long as we control CreatePolicy()
353 PolicyBase* policy_base = static_cast<PolicyBase*>(policy); 353 PolicyBase* policy_base = static_cast<PolicyBase*>(policy);
354 354
355 if (policy_base->GetAppContainer() && policy_base->GetLowBoxSid()) 355 if (policy_base->GetAppContainer() && policy_base->GetLowBoxSid())
356 return SBOX_ERROR_BAD_PARAMS; 356 return SBOX_ERROR_BAD_PARAMS;
357 357
358 // Construct the tokens and the job object that we are going to associate 358 // Construct the tokens and the job object that we are going to associate
359 // with the soon to be created target process. 359 // with the soon to be created target process.
360 HANDLE initial_token_temp; 360 base::win::ScopedHandle initial_token;
361 HANDLE lockdown_token_temp; 361 base::win::ScopedHandle lockdown_token;
362 ResultCode result = SBOX_ALL_OK; 362 ResultCode result = SBOX_ALL_OK;
363 363
364 if (IsTokenCacheable(policy_base)) { 364 if (IsTokenCacheable(policy_base)) {
365 // Create the master tokens only once and save them in a cache. That way 365 // Create the master tokens only once and save them in a cache. That way
366 // can just duplicate them to avoid hammering LSASS on every sandboxed 366 // can just duplicate them to avoid hammering LSASS on every sandboxed
367 // process launch. 367 // process launch.
368 uint32_t token_key = GenerateTokenCacheKey(policy_base); 368 uint32_t token_key = GenerateTokenCacheKey(policy_base);
369 TokenCacheMap::iterator it = token_cache_.find(token_key); 369 TokenCacheMap::iterator it = token_cache_.find(token_key);
370 HANDLE initial_token_temp;
371 HANDLE lockdown_token_temp;
370 if (it != token_cache_.end()) { 372 if (it != token_cache_.end()) {
371 initial_token_temp = it->second.first; 373 initial_token_temp = it->second.first;
372 lockdown_token_temp = it->second.second; 374 lockdown_token_temp = it->second.second;
373 } else { 375 } else {
374 result = 376 result = policy_base->MakeTokens(&initial_token, &lockdown_token);
375 policy_base->MakeTokens(&initial_token_temp, &lockdown_token_temp);
376 if (SBOX_ALL_OK != result) 377 if (SBOX_ALL_OK != result)
377 return result; 378 return result;
378 token_cache_[token_key] = 379 token_cache_[token_key] =
379 std::pair<HANDLE, HANDLE>(initial_token_temp, lockdown_token_temp); 380 std::make_pair(initial_token.Get(), lockdown_token.Get());
381 initial_token_temp = initial_token.Take();
382 lockdown_token_temp = lockdown_token.Take();
380 } 383 }
381 384
382 if (!::DuplicateToken(initial_token_temp, SecurityImpersonation, 385 if (!::DuplicateToken(initial_token_temp, SecurityImpersonation,
383 &initial_token_temp)) { 386 &initial_token_temp)) {
384 return SBOX_ERROR_GENERIC; 387 return SBOX_ERROR_GENERIC;
385 } 388 }
389 initial_token.Set(initial_token_temp);
386 390
387 if (!::DuplicateTokenEx(lockdown_token_temp, TOKEN_ALL_ACCESS, 0, 391 if (!::DuplicateTokenEx(lockdown_token_temp, TOKEN_ALL_ACCESS, 0,
388 SecurityIdentification, TokenPrimary, 392 SecurityIdentification, TokenPrimary,
389 &lockdown_token_temp)) { 393 &lockdown_token_temp)) {
390 return SBOX_ERROR_GENERIC; 394 return SBOX_ERROR_GENERIC;
391 } 395 }
396 lockdown_token.Set(lockdown_token_temp);
392 } else { 397 } else {
393 result = policy_base->MakeTokens(&initial_token_temp, &lockdown_token_temp); 398 result = policy_base->MakeTokens(&initial_token, &lockdown_token);
394 if (SBOX_ALL_OK != result) 399 if (SBOX_ALL_OK != result)
395 return result; 400 return result;
396 } 401 }
397 402
398 base::win::ScopedHandle initial_token(initial_token_temp);
399 base::win::ScopedHandle lockdown_token(lockdown_token_temp);
400
401 HANDLE job_temp; 403 HANDLE job_temp;
402 result = policy_base->MakeJobObject(&job_temp); 404 result = policy_base->MakeJobObject(&job_temp);
403 if (SBOX_ALL_OK != result) 405 if (SBOX_ALL_OK != result)
404 return result; 406 return result;
405 407
406 base::win::ScopedHandle job(job_temp); 408 base::win::ScopedHandle job(job_temp);
407 409
408 // Initialize the startup information from the policy. 410 // Initialize the startup information from the policy.
409 base::win::StartupInformation startup_info; 411 base::win::StartupInformation startup_info;
410 // The liftime of |mitigations| and |inherit_handle_list| have to be at least 412 // The liftime of |mitigations| and |inherit_handle_list| have to be at least
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 return SBOX_ERROR_UNSUPPORTED; 621 return SBOX_ERROR_UNSUPPORTED;
620 622
621 base::string16 name = LookupAppContainer(sid); 623 base::string16 name = LookupAppContainer(sid);
622 if (name.empty()) 624 if (name.empty())
623 return SBOX_ERROR_INVALID_APP_CONTAINER; 625 return SBOX_ERROR_INVALID_APP_CONTAINER;
624 626
625 return DeleteAppContainer(sid); 627 return DeleteAppContainer(sid);
626 } 628 }
627 629
628 } // namespace sandbox 630 } // namespace sandbox
OLDNEW
« no previous file with comments | « no previous file | sandbox/win/src/sandbox_policy_base.h » ('j') | sandbox/win/src/sandbox_policy_base.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698