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

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

Issue 1225183003: CreateThread interception, to use CreateRemoteThread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix up casts Created 4 years, 10 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 | « sandbox/win/src/process_thread_interception.h ('k') | sandbox/win/src/process_thread_policy.h » ('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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/process_thread_interception.h" 5 #include "sandbox/win/src/process_thread_interception.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8 #include "base/win/windows_version.h"
9 #include "sandbox/win/src/crosscall_client.h" 9 #include "sandbox/win/src/crosscall_client.h"
10 #include "sandbox/win/src/ipc_tags.h" 10 #include "sandbox/win/src/ipc_tags.h"
11 #include "sandbox/win/src/policy_params.h" 11 #include "sandbox/win/src/policy_params.h"
12 #include "sandbox/win/src/policy_target.h" 12 #include "sandbox/win/src/policy_target.h"
13 #include "sandbox/win/src/sandbox_factory.h" 13 #include "sandbox/win/src/sandbox_factory.h"
14 #include "sandbox/win/src/sandbox_nt_util.h" 14 #include "sandbox/win/src/sandbox_nt_util.h"
15 #include "sandbox/win/src/sharedmem_ipc_client.h" 15 #include "sandbox/win/src/sharedmem_ipc_client.h"
16 #include "sandbox/win/src/target_services.h" 16 #include "sandbox/win/src/target_services.h"
17 17
18 namespace sandbox { 18 namespace sandbox {
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 if (ERROR_SUCCESS != answer.win32_result) 401 if (ERROR_SUCCESS != answer.win32_result)
402 return FALSE; 402 return FALSE;
403 403
404 return TRUE; 404 return TRUE;
405 } while (false); 405 } while (false);
406 406
407 ::SetLastError(original_error); 407 ::SetLastError(original_error);
408 return FALSE; 408 return FALSE;
409 } 409 }
410 410
411 HANDLE WINAPI TargetCreateThread(CreateThreadFunction orig_CreateThread,
412 LPSECURITY_ATTRIBUTES thread_attributes,
413 SIZE_T stack_size,
414 LPTHREAD_START_ROUTINE start_address,
415 LPVOID parameter,
416 DWORD creation_flags,
417 LPDWORD thread_id) {
418 HANDLE hThread = NULL;
419
420 TargetServices* target_services = SandboxFactory::GetTargetServices();
421 if (NULL == target_services ||
422 target_services->GetState()->IsCsrssConnected()) {
423 hThread = orig_CreateThread(thread_attributes, stack_size, start_address,
424 parameter, creation_flags, thread_id);
425 if (hThread) {
426 return hThread;
427 }
428 }
429
430 DWORD original_error = ::GetLastError();
431 do {
432 if (NULL == target_services)
433 break;
434
435 // We don't trust that the IPC can work this early.
436 if (!target_services->GetState()->InitCalled())
437 break;
438
439 __try {
440 if (NULL != thread_id &&
441 !ValidParameter(thread_id, sizeof(*thread_id), WRITE))
442 break;
443
444 if (nullptr == start_address)
445 break;
446 // We don't support thread_attributes not being null.
447 if (nullptr != thread_attributes)
448 break;
449 } __except (EXCEPTION_EXECUTE_HANDLER) {
450 break;
451 }
452
453 void* memory = GetGlobalIPCMemory();
454 if (nullptr == memory)
455 break;
456
457 SharedMemIPCClient ipc(memory);
458 CrossCallReturn answer = {0};
459
460 // NOTE: we don't pass the thread_attributes through. This matches the
461 // approach in CreateProcess and in CreateThreadInternal().
462 ResultCode code = CrossCall(ipc, IPC_CREATETHREAD_TAG,
463 reinterpret_cast<LPVOID>(stack_size),
464 reinterpret_cast<LPVOID>(start_address),
465 parameter, creation_flags, &answer);
466 if (SBOX_ALL_OK != code)
467 break;
468
469 ::SetLastError(answer.win32_result);
470 if (ERROR_SUCCESS != answer.win32_result) {
471 return NULL;
472 }
473
474 __try {
475 if (thread_id != NULL) {
476 *thread_id = ::GetThreadId(answer.handle);
477 }
478 return answer.handle;
479 } __except (EXCEPTION_EXECUTE_HANDLER) {
480 break;
481 }
482 } while (false);
483
484 ::SetLastError(original_error);
485 return NULL;
486 }
487
411 } // namespace sandbox 488 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/process_thread_interception.h ('k') | sandbox/win/src/process_thread_policy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698