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 <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 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, |
| 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 |
OLD | NEW |