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

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

Issue 1229163002: Sandbox: Remove raw handles from PolicyBase. (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
« no previous file with comments | « sandbox/win/src/sandbox_policy_base.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/sandbox_policy_base.h" 5 #include "sandbox/win/src/sandbox_policy_base.h"
6 6
7 #include <sddl.h> 7 #include <sddl.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/stl_util.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "base/win/windows_version.h" 14 #include "base/win/windows_version.h"
14 #include "sandbox/win/src/app_container.h" 15 #include "sandbox/win/src/app_container.h"
15 #include "sandbox/win/src/filesystem_dispatcher.h" 16 #include "sandbox/win/src/filesystem_dispatcher.h"
16 #include "sandbox/win/src/filesystem_policy.h" 17 #include "sandbox/win/src/filesystem_policy.h"
17 #include "sandbox/win/src/handle_dispatcher.h" 18 #include "sandbox/win/src/handle_dispatcher.h"
18 #include "sandbox/win/src/handle_policy.h" 19 #include "sandbox/win/src/handle_policy.h"
19 #include "sandbox/win/src/job.h" 20 #include "sandbox/win/src/job.h"
20 #include "sandbox/win/src/interception.h" 21 #include "sandbox/win/src/interception.h"
21 #include "sandbox/win/src/process_mitigations.h" 22 #include "sandbox/win/src/process_mitigations.h"
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 return SBOX_ALL_OK; 460 return SBOX_ALL_OK;
460 } 461 }
461 462
462 ResultCode PolicyBase::AddKernelObjectToClose(const base::char16* handle_type, 463 ResultCode PolicyBase::AddKernelObjectToClose(const base::char16* handle_type,
463 const base::char16* handle_name) { 464 const base::char16* handle_name) {
464 return handle_closer_.AddHandle(handle_type, handle_name); 465 return handle_closer_.AddHandle(handle_type, handle_name);
465 } 466 }
466 467
467 void* PolicyBase::AddHandleToShare(HANDLE handle) { 468 void* PolicyBase::AddHandleToShare(HANDLE handle) {
468 if (base::win::GetVersion() < base::win::VERSION_VISTA) 469 if (base::win::GetVersion() < base::win::VERSION_VISTA)
469 return NULL; 470 return nullptr;
470 471
471 if (!handle) 472 if (!handle)
472 return NULL; 473 return nullptr;
473 474
474 HANDLE duped_handle = NULL; 475 HANDLE duped_handle = nullptr;
475 ::DuplicateHandle(::GetCurrentProcess(), 476 if (!::DuplicateHandle(::GetCurrentProcess(), handle, ::GetCurrentProcess(),
476 handle, 477 &duped_handle, 0, TRUE, DUPLICATE_SAME_ACCESS)) {
477 ::GetCurrentProcess(), 478 return nullptr;
478 &duped_handle, 479 }
479 0, 480 handles_to_share_.push_back(new base::win::ScopedHandle(duped_handle));
Will Harris 2015/07/10 18:05:02 this is a behavior change, previously we'd push a
rvargas (doing something else) 2015/07/10 18:26:45 Correct, but judging by the (insufficient) dcheck,
480 TRUE,
481 DUPLICATE_SAME_ACCESS);
482 DCHECK(duped_handle);
483 handles_to_share_.push_back(duped_handle);
484 return duped_handle; 481 return duped_handle;
485 } 482 }
486 483
487 HandleList PolicyBase::GetHandlesBeingShared() { 484 const HandleList& PolicyBase::GetHandlesBeingShared() {
488 return handles_to_share_; 485 return handles_to_share_;
489 } 486 }
490 487
491 void PolicyBase::ClearSharedHandles() { 488 void PolicyBase::ClearSharedHandles() {
492 for (auto handle : handles_to_share_) { 489 STLDeleteElements(&handles_to_share_);
493 ::CloseHandle(handle);
494 }
495 handles_to_share_.clear();
496 } 490 }
497 491
498 // When an IPC is ready in any of the targets we get called. We manage an array 492 // When an IPC is ready in any of the targets we get called. We manage an array
499 // of IPC dispatchers which are keyed on the IPC tag so we normally delegate 493 // of IPC dispatchers which are keyed on the IPC tag so we normally delegate
500 // to the appropriate dispatcher unless we can handle the IPC call ourselves. 494 // to the appropriate dispatcher unless we can handle the IPC call ourselves.
501 Dispatcher* PolicyBase::OnMessageReady(IPCParams* ipc, 495 Dispatcher* PolicyBase::OnMessageReady(IPCParams* ipc,
502 CallbackGeneric* callback) { 496 CallbackGeneric* callback) {
503 DCHECK(callback); 497 DCHECK(callback);
504 static const IPCParams ping1 = {IPC_PING1_TAG, {UINT32_TYPE}}; 498 static const IPCParams ping1 = {IPC_PING1_TAG, {UINT32_TYPE}};
505 static const IPCParams ping2 = {IPC_PING2_TAG, {INOUTPTR_TYPE}}; 499 static const IPCParams ping2 = {IPC_PING2_TAG, {INOUTPTR_TYPE}};
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 break; 872 break;
879 } 873 }
880 874
881 default: { return SBOX_ERROR_UNSUPPORTED; } 875 default: { return SBOX_ERROR_UNSUPPORTED; }
882 } 876 }
883 877
884 return SBOX_ALL_OK; 878 return SBOX_ALL_OK;
885 } 879 }
886 880
887 } // namespace sandbox 881 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/sandbox_policy_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698