diff options
author | tonyg <tonyg@chromium.org> | 2014-08-26 17:14:13 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-27 00:15:09 +0000 |
commit | cf244d180857d5df17b96734e976631024526930 (patch) | |
tree | a6205ffcd8faebedc54e8ffd2abb0e3b08c581d1 /chrome/app/close_handle_hook_win.cc | |
parent | f712d106692d782f2a590a8e752f720ad76ee608 (diff) | |
download | chromium_src-cf244d180857d5df17b96734e976631024526930.zip chromium_src-cf244d180857d5df17b96734e976631024526930.tar.gz chromium_src-cf244d180857d5df17b96734e976631024526930.tar.bz2 |
Revert of Improve the ScopedHandle verifier. (patchset #1 of https://codereview.chromium.org/506013004/)
Reason for revert:
All windows perf bots (official builds) crashing.
http://build.chromium.org/p/chromium.perf/builders/Win%20Builder/builds/73062/steps/generate_telemetry_profiles/logs/stdio
ChildEBP RetAddr
0022f7c0 6a3ffa19 chrome_69c90000!base::debug::BreakDebugger+0x10
0022f830 6a400622 chrome_69c90000!CheckIsChromeSxSProcess+0x26
0022f834 6a400d52 chrome_69c90000!InstallUtil::IsChromeSxSProcess+0x16
0022f83c 6a400c29 chrome_69c90000!BrowserDistribution::GetSpecificDistribution+0x3b
0022f844 6a3fe166 chrome_69c90000!BrowserDistribution::GetDistribution+0x7
0022f930 6a3fe11d chrome_69c90000!`anonymous namespace'::GetChromeChannelInternal+0x2c
0022f948 6a092c6c chrome_69c90000!GoogleUpdateSettings::GetChromeChannel+0x21
0022f9b4 6a08f70f chrome_69c90000!chrome::VersionInfo::GetChannel+0x60
0022f9b8 6a08f65a chrome_69c90000!`anonymous namespace'::UseHooks+0x5
0022f9dc 6a08eb5a chrome_69c90000!InstallCloseHandleHooks+0x15
0022fa20 00fb7623 chrome_69c90000!ChromeMain+0x3e
0022fab0 00fb7026 chrome!MainDllLoader::Launch+0x15f
0022faf4 00fd936a chrome!wWinMain+0x5a
0022fb40 766e338a chrome!__tmainCRTStartup+0xfd
WARNING: Stack unwind information not available. Following frames may be wrong.
0022fb4c 76f99f72 kernel32!BaseThreadInitThunk+0x12
0022fb8c 76f99f45 ntdll!RtlInitializeExceptionChain+0x63
0022fba4 00000000 ntdll!RtlInitializeExceptionChain+0x36
Original issue's description:
> Improve the ScopedHandle verifier.
>
> 1. Automate the selection of the proper channel to enable the verifier.
> Now the code is enabled at runtime.
>
> 2. Switch to a hash_map to track handles.
>
> 3. Intercept CloseHandle to detect the code that is closing handles owned
> by ScopedHandles. The initial implementation only covers chrome.exe/dll,
> but the plan is to extend that in the future to all modules loaded in the
> process.
>
> BUG=362176
> R=cpu@chromium.org
> R=sky@chromium.org
>
> See https://codereview.chromium.org/490043002/ for the actual review.
>
> TBR=cpu@chromium.org
> TBR=sky@chromium.org
>
> Committed: https://chromium.googlesource.com/chromium/src/+/c928d0383db43f2f4baf8f9b24ed7454bf7eda64
TBR=cpu@chromium.org,sky@chromium.org,rvargas@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=362176
Review URL: https://codereview.chromium.org/507893002
Cr-Commit-Position: refs/heads/master@{#292047}
Diffstat (limited to 'chrome/app/close_handle_hook_win.cc')
-rw-r--r-- | chrome/app/close_handle_hook_win.cc | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/chrome/app/close_handle_hook_win.cc b/chrome/app/close_handle_hook_win.cc deleted file mode 100644 index ca0b01e..0000000 --- a/chrome/app/close_handle_hook_win.cc +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2014 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. - -#include "chrome/app/close_handle_hook_win.h" - -#include <Windows.h> - -#include <vector> - -#include "base/files/file_path.h" -#include "base/lazy_instance.h" -#include "base/strings/string16.h" -#include "base/win/iat_patch_function.h" -#include "base/win/scoped_handle.h" -#include "chrome/common/chrome_version_info.h" - -namespace { - -typedef BOOL (WINAPI* CloseHandleType) (HANDLE handle); -CloseHandleType g_close_function = NULL; - -// The entry point for CloseHandle interception. This function notifies the -// verifier about the handle that is being closed, and calls the original -// function. -BOOL WINAPI CloseHandleHook(HANDLE handle) { - base::win::OnHandleBeingClosed(handle); - return g_close_function(handle); -} - -// Keeps track of all the hooks needed to intercept CloseHandle. -class CloseHandleHooks { - public: - CloseHandleHooks() {} - ~CloseHandleHooks() {} - - void AddIATPatch(const base::string16& module); - void Unpatch(); - - private: - std::vector<base::win::IATPatchFunction*> hooks_; - DISALLOW_COPY_AND_ASSIGN(CloseHandleHooks); -}; -base::LazyInstance<CloseHandleHooks> g_hooks = LAZY_INSTANCE_INITIALIZER; - -void CloseHandleHooks::AddIATPatch(const base::string16& module) { - if (module.empty()) - return; - - base::win::IATPatchFunction* patch = new base::win::IATPatchFunction; - patch->Patch(module.c_str(), "kernel32.dll", "CloseHandle", CloseHandleHook); - hooks_.push_back(patch); - if (!g_close_function) { - // Things are probably messed up if each intercepted function points to - // a different place, but we need only one function to call. - g_close_function = - reinterpret_cast<CloseHandleType>(patch->original_function()); - } -} - -void CloseHandleHooks::Unpatch() { - for (std::vector<base::win::IATPatchFunction*>::iterator it = hooks_.begin(); - it != hooks_.end(); ++it) { - (*it)->Unpatch(); - } -} - -bool UseHooks() { - chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); - if (channel == chrome::VersionInfo::CHANNEL_CANARY || - channel == chrome::VersionInfo::CHANNEL_DEV) { - return true; - } - - return false; -} - -base::string16 GetModuleName(HMODULE module) { - base::string16 name; - if (!module) - return name; - wchar_t buffer[MAX_PATH]; - int rv = GetModuleFileName(module, buffer, MAX_PATH); - if (rv == MAX_PATH) - return name; - - buffer[MAX_PATH - 1] = L'\0'; - name.assign(buffer); - base::FilePath path(name); - return path.BaseName().AsUTF16Unsafe(); -} - -HMODULE GetChromeDLLModule() { - HMODULE module; - if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | - GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - reinterpret_cast<wchar_t*>(&GetChromeDLLModule), - &module)) { - return NULL; - } - return module; -} - -} // namespace - -void InstallCloseHandleHooks() { - if (!UseHooks()) - return; - - base::win::EnableHandleVerifier(); - CloseHandleHooks* hooks = g_hooks.Pointer(); - hooks->AddIATPatch(L"chrome.exe"); - hooks->AddIATPatch(GetModuleName(GetChromeDLLModule())); -} - -void RemoveCloseHandleHooks() { - g_hooks.Get().Unpatch(); -} |