OLD | NEW |
---|---|
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 "base/win/windows_version.h" | |
cpu_(ooo_6.6-7.5)
2016/02/04 01:40:52
wrong include order?
| |
7 #include <stdint.h> | 8 #include <stdint.h> |
8 | |
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 Loading... | |
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, | |
cpu_(ooo_6.6-7.5)
2016/02/04 01:40:52
this block looks funny. Regardless of crss state,
jschuh
2016/02/04 04:49:51
No, because CreateThread() will try to register vi
| |
424 parameter, creation_flags, thread_id); | |
425 if (hThread) { | |
426 return hThread; | |
427 } | |
428 } | |
429 | |
430 if (NULL == target_services) | |
431 return NULL; | |
432 | |
433 // We don't trust that the IPC can work this early. | |
434 if (!target_services->GetState()->InitCalled()) | |
435 return NULL; | |
436 | |
437 DWORD original_error = ::GetLastError(); | |
438 | |
439 do { | |
440 if (NULL != thread_id && | |
441 !ValidParameter(thread_id, sizeof(*thread_id), WRITE)) | |
442 break; | |
443 | |
444 void* memory = GetGlobalIPCMemory(); | |
445 if (NULL == memory) | |
446 break; | |
447 | |
448 SharedMemIPCClient ipc(memory); | |
449 CrossCallReturn answer = {0}; | |
450 | |
451 // NOTE: we don't pass the thread_attributes through. This matches the | |
452 // approach in CreateProcess and in CreateThreadInternal(). | |
453 ResultCode code = CrossCall(ipc, IPC_CREATETHREAD_TAG, | |
454 reinterpret_cast<LPVOID>(stack_size), | |
455 reinterpret_cast<LPVOID>(start_address), | |
456 parameter, creation_flags, &answer); | |
457 if (SBOX_ALL_OK != code) | |
458 break; | |
459 | |
460 ::SetLastError(answer.win32_result); | |
461 if (ERROR_SUCCESS != answer.win32_result) { | |
462 return NULL; | |
463 } | |
464 | |
465 if (thread_id != NULL) { | |
466 *thread_id = ::GetThreadId(answer.handle); | |
467 } | |
468 return answer.handle; | |
469 } while (false); | |
470 | |
471 ::SetLastError(original_error); | |
472 return NULL; | |
473 } | |
474 | |
411 } // namespace sandbox | 475 } // namespace sandbox |
OLD | NEW |