OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef SANDBOX_WIN_SRC_SANDBOX_POLICY_BASE_H_ | |
6 #define SANDBOX_WIN_SRC_SANDBOX_POLICY_BASE_H_ | |
7 | |
8 #include <windows.h> | |
9 | |
10 #include <list> | |
11 #include <vector> | |
12 | |
13 #include "base/basictypes.h" | |
14 #include "base/compiler_specific.h" | |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "base/strings/string16.h" | |
17 #include "base/win/scoped_handle.h" | |
18 #include "sandbox/win/src/crosscall_server.h" | |
19 #include "sandbox/win/src/handle_closer.h" | |
20 #include "sandbox/win/src/ipc_tags.h" | |
21 #include "sandbox/win/src/policy_engine_opcodes.h" | |
22 #include "sandbox/win/src/policy_engine_params.h" | |
23 #include "sandbox/win/src/sandbox_policy.h" | |
24 #include "sandbox/win/src/win_utils.h" | |
25 | |
26 namespace sandbox { | |
27 | |
28 class AppContainerAttributes; | |
29 class LowLevelPolicy; | |
30 class TargetProcess; | |
31 struct PolicyGlobal; | |
32 | |
33 typedef std::vector<base::win::ScopedHandle*> HandleList; | |
34 | |
35 class PolicyBase final : public TargetPolicy { | |
36 public: | |
37 PolicyBase(); | |
38 | |
39 // TargetPolicy: | |
40 void AddRef() override; | |
41 void Release() override; | |
42 ResultCode SetTokenLevel(TokenLevel initial, TokenLevel lockdown) override; | |
43 TokenLevel GetInitialTokenLevel() const override; | |
44 TokenLevel GetLockdownTokenLevel() const override; | |
45 ResultCode SetJobLevel(JobLevel job_level, uint32 ui_exceptions) override; | |
46 ResultCode SetJobMemoryLimit(size_t memory_limit) override; | |
47 ResultCode SetAlternateDesktop(bool alternate_winstation) override; | |
48 base::string16 GetAlternateDesktop() const override; | |
49 ResultCode CreateAlternateDesktop(bool alternate_winstation) override; | |
50 void DestroyAlternateDesktop() override; | |
51 ResultCode SetIntegrityLevel(IntegrityLevel integrity_level) override; | |
52 IntegrityLevel GetIntegrityLevel() const override; | |
53 ResultCode SetDelayedIntegrityLevel(IntegrityLevel integrity_level) override; | |
54 ResultCode SetAppContainer(const wchar_t* sid) override; | |
55 ResultCode SetCapability(const wchar_t* sid) override; | |
56 ResultCode SetLowBox(const wchar_t* sid) override; | |
57 ResultCode SetProcessMitigations(MitigationFlags flags) override; | |
58 MitigationFlags GetProcessMitigations() override; | |
59 ResultCode SetDelayedProcessMitigations(MitigationFlags flags) override; | |
60 MitigationFlags GetDelayedProcessMitigations() const override; | |
61 void SetStrictInterceptions() override; | |
62 ResultCode SetStdoutHandle(HANDLE handle) override; | |
63 ResultCode SetStderrHandle(HANDLE handle) override; | |
64 ResultCode AddRule(SubSystem subsystem, | |
65 Semantics semantics, | |
66 const wchar_t* pattern) override; | |
67 ResultCode AddDllToUnload(const wchar_t* dll_name) override; | |
68 ResultCode AddKernelObjectToClose(const base::char16* handle_type, | |
69 const base::char16* handle_name) override; | |
70 void* AddHandleToShare(HANDLE handle) override; | |
71 | |
72 // Creates a Job object with the level specified in a previous call to | |
73 // SetJobLevel(). | |
74 ResultCode MakeJobObject(base::win::ScopedHandle* job); | |
75 | |
76 // Creates the two tokens with the levels specified in a previous call to | |
77 // SetTokenLevel(). Also creates a lowbox token if specified based on the | |
78 // lowbox SID. | |
79 ResultCode MakeTokens(base::win::ScopedHandle* initial, | |
80 base::win::ScopedHandle* lockdown, | |
81 base::win::ScopedHandle* lowbox); | |
82 | |
83 const AppContainerAttributes* GetAppContainer() const; | |
84 | |
85 PSID GetLowBoxSid() const; | |
86 | |
87 // Adds a target process to the internal list of targets. Internally a | |
88 // call to TargetProcess::Init() is issued. | |
89 bool AddTarget(TargetProcess* target); | |
90 | |
91 // Called when there are no more active processes in a Job. | |
92 // Removes a Job object associated with this policy and the target associated | |
93 // with the job. | |
94 bool OnJobEmpty(HANDLE job); | |
95 | |
96 EvalResult EvalPolicy(int service, CountedParameterSetBase* params); | |
97 | |
98 HANDLE GetStdoutHandle(); | |
99 HANDLE GetStderrHandle(); | |
100 | |
101 // Returns the list of handles being shared with the target process. | |
102 const HandleList& GetHandlesBeingShared(); | |
103 | |
104 // Closes the handles being shared with the target and clears out the list. | |
105 void ClearSharedHandles(); | |
106 | |
107 private: | |
108 ~PolicyBase(); | |
109 | |
110 // Sets up interceptions for a new target. | |
111 bool SetupAllInterceptions(TargetProcess* target); | |
112 | |
113 // Sets up the handle closer for a new target. | |
114 bool SetupHandleCloser(TargetProcess* target); | |
115 | |
116 ResultCode AddRuleInternal(SubSystem subsystem, | |
117 Semantics semantics, | |
118 const wchar_t* pattern); | |
119 | |
120 // This lock synchronizes operations on the targets_ collection. | |
121 CRITICAL_SECTION lock_; | |
122 // Maintains the list of target process associated with this policy. | |
123 // The policy takes ownership of them. | |
124 typedef std::list<TargetProcess*> TargetSet; | |
125 TargetSet targets_; | |
126 // Standard object-lifetime reference counter. | |
127 volatile LONG ref_count; | |
128 // The user-defined global policy settings. | |
129 TokenLevel lockdown_level_; | |
130 TokenLevel initial_level_; | |
131 JobLevel job_level_; | |
132 uint32 ui_exceptions_; | |
133 size_t memory_limit_; | |
134 bool use_alternate_desktop_; | |
135 bool use_alternate_winstation_; | |
136 // Helps the file system policy initialization. | |
137 bool file_system_init_; | |
138 bool relaxed_interceptions_; | |
139 HANDLE stdout_handle_; | |
140 HANDLE stderr_handle_; | |
141 IntegrityLevel integrity_level_; | |
142 IntegrityLevel delayed_integrity_level_; | |
143 MitigationFlags mitigations_; | |
144 MitigationFlags delayed_mitigations_; | |
145 // Object in charge of generating the low level policy. | |
146 LowLevelPolicy* policy_maker_; | |
147 // Memory structure that stores the low level policy. | |
148 PolicyGlobal* policy_; | |
149 // The list of dlls to unload in the target process. | |
150 std::vector<base::string16> blacklisted_dlls_; | |
151 // This is a map of handle-types to names that we need to close in the | |
152 // target process. A null set means we need to close all handles of the | |
153 // given type. | |
154 HandleCloser handle_closer_; | |
155 std::vector<base::string16> capabilities_; | |
156 scoped_ptr<AppContainerAttributes> appcontainer_list_; | |
157 PSID lowbox_sid_; | |
158 base::win::ScopedHandle lowbox_directory_; | |
159 scoped_ptr<Dispatcher> dispatcher_; | |
160 | |
161 static HDESK alternate_desktop_handle_; | |
162 static HWINSTA alternate_winstation_handle_; | |
163 static IntegrityLevel alternate_desktop_integrity_level_label_; | |
164 | |
165 // Contains the list of handles being shared with the target process. | |
166 // This list contains handles other than the stderr/stdout handles which are | |
167 // shared with the target at times. | |
168 HandleList handles_to_share_; | |
169 | |
170 DISALLOW_COPY_AND_ASSIGN(PolicyBase); | |
171 }; | |
172 | |
173 } // namespace sandbox | |
174 | |
175 #endif // SANDBOX_WIN_SRC_SANDBOX_POLICY_BASE_H_ | |
OLD | NEW |