OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef SANDBOX_WIN_SRC_SANDBOX_POLICY_BASE_H_ | 5 #ifndef SANDBOX_WIN_SRC_SANDBOX_POLICY_BASE_H_ |
6 #define SANDBOX_WIN_SRC_SANDBOX_POLICY_BASE_H_ | 6 #define SANDBOX_WIN_SRC_SANDBOX_POLICY_BASE_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
16 #include "base/win/scoped_handle.h" | 17 #include "base/win/scoped_handle.h" |
17 #include "sandbox/win/src/crosscall_server.h" | 18 #include "sandbox/win/src/crosscall_server.h" |
18 #include "sandbox/win/src/handle_closer.h" | 19 #include "sandbox/win/src/handle_closer.h" |
19 #include "sandbox/win/src/ipc_tags.h" | 20 #include "sandbox/win/src/ipc_tags.h" |
20 #include "sandbox/win/src/policy_engine_opcodes.h" | 21 #include "sandbox/win/src/policy_engine_opcodes.h" |
21 #include "sandbox/win/src/policy_engine_params.h" | 22 #include "sandbox/win/src/policy_engine_params.h" |
22 #include "sandbox/win/src/sandbox_policy.h" | 23 #include "sandbox/win/src/sandbox_policy.h" |
23 #include "sandbox/win/src/win_utils.h" | 24 #include "sandbox/win/src/win_utils.h" |
24 | 25 |
25 namespace sandbox { | 26 namespace sandbox { |
26 | 27 |
27 class AppContainerAttributes; | 28 class AppContainerAttributes; |
28 class LowLevelPolicy; | 29 class LowLevelPolicy; |
29 class TargetProcess; | 30 class TargetProcess; |
30 struct PolicyGlobal; | 31 struct PolicyGlobal; |
31 | 32 |
32 typedef std::vector<base::win::ScopedHandle*> HandleList; | 33 typedef std::vector<base::win::ScopedHandle*> HandleList; |
33 | 34 |
34 // We act as a policy dispatcher, implementing the handler for the "ping" IPC, | 35 class PolicyBase : public TargetPolicy { |
35 // so we have to provide the appropriate handler on the OnMessageReady method. | |
36 // There is a static_cast for the handler, and the compiler only performs the | |
37 // cast if the first base class is Dispatcher. | |
38 class PolicyBase : public Dispatcher, public TargetPolicy { | |
39 public: | 36 public: |
40 PolicyBase(); | 37 PolicyBase(); |
41 | 38 |
42 // TargetPolicy: | 39 // TargetPolicy: |
43 void AddRef() override; | 40 void AddRef() override; |
44 void Release() override; | 41 void Release() override; |
45 ResultCode SetTokenLevel(TokenLevel initial, TokenLevel lockdown) override; | 42 ResultCode SetTokenLevel(TokenLevel initial, TokenLevel lockdown) override; |
46 TokenLevel GetInitialTokenLevel() const override; | 43 TokenLevel GetInitialTokenLevel() const override; |
47 TokenLevel GetLockdownTokenLevel() const override; | 44 TokenLevel GetLockdownTokenLevel() const override; |
48 ResultCode SetJobLevel(JobLevel job_level, uint32 ui_exceptions) override; | 45 ResultCode SetJobLevel(JobLevel job_level, uint32 ui_exceptions) override; |
(...skipping 16 matching lines...) Expand all Loading... |
65 ResultCode SetStdoutHandle(HANDLE handle) override; | 62 ResultCode SetStdoutHandle(HANDLE handle) override; |
66 ResultCode SetStderrHandle(HANDLE handle) override; | 63 ResultCode SetStderrHandle(HANDLE handle) override; |
67 ResultCode AddRule(SubSystem subsystem, | 64 ResultCode AddRule(SubSystem subsystem, |
68 Semantics semantics, | 65 Semantics semantics, |
69 const wchar_t* pattern) override; | 66 const wchar_t* pattern) override; |
70 ResultCode AddDllToUnload(const wchar_t* dll_name) override; | 67 ResultCode AddDllToUnload(const wchar_t* dll_name) override; |
71 ResultCode AddKernelObjectToClose(const base::char16* handle_type, | 68 ResultCode AddKernelObjectToClose(const base::char16* handle_type, |
72 const base::char16* handle_name) override; | 69 const base::char16* handle_name) override; |
73 void* AddHandleToShare(HANDLE handle) override; | 70 void* AddHandleToShare(HANDLE handle) override; |
74 | 71 |
75 // Dispatcher: | |
76 Dispatcher* OnMessageReady(IPCParams* ipc, | |
77 CallbackGeneric* callback) override; | |
78 bool SetupService(InterceptionManager* manager, int service) override; | |
79 | |
80 // Creates a Job object with the level specified in a previous call to | 72 // Creates a Job object with the level specified in a previous call to |
81 // SetJobLevel(). | 73 // SetJobLevel(). |
82 ResultCode MakeJobObject(base::win::ScopedHandle* job); | 74 ResultCode MakeJobObject(base::win::ScopedHandle* job); |
83 | 75 |
84 // Creates the two tokens with the levels specified in a previous call to | 76 // Creates the two tokens with the levels specified in a previous call to |
85 // SetTokenLevel(). Also creates a lowbox token if specified based on the | 77 // SetTokenLevel(). Also creates a lowbox token if specified based on the |
86 // lowbox SID. | 78 // lowbox SID. |
87 ResultCode MakeTokens(base::win::ScopedHandle* initial, | 79 ResultCode MakeTokens(base::win::ScopedHandle* initial, |
88 base::win::ScopedHandle* lockdown, | 80 base::win::ScopedHandle* lockdown, |
89 base::win::ScopedHandle* lowbox); | 81 base::win::ScopedHandle* lowbox); |
(...skipping 16 matching lines...) Expand all Loading... |
106 HANDLE GetStdoutHandle(); | 98 HANDLE GetStdoutHandle(); |
107 HANDLE GetStderrHandle(); | 99 HANDLE GetStderrHandle(); |
108 | 100 |
109 // Returns the list of handles being shared with the target process. | 101 // Returns the list of handles being shared with the target process. |
110 const HandleList& GetHandlesBeingShared(); | 102 const HandleList& GetHandlesBeingShared(); |
111 | 103 |
112 // Closes the handles being shared with the target and clears out the list. | 104 // Closes the handles being shared with the target and clears out the list. |
113 void ClearSharedHandles(); | 105 void ClearSharedHandles(); |
114 | 106 |
115 private: | 107 private: |
116 ~PolicyBase() override; | 108 ~PolicyBase(); |
117 | |
118 // Test IPC providers. | |
119 bool Ping(IPCInfo* ipc, void* cookie); | |
120 | |
121 // Returns a dispatcher from ipc_targets_. | |
122 Dispatcher* GetDispatcher(int ipc_tag); | |
123 | 109 |
124 // Sets up interceptions for a new target. | 110 // Sets up interceptions for a new target. |
125 bool SetupAllInterceptions(TargetProcess* target); | 111 bool SetupAllInterceptions(TargetProcess* target); |
126 | 112 |
127 // Sets up the handle closer for a new target. | 113 // Sets up the handle closer for a new target. |
128 bool SetupHandleCloser(TargetProcess* target); | 114 bool SetupHandleCloser(TargetProcess* target); |
129 | 115 |
130 ResultCode AddRuleInternal(SubSystem subsystem, | 116 ResultCode AddRuleInternal(SubSystem subsystem, |
131 Semantics semantics, | 117 Semantics semantics, |
132 const wchar_t* pattern); | 118 const wchar_t* pattern); |
(...skipping 16 matching lines...) Expand all Loading... |
149 bool use_alternate_winstation_; | 135 bool use_alternate_winstation_; |
150 // Helps the file system policy initialization. | 136 // Helps the file system policy initialization. |
151 bool file_system_init_; | 137 bool file_system_init_; |
152 bool relaxed_interceptions_; | 138 bool relaxed_interceptions_; |
153 HANDLE stdout_handle_; | 139 HANDLE stdout_handle_; |
154 HANDLE stderr_handle_; | 140 HANDLE stderr_handle_; |
155 IntegrityLevel integrity_level_; | 141 IntegrityLevel integrity_level_; |
156 IntegrityLevel delayed_integrity_level_; | 142 IntegrityLevel delayed_integrity_level_; |
157 MitigationFlags mitigations_; | 143 MitigationFlags mitigations_; |
158 MitigationFlags delayed_mitigations_; | 144 MitigationFlags delayed_mitigations_; |
159 // The array of objects that will answer IPC calls. | |
160 Dispatcher* ipc_targets_[IPC_LAST_TAG]; | |
161 // Object in charge of generating the low level policy. | 145 // Object in charge of generating the low level policy. |
162 LowLevelPolicy* policy_maker_; | 146 LowLevelPolicy* policy_maker_; |
163 // Memory structure that stores the low level policy. | 147 // Memory structure that stores the low level policy. |
164 PolicyGlobal* policy_; | 148 PolicyGlobal* policy_; |
165 // The list of dlls to unload in the target process. | 149 // The list of dlls to unload in the target process. |
166 std::vector<base::string16> blacklisted_dlls_; | 150 std::vector<base::string16> blacklisted_dlls_; |
167 // This is a map of handle-types to names that we need to close in the | 151 // This is a map of handle-types to names that we need to close in the |
168 // target process. A null set means we need to close all handles of the | 152 // target process. A null set means we need to close all handles of the |
169 // given type. | 153 // given type. |
170 HandleCloser handle_closer_; | 154 HandleCloser handle_closer_; |
171 std::vector<base::string16> capabilities_; | 155 std::vector<base::string16> capabilities_; |
172 scoped_ptr<AppContainerAttributes> appcontainer_list_; | 156 scoped_ptr<AppContainerAttributes> appcontainer_list_; |
173 PSID lowbox_sid_; | 157 PSID lowbox_sid_; |
174 base::win::ScopedHandle lowbox_directory_; | 158 base::win::ScopedHandle lowbox_directory_; |
| 159 scoped_ptr<Dispatcher> dispatcher_; |
175 | 160 |
176 static HDESK alternate_desktop_handle_; | 161 static HDESK alternate_desktop_handle_; |
177 static HWINSTA alternate_winstation_handle_; | 162 static HWINSTA alternate_winstation_handle_; |
178 static IntegrityLevel alternate_desktop_integrity_level_label_; | 163 static IntegrityLevel alternate_desktop_integrity_level_label_; |
179 | 164 |
180 // Contains the list of handles being shared with the target process. | 165 // Contains the list of handles being shared with the target process. |
181 // This list contains handles other than the stderr/stdout handles which are | 166 // This list contains handles other than the stderr/stdout handles which are |
182 // shared with the target at times. | 167 // shared with the target at times. |
183 HandleList handles_to_share_; | 168 HandleList handles_to_share_; |
184 | 169 |
185 DISALLOW_COPY_AND_ASSIGN(PolicyBase); | 170 DISALLOW_COPY_AND_ASSIGN(PolicyBase); |
186 }; | 171 }; |
187 | 172 |
188 } // namespace sandbox | 173 } // namespace sandbox |
189 | 174 |
190 #endif // SANDBOX_WIN_SRC_SANDBOX_POLICY_BASE_H_ | 175 #endif // SANDBOX_WIN_SRC_SANDBOX_POLICY_BASE_H_ |
OLD | NEW |