security/sandbox/win/src/broker_services.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #ifndef SANDBOX_WIN_SRC_BROKER_SERVICES_H_
michael@0 6 #define SANDBOX_WIN_SRC_BROKER_SERVICES_H_
michael@0 7
michael@0 8 #include <list>
michael@0 9 #include <map>
michael@0 10 #include <set>
michael@0 11 #include "base/basictypes.h"
michael@0 12 #include "base/compiler_specific.h"
michael@0 13 #include "base/win/scoped_handle.h"
michael@0 14 #include "sandbox/win/src/crosscall_server.h"
michael@0 15 #include "sandbox/win/src/job.h"
michael@0 16 #include "sandbox/win/src/sandbox.h"
michael@0 17 #include "sandbox/win/src/sharedmem_ipc_server.h"
michael@0 18 #include "sandbox/win/src/win2k_threadpool.h"
michael@0 19 #include "sandbox/win/src/win_utils.h"
michael@0 20
michael@0 21 namespace {
michael@0 22
michael@0 23 struct JobTracker;
michael@0 24 struct PeerTracker;
michael@0 25
michael@0 26 } // namespace
michael@0 27
michael@0 28 namespace sandbox {
michael@0 29
michael@0 30 class PolicyBase;
michael@0 31
michael@0 32 // BrokerServicesBase ---------------------------------------------------------
michael@0 33 // Broker implementation version 0
michael@0 34 //
michael@0 35 // This is an implementation of the interface BrokerServices and
michael@0 36 // of the associated TargetProcess interface. In this implementation
michael@0 37 // TargetProcess is a friend of BrokerServices where the later manages a
michael@0 38 // collection of the former.
michael@0 39 class BrokerServicesBase : public BrokerServices,
michael@0 40 public SingletonBase<BrokerServicesBase> {
michael@0 41 public:
michael@0 42 BrokerServicesBase();
michael@0 43
michael@0 44 ~BrokerServicesBase();
michael@0 45
michael@0 46 // BrokerServices interface.
michael@0 47 virtual ResultCode Init() OVERRIDE;
michael@0 48 virtual TargetPolicy* CreatePolicy() OVERRIDE;
michael@0 49 virtual ResultCode SpawnTarget(const wchar_t* exe_path,
michael@0 50 const wchar_t* command_line,
michael@0 51 TargetPolicy* policy,
michael@0 52 PROCESS_INFORMATION* target) OVERRIDE;
michael@0 53 virtual ResultCode WaitForAllTargets() OVERRIDE;
michael@0 54 virtual ResultCode AddTargetPeer(HANDLE peer_process) OVERRIDE;
michael@0 55 virtual ResultCode InstallAppContainer(const wchar_t* sid,
michael@0 56 const wchar_t* name) OVERRIDE;
michael@0 57 virtual ResultCode UninstallAppContainer(const wchar_t* sid) OVERRIDE;
michael@0 58
michael@0 59 // Checks if the supplied process ID matches one of the broker's active
michael@0 60 // target processes
michael@0 61 // Returns:
michael@0 62 // true if there is an active target process for this ID, otherwise false.
michael@0 63 bool IsActiveTarget(DWORD process_id);
michael@0 64
michael@0 65 private:
michael@0 66 // Releases the Job and notifies the associated Policy object to its
michael@0 67 // resources as well.
michael@0 68 static void FreeResources(JobTracker* tracker);
michael@0 69
michael@0 70 // The routine that the worker thread executes. It is in charge of
michael@0 71 // notifications and cleanup-related tasks.
michael@0 72 static DWORD WINAPI TargetEventsThread(PVOID param);
michael@0 73
michael@0 74 // Removes a target peer from the process list if it expires.
michael@0 75 static VOID CALLBACK RemovePeer(PVOID parameter, BOOLEAN timeout);
michael@0 76
michael@0 77 // The completion port used by the job objects to communicate events to
michael@0 78 // the worker thread.
michael@0 79 HANDLE job_port_;
michael@0 80
michael@0 81 // Handle to a manual-reset event that is signaled when the total target
michael@0 82 // process count reaches zero.
michael@0 83 HANDLE no_targets_;
michael@0 84
michael@0 85 // Handle to the worker thread that reacts to job notifications.
michael@0 86 HANDLE job_thread_;
michael@0 87
michael@0 88 // Lock used to protect the list of targets from being modified by 2
michael@0 89 // threads at the same time.
michael@0 90 CRITICAL_SECTION lock_;
michael@0 91
michael@0 92 // provides a pool of threads that are used to wait on the IPC calls.
michael@0 93 ThreadProvider* thread_pool_;
michael@0 94
michael@0 95 // List of the trackers for closing and cleanup purposes.
michael@0 96 typedef std::list<JobTracker*> JobTrackerList;
michael@0 97 JobTrackerList tracker_list_;
michael@0 98
michael@0 99 // Maps peer process IDs to the saved handle and wait event.
michael@0 100 // Prevents peer callbacks from accessing the broker after destruction.
michael@0 101 typedef std::map<DWORD, PeerTracker*> PeerTrackerMap;
michael@0 102 PeerTrackerMap peer_map_;
michael@0 103
michael@0 104 // Provides a fast lookup to identify sandboxed processes that belong to a
michael@0 105 // job. Consult |jobless_process_handles_| for handles of pocess without job.
michael@0 106 std::set<DWORD> child_process_ids_;
michael@0 107
michael@0 108 DISALLOW_COPY_AND_ASSIGN(BrokerServicesBase);
michael@0 109 };
michael@0 110
michael@0 111 } // namespace sandbox
michael@0 112
michael@0 113
michael@0 114 #endif // SANDBOX_WIN_SRC_BROKER_SERVICES_H_

mercurial