Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Issue 2744043003: Use LoadLibraryExW if applicable in LoadNativeLibrary on Windows (Closed)

Created:
3 years, 9 months ago by chengx
Modified:
3 years, 9 months ago
Reviewers:
xhwang, Ilya Sherman, dcheng
CC:
chromium-reviews, vmpstr+watch_chromium.org, brucedawson
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Use LoadLibraryExW if applicable in LoadNativeLibrary on Windows In the current LoadNativeLibrary implementation, LoadLibraryW Windows API is used to load a DLL. To be able to find dependencies in the same folder, SetCurrentDirectory() is needed to search for the DLL directory, and sets it back after the DLL is loaded. This is required because on Windows, it'll search for dependencies in a search list, which includes the system "current directory", but not the DLL directory. However, SetCurrentDirectory() can be potentially problematic. It is not recommended in a multithreaded application, and could pose a security risk as "If an attacker gains control of one of the directories on the DLL search path, it can place a malicious copy of the DLL in that directory. This is sometimes called a DLL preloading attack or a binary planting attack." The right thing to do is to use LoadLibraryExW, where we can specify additional flags like LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR to enable searching in the DLL directory. With this, we can eliminate the need of doing SetCurrentDirectory(). Using these additional flags requires KB2533623 to be installed and the method is "To determine whether the flags are available, use GetProcAddress to get the address of the AddDllDirectory, RemoveDllDirectory, or SetDefaultDllDirectories function. If GetProcAddress succeeds, the LOAD_LIBRARY_SEARCH_* flags can be used with LoadLibraryEx." Therefore, we can dynamically call LoadLibraryExW if the API and the flags are available. If not or its call fails, we should use the LoadLibraryW API. This CL also adds UMA histogram to record the calling status of both LoadLibraryExW and LoadLibraryW APIs. Besides, this CL removes the LoadNativeLibraryDynamically method as it is not used anywhere. Running Chromium built with this CL locally shows that LoadLibraryExW call were successful for kernel32.dll and widevinecdm.dll (which caused crbug.com/700208), but failed when loading MDMRegistration.dll. LoadLibraryW succeeds in loading MDMRegistration.dll though. BUG=700503, 700208 Review-Url: https://codereview.chromium.org/2744043003 Cr-Commit-Position: refs/heads/master@{#457359} Committed: https://chromium.googlesource.com/chromium/src/+/5946c9233dc393f2e3e275323e66659fe5fb35cd

Patch Set 1 #

Patch Set 2 : Add UMA_histogram #

Total comments: 34

Patch Set 3 : Address comments. #

Total comments: 6

Patch Set 4 : Remove LoadNativeLibraryDynamically, update LoadNativeLibraryWithOptions, address comments. #

Patch Set 5 : Add a wrapper method for UMA. #

Total comments: 22

Patch Set 6 : Refactor code, address comments. #

Total comments: 4

Patch Set 7 : Better variable names, fix nits. #

Patch Set 8 : Add TODO for removing fallback. #

Total comments: 2

Patch Set 9 : Better variable name. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+121 lines, -27 lines) Patch
M base/native_library.h View 1 2 3 1 chunk +0 lines, -10 lines 0 comments Download
M base/native_library_win.cc View 1 2 3 4 5 6 7 8 4 chunks +104 lines, -17 lines 0 comments Download
M tools/metrics/histograms/histograms.xml View 1 2 3 4 5 2 chunks +17 lines, -0 lines 0 comments Download

Messages

