Commit 496cb36c authored by Greg Thompson's avatar Greg Thompson Committed by Commit Bot

Launch external protocol handlers with C:\Windows\System32 as their CWD.

This mitigates a potential DLL search order hijack for processes that
don't implement their own mitigation.

BUG=1126506

Change-Id: I26d88354c6b4f8ce42eab0a3ba49eca6313611fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410030Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarEric Lawrence [MSFT] <ericlaw@microsoft.com>
Commit-Queue: Greg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807014}
parent ac2fc982
...@@ -109,16 +109,19 @@ void OpenExternalOnWorkerThread(const GURL& url) { ...@@ -109,16 +109,19 @@ void OpenExternalOnWorkerThread(const GURL& url) {
if (escaped_url.length() > kMaxUrlLength) if (escaped_url.length() > kMaxUrlLength)
return; return;
// Specify the user's %TMP% directory as the CWD so that any new proc spawned // Specify %windir%\system32 as the CWD so that any new proc spawned does not
// does not inherit this proc's CWD. Without this, uninstalls may be broken by // inherit this proc's CWD. Without this, uninstalls may be broken by a
// a long-lived child proc that holds a handle to the browser's version // long-lived child proc that holds a handle to the browser's version
// directory. // directory (the browser's CWD). A process's CWD is in the standard list of
base::FilePath temp_dir; // directories to search when loading a DLL, and precedes the system directory
base::PathService::Get(base::DIR_TEMP, &temp_dir); // when safe DLL search mode is disabled (not the default). Setting the CWD to
if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(NULL, "open", // the system directory is a nice way to mitigate a potential DLL search order
escaped_url.c_str(), NULL, // hijack for processes that don't implement their own mitigation.
temp_dir.AsUTF8Unsafe().c_str(), base::FilePath system_dir;
SW_SHOWNORMAL)) <= 32) { base::PathService::Get(base::DIR_SYSTEM, &system_dir);
if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(
NULL, "open", escaped_url.c_str(), NULL,
system_dir.AsUTF8Unsafe().c_str(), SW_SHOWNORMAL)) <= 32) {
// On failure, it may be good to display a message to the user. // On failure, it may be good to display a message to the user.
// https://crbug.com/727913 // https://crbug.com/727913
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment