Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: sandbox/win/src/broker_services.cc

Issue 1826223004: Correctly handle child processes of sandboxed target processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove unused test Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | sandbox/win/src/process_mitigations_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/win/src/broker_services.h" 5 #include "sandbox/win/src/broker_services.h"
6 6
7 #include <AclAPI.h> 7 #include <AclAPI.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 if (NULL == param) 188 if (NULL == param)
189 return 1; 189 return 1;
190 190
191 base::PlatformThread::SetName("BrokerEvent"); 191 base::PlatformThread::SetName("BrokerEvent");
192 192
193 BrokerServicesBase* broker = reinterpret_cast<BrokerServicesBase*>(param); 193 BrokerServicesBase* broker = reinterpret_cast<BrokerServicesBase*>(param);
194 HANDLE port = broker->job_port_.Get(); 194 HANDLE port = broker->job_port_.Get();
195 HANDLE no_targets = broker->no_targets_.Get(); 195 HANDLE no_targets = broker->no_targets_.Get();
196 196
197 int target_counter = 0; 197 int target_counter = 0;
198 int untracked_target_counter = 0;
198 ::ResetEvent(no_targets); 199 ::ResetEvent(no_targets);
199 200
200 while (true) { 201 while (true) {
201 DWORD events = 0; 202 DWORD events = 0;
202 ULONG_PTR key = 0; 203 ULONG_PTR key = 0;
203 LPOVERLAPPED ovl = NULL; 204 LPOVERLAPPED ovl = NULL;
204 205
205 if (!::GetQueuedCompletionStatus(port, &events, &key, &ovl, INFINITE)) { 206 if (!::GetQueuedCompletionStatus(port, &events, &key, &ovl, INFINITE)) {
206 // this call fails if the port has been closed before we have a 207 // this call fails if the port has been closed before we have a
207 // chance to service the last packet which is 'exit' anyway so 208 // chance to service the last packet which is 'exit' anyway so
(...skipping 11 matching lines...) Expand all
219 // The job object has signaled that the last process associated 220 // The job object has signaled that the last process associated
220 // with it has terminated. Assuming there is no way for a process 221 // with it has terminated. Assuming there is no way for a process
221 // to appear out of thin air in this job, it safe to assume that 222 // to appear out of thin air in this job, it safe to assume that
222 // we can tell the policy to destroy the target object, and for 223 // we can tell the policy to destroy the target object, and for
223 // us to release our reference to the policy object. 224 // us to release our reference to the policy object.
224 tracker->FreeResources(); 225 tracker->FreeResources();
225 break; 226 break;
226 } 227 }
227 228
228 case JOB_OBJECT_MSG_NEW_PROCESS: { 229 case JOB_OBJECT_MSG_NEW_PROCESS: {
230 DWORD handle = static_cast<DWORD>(reinterpret_cast<uintptr_t>(ovl));
231 {
232 AutoLock lock(&broker->lock_);
233 size_t count = broker->child_process_ids_.count(handle);
234 // Child process created from sandboxed process.
235 if (count == 0)
236 untracked_target_counter++;
237 }
229 ++target_counter; 238 ++target_counter;
230 if (1 == target_counter) { 239 if (1 == target_counter) {
231 ::ResetEvent(no_targets); 240 ::ResetEvent(no_targets);
232 } 241 }
233 break; 242 break;
234 } 243 }
235 244
236 case JOB_OBJECT_MSG_EXIT_PROCESS: 245 case JOB_OBJECT_MSG_EXIT_PROCESS:
237 case JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS: { 246 case JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS: {
247 size_t erase_result = 0;
238 { 248 {
239 AutoLock lock(&broker->lock_); 249 AutoLock lock(&broker->lock_);
240 broker->child_process_ids_.erase( 250 erase_result = broker->child_process_ids_.erase(
241 static_cast<DWORD>(reinterpret_cast<uintptr_t>(ovl))); 251 static_cast<DWORD>(reinterpret_cast<uintptr_t>(ovl)));
242 } 252 }
253 if (erase_result != 1U) {
254 // The process was untracked e.g. a child process of the target.
255 --untracked_target_counter;
256 DCHECK(untracked_target_counter >= 0);
257 }
243 --target_counter; 258 --target_counter;
244 if (0 == target_counter) 259 if (0 == target_counter)
245 ::SetEvent(no_targets); 260 ::SetEvent(no_targets);
246 261
247 DCHECK(target_counter >= 0); 262 DCHECK(target_counter >= 0);
248 break; 263 break;
249 } 264 }
250 265
251 case JOB_OBJECT_MSG_ACTIVE_PROCESS_LIMIT: { 266 case JOB_OBJECT_MSG_ACTIVE_PROCESS_LIMIT: {
267 // A child process attempted and failed to create a child process.
268 // Windows does not reveal the process id.
269 untracked_target_counter++;
270 target_counter++;
252 break; 271 break;
253 } 272 }
254 273
255 case JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT: { 274 case JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT: {
256 BOOL res = ::TerminateJobObject(tracker->job.Get(), 275 BOOL res = ::TerminateJobObject(tracker->job.Get(),
257 SBOX_FATAL_MEMORY_EXCEEDED); 276 SBOX_FATAL_MEMORY_EXCEEDED);
258 DCHECK(res); 277 DCHECK(res);
259 break; 278 break;
260 } 279 }
261 280
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 return SBOX_ERROR_UNSUPPORTED; 575 return SBOX_ERROR_UNSUPPORTED;
557 576
558 base::string16 name = LookupAppContainer(sid); 577 base::string16 name = LookupAppContainer(sid);
559 if (name.empty()) 578 if (name.empty())
560 return SBOX_ERROR_INVALID_APP_CONTAINER; 579 return SBOX_ERROR_INVALID_APP_CONTAINER;
561 580
562 return DeleteAppContainer(sid); 581 return DeleteAppContainer(sid);
563 } 582 }
564 583
565 } // namespace sandbox 584 } // namespace sandbox
OLDNEW
« no previous file with comments | « no previous file | sandbox/win/src/process_mitigations_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698