diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-04 22:47:37 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-04 22:47:37 +0000 |
commit | 4bc818e1dc285910638203a0d94063a9e92e36b0 (patch) | |
tree | 871de4bc758b249b02246e0a449cd3c7960f76e3 /sandbox/src/interception.cc | |
parent | bd06fc48da4098267e99ae9e03313c3689100147 (diff) | |
download | chromium_src-4bc818e1dc285910638203a0d94063a9e92e36b0.zip chromium_src-4bc818e1dc285910638203a0d94063a9e92e36b0.tar.gz chromium_src-4bc818e1dc285910638203a0d94063a9e92e36b0.tar.bz2 |
Sandbox: Finish the interception manager support for x64.
Unit tests and integration tests run (as long as they don't
depend on IPCs), both regular and under SANDBOX_EXPORTS.
The interception agent is there, but no EAT interceptions yet.
BUG=27218
TEST=unit tests/ integration tests.
Review URL: http://codereview.chromium.org/565026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38143 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox/src/interception.cc')
-rw-r--r-- | sandbox/src/interception.cc | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/sandbox/src/interception.cc b/sandbox/src/interception.cc index 007c373..28edf2c 100644 --- a/sandbox/src/interception.cc +++ b/sandbox/src/interception.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,6 +13,7 @@ #include "base/pe_image.h" #include "base/scoped_ptr.h" #include "sandbox/src/interception_internal.h" +#include "sandbox/src/interceptors.h" #include "sandbox/src/sandbox.h" #include "sandbox/src/sandbox_utils.h" #include "sandbox/src/service_resolver.h" @@ -31,6 +32,9 @@ namespace sandbox { SANDBOX_INTERCEPT SharedMemory* g_interceptions; +// Table of the unpatched functions that we intercept. Mapped from the parent. +SANDBOX_INTERCEPT OriginalFunctions g_originals = { NULL }; + // Magic constant that identifies that this function is not to be patched. const char kUnloadDLLDummyFunction[] = "@"; @@ -45,9 +49,11 @@ InterceptionManager::~InterceptionManager() { bool InterceptionManager::AddToPatchedFunctions( const wchar_t* dll_name, const char* function_name, - InterceptionType interception_type, const void* replacement_code_address) { + InterceptionType interception_type, const void* replacement_code_address, + InterceptorId id) { InterceptionData function; function.type = interception_type; + function.id = id; function.dll = dll_name; function.function = function_name; function.interceptor_address = replacement_code_address; @@ -58,9 +64,11 @@ bool InterceptionManager::AddToPatchedFunctions( bool InterceptionManager::AddToPatchedFunctions( const wchar_t* dll_name, const char* function_name, - InterceptionType interception_type, const char* replacement_function_name) { + InterceptionType interception_type, const char* replacement_function_name, + InterceptorId id) { InterceptionData function; function.type = interception_type; + function.id = id; function.dll = dll_name; function.function = function_name; function.interceptor = replacement_function_name; @@ -103,9 +111,10 @@ bool InterceptionManager::InitializeInterceptions() { return false; g_interceptions = reinterpret_cast<SharedMemory*>(remote_buffer); - child_->TransferVariable("sandbox::g_interceptions", &g_interceptions, - sizeof(g_interceptions)); - return true; + ResultCode rc = child_->TransferVariable("g_interceptions", + &g_interceptions, + sizeof(g_interceptions)); + return (SBOX_ALL_OK == rc); } size_t InterceptionManager::GetBufferSize() const { @@ -261,6 +270,7 @@ bool InterceptionManager::SetupInterceptionInfo(const InterceptionData& data, function->record_bytes = required; function->type = data.type; + function->id = data.id; function->interceptor_address = data.interceptor_address; char* names = function->function; @@ -337,22 +347,16 @@ bool InterceptionManager::PatchNtdll(bool hot_patch_needed) { if (hot_patch_needed) { #if SANDBOX_EXPORTS // Make sure the functions are not excluded by the linker. +#if defined(_WIN64) + #pragma comment(linker, "/include:TargetNtMapViewOfSection64") + #pragma comment(linker, "/include:TargetNtUnmapViewOfSection64") +#else #pragma comment(linker, "/include:_TargetNtMapViewOfSection@44") #pragma comment(linker, "/include:_TargetNtUnmapViewOfSection@12") - - AddToPatchedFunctions(kNtdllName, kMapViewOfSectionName, - INTERCEPTION_SERVICE_CALL, - "_TargetNtMapViewOfSection@44"); - AddToPatchedFunctions(kNtdllName, kUnmapViewOfSectionName, - INTERCEPTION_SERVICE_CALL, - "_TargetNtUnmapViewOfSection@12"); -#else - AddToPatchedFunctions(kNtdllName, kMapViewOfSectionName, - INTERCEPTION_SERVICE_CALL, &TargetNtMapViewOfSection); - AddToPatchedFunctions(kNtdllName, kUnmapViewOfSectionName, - INTERCEPTION_SERVICE_CALL, - &TargetNtUnmapViewOfSection); #endif +#endif + ADD_NT_INTERCEPTION(NtMapViewOfSection, MAP_VIEW_OF_SECTION_ID, 44); + ADD_NT_INTERCEPTION(NtUnmapViewOfSection, UNMAP_VIEW_OF_SECTION_ID, 12); } size_t thunk_bytes = interceptions_.size() * sizeof(ThunkData) + @@ -370,6 +374,9 @@ bool InterceptionManager::PatchNtdll(bool hot_patch_needed) { dll_data.num_thunks = 0; dll_data.used_bytes = offsetof(DllInterceptionData, thunks); + // Reset all helpers for a new child. + memset(g_originals, 0, sizeof(g_originals)); + // this should write all the individual thunks to the child's memory if (!PatchClientFunctions(thunks, thunk_bytes, &dll_data)) return false; @@ -388,7 +395,10 @@ bool InterceptionManager::PatchNtdll(bool hot_patch_needed) { ::VirtualProtectEx(child, thunks, thunk_bytes, PAGE_EXECUTE_READ, &old_protection); - return true; + ResultCode ret = child_->TransferVariable("g_originals", g_originals, + sizeof(g_originals)); + + return SBOX_ALL_OK == ret ? true : false; } bool InterceptionManager::PatchClientFunctions(DllInterceptionData* thunks, @@ -468,6 +478,9 @@ bool InterceptionManager::PatchClientFunctions(DllInterceptionData* thunks, if (!NT_SUCCESS(ret)) break; + DCHECK(!g_originals[it->id]); + g_originals[it->id] = &thunks->thunks[dll_data->num_thunks]; + dll_data->num_thunks++; dll_data->used_bytes += sizeof(ThunkData); } |