summaryrefslogtreecommitdiffstats
path: root/security/sandbox/chromium-shim/patches/with_update/replace_ScopedNativeLibrary_in_ApplyMitigationsToCurrentThread.patch
blob: 47418009d6038be48db2c219cea533914de8fc16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# HG changeset patch
# User Toshihito Kikuchi <tkikuchi@mozilla.com>
# Date 1589672273 25200
#      Sat May 16 16:37:53 2020 -0700
# Node ID c14ef8304c36fdc2570b77b63b36114cff2d070d
# Parent  90b5f63770f52fab163adaed1d5812b2887b335a
Use GetModuleHandle/GetProcAddress in ApplyMitigationsToCurrentThread. r=bobowen

This patch removes the use of base::ScopedNativeLibrary from
sandbox::ApplyMitigationsToCurrentThread because to avoid
new dependencies.

diff --git a/security/sandbox/chromium/sandbox/win/src/process_mitigations.cc b/security/sandbox/chromium/sandbox/win/src/process_mitigations.cc
--- a/security/sandbox/chromium/sandbox/win/src/process_mitigations.cc
+++ b/security/sandbox/chromium/sandbox/win/src/process_mitigations.cc
@@ -5,18 +5,16 @@
 #include "sandbox/win/src/process_mitigations.h"
 
 #include <stddef.h>
 #include <windows.h>
 #include <wow64apiset.h>
 
 #include <algorithm>
 
-#include "base/files/file_path.h"
-#include "base/scoped_native_library.h"
 #include "base/win/windows_version.h"
 #include "build/build_config.h"
 #include "sandbox/win/src/nt_internals.h"
 #include "sandbox/win/src/restricted_token_utils.h"
 #include "sandbox/win/src/sandbox_rand.h"
 #include "sandbox/win/src/win_utils.h"
 
 namespace {
@@ -321,22 +319,19 @@ bool ApplyMitigationsToCurrentThread(Mit
     return true;
 
   // Enable dynamic code per-thread policies.
   if (flags & MITIGATION_DYNAMIC_CODE_OPT_OUT_THIS_THREAD) {
     DWORD thread_policy = THREAD_DYNAMIC_CODE_ALLOW;
 
     // NOTE: SetThreadInformation API only exists on >= Win8.  Dynamically
     //       get function handle.
-    base::ScopedNativeLibrary dll(base::FilePath(L"kernel32.dll"));
-    if (!dll.is_valid())
-      return false;
     SetThreadInformationFunction set_thread_info_function =
-        reinterpret_cast<SetThreadInformationFunction>(
-            dll.GetFunctionPointer("SetThreadInformation"));
+        reinterpret_cast<SetThreadInformationFunction>(::GetProcAddress(
+            ::GetModuleHandleA("kernel32.dll"), "SetThreadInformation"));
     if (!set_thread_info_function)
       return false;
 
     // NOTE: Must use the pseudo-handle here, a thread HANDLE won't work.
     if (!set_thread_info_function(::GetCurrentThread(), ThreadDynamicCodePolicy,
                                   &thread_policy, sizeof(thread_policy))) {
       return false;
     }