Total messages: 104 (80 generated)
chengx
PTAL~
3 years, 9 months ago (2017-03-13 20:12:46 UTC) #30
xhwang
Thank you sooo much for working on this! To test this manually, you can check ...
3 years, 9 months ago (2017-03-13 20:47:09 UTC) #31
chengx
I have addressed all the comments except that if we want to remove LoadNativeLibraryDynamically() and ...
3 years, 9 months ago (2017-03-13 22:20:23 UTC) #36
xhwang
Thanks! I have a few more comments. https://codereview.chromium.org/2744043003/diff/100001/base/native_library_win.cc File base/native_library_win.cc (right): https://codereview.chromium.org/2744043003/diff/100001/base/native_library_win.cc#newcode81 base/native_library_win.cc:81: NativeLibrary LoadNativeLibraryWithOptions(const ...
3 years, 9 months ago (2017-03-14 00:14:32 UTC) #43
chengx
PTAL~ https://codereview.chromium.org/2744043003/diff/100001/base/native_library_win.cc File base/native_library_win.cc (right): https://codereview.chromium.org/2744043003/diff/100001/base/native_library_win.cc#newcode81 base/native_library_win.cc:81: NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path, On 2017/03/14 00:14:31, xhwang_slow ...
3 years, 9 months ago (2017-03-14 02:44:41 UTC) #49
chengx
PTAL~ isherman@ owner for tools/metrics/histograms/histograms.xml dcheng@ owner for //base. Thank you! P.S. Linux build bots ...
3 years, 9 months ago (2017-03-14 18:40:14 UTC) #57
Ilya Sherman
Metrics LGTM % nits: https://codereview.chromium.org/2744043003/diff/180001/base/native_library_win.cc File base/native_library_win.cc (right): https://codereview.chromium.org/2744043003/diff/180001/base/native_library_win.cc#newcode21 base/native_library_win.cc:21: enum LoadLibraryResult { nit: Please ...
3 years, 9 months ago (2017-03-14 18:42:28 UTC) #58
xhwang
looking good! I only have a few nits. Thanks! https://codereview.chromium.org/2744043003/diff/180001/base/native_library_win.cc File base/native_library_win.cc (right): https://codereview.chromium.org/2744043003/diff/180001/base/native_library_win.cc#newcode41 base/native_library_win.cc:41: ...
3 years, 9 months ago (2017-03-14 21:48:26 UTC) #64
chengx
Hi xhwang@, comments all addressed in the new patch set. PTAL, thanks! https://codereview.chromium.org/2744043003/diff/180001/base/native_library_win.cc File base/native_library_win.cc ...
3 years, 9 months ago (2017-03-14 23:08:30 UTC) #67
xhwang
Did you manually test this against crbug/700208? Otherwise LGTM % nit Thank you again for ...
3 years, 9 months ago (2017-03-14 23:17:42 UTC) #68
dcheng
Do we need to use the fallback path if we can use LoadLibraryExW? It seems ...
3 years, 9 months ago (2017-03-15 09:33:49 UTC) #71
chengx
On 2017/03/15 09:33:49, dcheng wrote: > Do we need to use the fallback path if ...
3 years, 9 months ago (2017-03-15 17:50:31 UTC) #74
chengx
Comments addressed in the new patch set. https://codereview.chromium.org/2744043003/diff/200001/base/native_library_win.cc File base/native_library_win.cc (right): https://codereview.chromium.org/2744043003/diff/200001/base/native_library_win.cc#newcode18 base/native_library_win.cc:18: typedef HMODULE(WINAPI* ...
3 years, 9 months ago (2017-03-15 18:59:25 UTC) #77
dcheng
On 2017/03/15 17:50:31, chengx wrote: > On 2017/03/15 09:33:49, dcheng wrote: > > Do we ...
3 years, 9 months ago (2017-03-15 19:57:07 UTC) #78
xhwang
On 2017/03/15 19:57:07, dcheng wrote: > On 2017/03/15 17:50:31, chengx wrote: > > On 2017/03/15 ...
3 years, 9 months ago (2017-03-15 19:59:06 UTC) #79
xhwang
On 2017/03/15 19:59:06, xhwang_slow wrote: > On 2017/03/15 19:57:07, dcheng wrote: > > On 2017/03/15 ...
3 years, 9 months ago (2017-03-15 19:59:38 UTC) #80
chengx
On 2017/03/15 19:59:38, xhwang_slow wrote: > On 2017/03/15 19:59:06, xhwang_slow wrote: > > On 2017/03/15 ...
3 years, 9 months ago (2017-03-15 20:33:03 UTC) #86
xhwang
Thanks! Have you verified whether UMA reporting is working as expected? https://codereview.chromium.org/2744043003/diff/260001/base/native_library_win.cc File base/native_library_win.cc (right): ...
3 years, 9 months ago (2017-03-15 21:04:06 UTC) #87
chengx
PTAL~ On 2017/03/15 21:04:06, xhwang_slow wrote: > Thanks! > > Have you verified whether UMA ...
3 years, 9 months ago (2017-03-15 23:52:30 UTC) #93
xhwang
On 2017/03/15 23:52:30, chengx wrote: > PTAL~ > > On 2017/03/15 21:04:06, xhwang_slow wrote: > ...
3 years, 9 months ago (2017-03-16 00:20:00 UTC) #94
chengx
On 2017/03/16 00:20:00, xhwang_slow wrote: > When LoadLibraryW successfully loads MDMRegistration.dll, do you see anything ...
3 years, 9 months ago (2017-03-16 00:52:38 UTC) #95
dcheng
lgtm
3 years, 9 months ago (2017-03-16 05:42:12 UTC) #98
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2744043003/280001
3 years, 9 months ago (2017-03-16 05:45:21 UTC) #101
commit-bot: I haz the power
3 years, 9 months ago (2017-03-16 05:50:32 UTC) #104
Message was sent while issue was closed.
Committed patchset #9 (id:280001) as
https://chromium.googlesource.com/chromium/src/+/5946c9233dc393f2e3e275323e66...

Powered by Google App Engine
This is Rietveld 408576698