1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/win/src/broker_services.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +// Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef SANDBOX_WIN_SRC_BROKER_SERVICES_H_ 1.9 +#define SANDBOX_WIN_SRC_BROKER_SERVICES_H_ 1.10 + 1.11 +#include <list> 1.12 +#include <map> 1.13 +#include <set> 1.14 +#include "base/basictypes.h" 1.15 +#include "base/compiler_specific.h" 1.16 +#include "base/win/scoped_handle.h" 1.17 +#include "sandbox/win/src/crosscall_server.h" 1.18 +#include "sandbox/win/src/job.h" 1.19 +#include "sandbox/win/src/sandbox.h" 1.20 +#include "sandbox/win/src/sharedmem_ipc_server.h" 1.21 +#include "sandbox/win/src/win2k_threadpool.h" 1.22 +#include "sandbox/win/src/win_utils.h" 1.23 + 1.24 +namespace { 1.25 + 1.26 +struct JobTracker; 1.27 +struct PeerTracker; 1.28 + 1.29 +} // namespace 1.30 + 1.31 +namespace sandbox { 1.32 + 1.33 +class PolicyBase; 1.34 + 1.35 +// BrokerServicesBase --------------------------------------------------------- 1.36 +// Broker implementation version 0 1.37 +// 1.38 +// This is an implementation of the interface BrokerServices and 1.39 +// of the associated TargetProcess interface. In this implementation 1.40 +// TargetProcess is a friend of BrokerServices where the later manages a 1.41 +// collection of the former. 1.42 +class BrokerServicesBase : public BrokerServices, 1.43 + public SingletonBase<BrokerServicesBase> { 1.44 + public: 1.45 + BrokerServicesBase(); 1.46 + 1.47 + ~BrokerServicesBase(); 1.48 + 1.49 + // BrokerServices interface. 1.50 + virtual ResultCode Init() OVERRIDE; 1.51 + virtual TargetPolicy* CreatePolicy() OVERRIDE; 1.52 + virtual ResultCode SpawnTarget(const wchar_t* exe_path, 1.53 + const wchar_t* command_line, 1.54 + TargetPolicy* policy, 1.55 + PROCESS_INFORMATION* target) OVERRIDE; 1.56 + virtual ResultCode WaitForAllTargets() OVERRIDE; 1.57 + virtual ResultCode AddTargetPeer(HANDLE peer_process) OVERRIDE; 1.58 + virtual ResultCode InstallAppContainer(const wchar_t* sid, 1.59 + const wchar_t* name) OVERRIDE; 1.60 + virtual ResultCode UninstallAppContainer(const wchar_t* sid) OVERRIDE; 1.61 + 1.62 + // Checks if the supplied process ID matches one of the broker's active 1.63 + // target processes 1.64 + // Returns: 1.65 + // true if there is an active target process for this ID, otherwise false. 1.66 + bool IsActiveTarget(DWORD process_id); 1.67 + 1.68 + private: 1.69 + // Releases the Job and notifies the associated Policy object to its 1.70 + // resources as well. 1.71 + static void FreeResources(JobTracker* tracker); 1.72 + 1.73 + // The routine that the worker thread executes. It is in charge of 1.74 + // notifications and cleanup-related tasks. 1.75 + static DWORD WINAPI TargetEventsThread(PVOID param); 1.76 + 1.77 + // Removes a target peer from the process list if it expires. 1.78 + static VOID CALLBACK RemovePeer(PVOID parameter, BOOLEAN timeout); 1.79 + 1.80 + // The completion port used by the job objects to communicate events to 1.81 + // the worker thread. 1.82 + HANDLE job_port_; 1.83 + 1.84 + // Handle to a manual-reset event that is signaled when the total target 1.85 + // process count reaches zero. 1.86 + HANDLE no_targets_; 1.87 + 1.88 + // Handle to the worker thread that reacts to job notifications. 1.89 + HANDLE job_thread_; 1.90 + 1.91 + // Lock used to protect the list of targets from being modified by 2 1.92 + // threads at the same time. 1.93 + CRITICAL_SECTION lock_; 1.94 + 1.95 + // provides a pool of threads that are used to wait on the IPC calls. 1.96 + ThreadProvider* thread_pool_; 1.97 + 1.98 + // List of the trackers for closing and cleanup purposes. 1.99 + typedef std::list<JobTracker*> JobTrackerList; 1.100 + JobTrackerList tracker_list_; 1.101 + 1.102 + // Maps peer process IDs to the saved handle and wait event. 1.103 + // Prevents peer callbacks from accessing the broker after destruction. 1.104 + typedef std::map<DWORD, PeerTracker*> PeerTrackerMap; 1.105 + PeerTrackerMap peer_map_; 1.106 + 1.107 + // Provides a fast lookup to identify sandboxed processes that belong to a 1.108 + // job. Consult |jobless_process_handles_| for handles of pocess without job. 1.109 + std::set<DWORD> child_process_ids_; 1.110 + 1.111 + DISALLOW_COPY_AND_ASSIGN(BrokerServicesBase); 1.112 +}; 1.113 + 1.114 +} // namespace sandbox 1.115 + 1.116 + 1.117 +#endif // SANDBOX_WIN_SRC_BROKER_SERVICES_H_