OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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/src/process_thread_policy.h" | 5 #include "sandbox/src/process_thread_policy.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "sandbox/src/ipc_tags.h" | 10 #include "sandbox/src/ipc_tags.h" |
11 #include "sandbox/src/nt_internals.h" | 11 #include "sandbox/src/nt_internals.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 if (!policy->AddRule(IPC_CREATEPROCESSW_TAG, process.get())) { | 97 if (!policy->AddRule(IPC_CREATEPROCESSW_TAG, process.get())) { |
98 return false; | 98 return false; |
99 } | 99 } |
100 return true; | 100 return true; |
101 } | 101 } |
102 | 102 |
103 NTSTATUS ProcessPolicy::OpenThreadAction(const ClientInfo& client_info, | 103 NTSTATUS ProcessPolicy::OpenThreadAction(const ClientInfo& client_info, |
104 uint32 desired_access, | 104 uint32 desired_access, |
105 uint32 thread_id, | 105 uint32 thread_id, |
106 HANDLE *handle) { | 106 HANDLE* handle) { |
107 *handle = NULL; | 107 *handle = NULL; |
108 | 108 |
109 NtOpenThreadFunction NtOpenThread = NULL; | 109 NtOpenThreadFunction NtOpenThread = NULL; |
110 ResolveNTFunctionPtr("NtOpenThread", &NtOpenThread); | 110 ResolveNTFunctionPtr("NtOpenThread", &NtOpenThread); |
111 | 111 |
112 OBJECT_ATTRIBUTES attributes = {0}; | 112 OBJECT_ATTRIBUTES attributes = {0}; |
113 attributes.Length = sizeof(attributes); | 113 attributes.Length = sizeof(attributes); |
114 CLIENT_ID client_id = {0}; | 114 CLIENT_ID client_id = {0}; |
115 client_id.UniqueProcess = reinterpret_cast<PVOID>( | 115 client_id.UniqueProcess = reinterpret_cast<PVOID>( |
116 static_cast<ULONG_PTR>(client_info.process_id)); | 116 static_cast<ULONG_PTR>(client_info.process_id)); |
(...skipping 11 matching lines...) Expand all Loading... |
128 return STATUS_ACCESS_DENIED; | 128 return STATUS_ACCESS_DENIED; |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 return status; | 132 return status; |
133 } | 133 } |
134 | 134 |
135 NTSTATUS ProcessPolicy::OpenProcessAction(const ClientInfo& client_info, | 135 NTSTATUS ProcessPolicy::OpenProcessAction(const ClientInfo& client_info, |
136 uint32 desired_access, | 136 uint32 desired_access, |
137 uint32 process_id, | 137 uint32 process_id, |
138 HANDLE *handle) { | 138 HANDLE* handle) { |
139 *handle = NULL; | 139 *handle = NULL; |
140 | 140 |
141 NtOpenProcessFunction NtOpenProcess = NULL; | 141 NtOpenProcessFunction NtOpenProcess = NULL; |
142 ResolveNTFunctionPtr("NtOpenProcess", &NtOpenProcess); | 142 ResolveNTFunctionPtr("NtOpenProcess", &NtOpenProcess); |
143 | 143 |
144 if (client_info.process_id != process_id) | 144 if (client_info.process_id != process_id) |
145 return STATUS_ACCESS_DENIED; | 145 return STATUS_ACCESS_DENIED; |
146 | 146 |
147 OBJECT_ATTRIBUTES attributes = {0}; | 147 OBJECT_ATTRIBUTES attributes = {0}; |
148 attributes.Length = sizeof(attributes); | 148 attributes.Length = sizeof(attributes); |
149 CLIENT_ID client_id = {0}; | 149 CLIENT_ID client_id = {0}; |
150 client_id.UniqueProcess = reinterpret_cast<PVOID>( | 150 client_id.UniqueProcess = reinterpret_cast<PVOID>( |
151 static_cast<ULONG_PTR>(client_info.process_id)); | 151 static_cast<ULONG_PTR>(client_info.process_id)); |
152 HANDLE local_handle; | 152 HANDLE local_handle; |
153 NTSTATUS status = NtOpenProcess(&local_handle, desired_access, &attributes, | 153 NTSTATUS status = NtOpenProcess(&local_handle, desired_access, &attributes, |
154 &client_id); | 154 &client_id); |
155 if (NT_SUCCESS(status)) { | 155 if (NT_SUCCESS(status)) { |
156 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, | 156 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, |
157 client_info.process, handle, 0, FALSE, | 157 client_info.process, handle, 0, FALSE, |
158 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { | 158 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { |
159 ::CloseHandle(local_handle); | 159 ::CloseHandle(local_handle); |
160 return STATUS_ACCESS_DENIED; | 160 return STATUS_ACCESS_DENIED; |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 return status; | 164 return status; |
165 } | 165 } |
166 | 166 |
167 NTSTATUS ProcessPolicy::OpenProcessTokenAction(const ClientInfo& client_info, | 167 NTSTATUS ProcessPolicy::OpenProcessTokenAction(const ClientInfo& client_info, |
168 uint32 process_requested, | 168 HANDLE process, |
169 uint32 desired_access, | 169 uint32 desired_access, |
170 HANDLE *handle) { | 170 HANDLE* handle) { |
171 *handle = NULL; | 171 *handle = NULL; |
172 | |
173 NtOpenProcessTokenFunction NtOpenProcessToken = NULL; | 172 NtOpenProcessTokenFunction NtOpenProcessToken = NULL; |
174 ResolveNTFunctionPtr("NtOpenProcessToken", &NtOpenProcessToken); | 173 ResolveNTFunctionPtr("NtOpenProcessToken", &NtOpenProcessToken); |
175 | 174 |
176 HANDLE process = reinterpret_cast<HANDLE>( | |
177 static_cast<ULONG_PTR>(process_requested)); | |
178 if (CURRENT_PROCESS != process) | 175 if (CURRENT_PROCESS != process) |
179 return STATUS_ACCESS_DENIED; | 176 return STATUS_ACCESS_DENIED; |
180 | 177 |
181 HANDLE local_handle; | 178 HANDLE local_handle; |
182 NTSTATUS status = NtOpenProcessToken(client_info.process, desired_access, | 179 NTSTATUS status = NtOpenProcessToken(client_info.process, desired_access, |
183 &local_handle); | 180 &local_handle); |
184 if (NT_SUCCESS(status)) { | 181 if (NT_SUCCESS(status)) { |
185 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, | 182 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, |
186 client_info.process, handle, 0, FALSE, | 183 client_info.process, handle, 0, FALSE, |
187 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { | 184 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { |
188 ::CloseHandle(local_handle); | 185 ::CloseHandle(local_handle); |
189 return STATUS_ACCESS_DENIED; | 186 return STATUS_ACCESS_DENIED; |
190 } | 187 } |
191 } | 188 } |
192 | |
193 return status; | 189 return status; |
194 } | 190 } |
195 | 191 |
196 NTSTATUS ProcessPolicy::OpenProcessTokenExAction(const ClientInfo& client_info, | 192 NTSTATUS ProcessPolicy::OpenProcessTokenExAction(const ClientInfo& client_info, |
197 uint32 process_requested, | 193 HANDLE process, |
198 uint32 desired_access, | 194 uint32 desired_access, |
199 uint32 attributes, | 195 uint32 attributes, |
200 HANDLE *handle) { | 196 HANDLE* handle) { |
201 *handle = NULL; | 197 *handle = NULL; |
202 NtOpenProcessTokenExFunction NtOpenProcessTokenEx = NULL; | 198 NtOpenProcessTokenExFunction NtOpenProcessTokenEx = NULL; |
203 ResolveNTFunctionPtr("NtOpenProcessTokenEx", &NtOpenProcessTokenEx); | 199 ResolveNTFunctionPtr("NtOpenProcessTokenEx", &NtOpenProcessTokenEx); |
204 | 200 |
205 HANDLE process = reinterpret_cast<HANDLE>( | |
206 static_cast<ULONG_PTR>(process_requested)); | |
207 if (CURRENT_PROCESS != process) | 201 if (CURRENT_PROCESS != process) |
208 return STATUS_ACCESS_DENIED; | 202 return STATUS_ACCESS_DENIED; |
209 | 203 |
210 HANDLE local_handle; | 204 HANDLE local_handle; |
211 NTSTATUS status = NtOpenProcessTokenEx(client_info.process, desired_access, | 205 NTSTATUS status = NtOpenProcessTokenEx(client_info.process, desired_access, |
212 attributes, &local_handle); | 206 attributes, &local_handle); |
213 if (NT_SUCCESS(status)) { | 207 if (NT_SUCCESS(status)) { |
214 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, | 208 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, |
215 client_info.process, handle, 0, FALSE, | 209 client_info.process, handle, 0, FALSE, |
216 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { | 210 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { |
217 ::CloseHandle(local_handle); | 211 ::CloseHandle(local_handle); |
218 return STATUS_ACCESS_DENIED; | 212 return STATUS_ACCESS_DENIED; |
219 } | 213 } |
220 } | 214 } |
221 | |
222 return status; | 215 return status; |
223 } | 216 } |
224 | 217 |
225 DWORD ProcessPolicy::CreateProcessWAction(EvalResult eval_result, | 218 DWORD ProcessPolicy::CreateProcessWAction(EvalResult eval_result, |
226 const ClientInfo& client_info, | 219 const ClientInfo& client_info, |
227 const std::wstring &app_name, | 220 const std::wstring &app_name, |
228 const std::wstring &command_line, | 221 const std::wstring &command_line, |
229 PROCESS_INFORMATION* process_info) { | 222 PROCESS_INFORMATION* process_info) { |
230 // The only action supported is ASK_BROKER which means create the process. | 223 // The only action supported is ASK_BROKER which means create the process. |
231 if (GIVE_ALLACCESS != eval_result && GIVE_READONLY != eval_result) { | 224 if (GIVE_ALLACCESS != eval_result && GIVE_READONLY != eval_result) { |
232 return ERROR_ACCESS_DENIED; | 225 return ERROR_ACCESS_DENIED; |
233 } | 226 } |
234 | 227 |
235 STARTUPINFO startup_info = {0}; | 228 STARTUPINFO startup_info = {0}; |
236 startup_info.cb = sizeof(startup_info); | 229 startup_info.cb = sizeof(startup_info); |
237 scoped_ptr_malloc<wchar_t> cmd_line(_wcsdup(command_line.c_str())); | 230 scoped_ptr_malloc<wchar_t> cmd_line(_wcsdup(command_line.c_str())); |
238 | 231 |
239 BOOL should_give_full_access = (GIVE_ALLACCESS == eval_result); | 232 BOOL should_give_full_access = (GIVE_ALLACCESS == eval_result); |
240 if (!CreateProcessExWHelper(client_info.process, should_give_full_access, | 233 if (!CreateProcessExWHelper(client_info.process, should_give_full_access, |
241 app_name.c_str(), cmd_line.get(), NULL, NULL, | 234 app_name.c_str(), cmd_line.get(), NULL, NULL, |
242 FALSE, 0, NULL, NULL, &startup_info, | 235 FALSE, 0, NULL, NULL, &startup_info, |
243 process_info)) { | 236 process_info)) { |
244 return ERROR_ACCESS_DENIED; | 237 return ERROR_ACCESS_DENIED; |
245 } | 238 } |
246 return ERROR_SUCCESS; | 239 return ERROR_SUCCESS; |
247 } | 240 } |
248 | 241 |
249 } // namespace sandbox | 242 } // namespace sandbox |
OLD | NEW |