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

Side by Side Diff: sandbox/win/src/target_services.cc

Issue 1324523008: Windows sbox: Warmup locales before sandbox lockdown (and tests) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add explicit checks of returned values from Win32 calls Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sandbox/win/src/sandbox_types.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sandbox/win/src/target_services.h" 5 #include "sandbox/win/src/target_services.h"
6 6
7 #include <new> 7 #include <new>
8 8
9 #include <process.h> 9 #include <process.h>
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 if (sandbox::HandleCloserAgent::NeedsHandlesClosed()) { 52 if (sandbox::HandleCloserAgent::NeedsHandlesClosed()) {
53 sandbox::HandleCloserAgent handle_closer; 53 sandbox::HandleCloserAgent handle_closer;
54 handle_closer.InitializeHandlesToClose(is_csrss_connected); 54 handle_closer.InitializeHandlesToClose(is_csrss_connected);
55 if (!handle_closer.CloseHandles()) 55 if (!handle_closer.CloseHandles())
56 return false; 56 return false;
57 } 57 }
58 58
59 return true; 59 return true;
60 } 60 }
61 61
62 // Warm up language subsystems before the sandbox is turned on.
63 // Tested on Win8.1 x64:
64 // This needs to happen after RevertToSelf() is called, because (at least) in
65 // the case of GetUserDefaultLCID() it checks the TEB to see if the process is
66 // impersonating (TEB!IsImpersonating). If it is, the cached locale information
67 // is not used, nor is it set. Therefore, calls after RevertToSelf() will not
68 // have warmed-up values to use.
69 bool WarmupWindowsLocales() {
70 // NOTE(liamjm): When last checked (Win 8.1 x64) it wasn't necessary to
71 // warmup all of these functions, but let's not assume that.
72 ::GetUserDefaultLangID();
73 ::GetUserDefaultLCID();
74 wchar_t localeName[LOCALE_NAME_MAX_LENGTH] = { 0 };
75 return (0 != ::GetUserDefaultLocaleName(
76 localeName, LOCALE_NAME_MAX_LENGTH * sizeof(wchar_t)));
77 }
62 78
63 // Used as storage for g_target_services, because other allocation facilities 79 // Used as storage for g_target_services, because other allocation facilities
64 // are not available early. We can't use a regular function static because on 80 // are not available early. We can't use a regular function static because on
65 // VS2015, because the CRT tries to acquire a lock to guard initialization, but 81 // VS2015, because the CRT tries to acquire a lock to guard initialization, but
66 // this code runs before the CRT is initialized. 82 // this code runs before the CRT is initialized.
67 char g_target_services_memory[sizeof(sandbox::TargetServicesBase)]; 83 char g_target_services_memory[sizeof(sandbox::TargetServicesBase)];
68 sandbox::TargetServicesBase* g_target_services = nullptr; 84 sandbox::TargetServicesBase* g_target_services = nullptr;
69 85
70 } // namespace 86 } // namespace
71 87
(...skipping 18 matching lines...) Expand all
90 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_INTEGRITY); 106 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_INTEGRITY);
91 process_state_.SetRevertedToSelf(); 107 process_state_.SetRevertedToSelf();
92 // If the client code as called RegOpenKey, advapi32.dll has cached some 108 // If the client code as called RegOpenKey, advapi32.dll has cached some
93 // handles. The following code gets rid of them. 109 // handles. The following code gets rid of them.
94 if (!::RevertToSelf()) 110 if (!::RevertToSelf())
95 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_DROPTOKEN); 111 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_DROPTOKEN);
96 if (!FlushCachedRegHandles()) 112 if (!FlushCachedRegHandles())
97 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_FLUSHANDLES); 113 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_FLUSHANDLES);
98 if (ERROR_SUCCESS != ::RegDisablePredefinedCache()) 114 if (ERROR_SUCCESS != ::RegDisablePredefinedCache())
99 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_CACHEDISABLE); 115 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_CACHEDISABLE);
116 if (!WarmupWindowsLocales())
117 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_WARMUP);
100 bool is_csrss_connected = true; 118 bool is_csrss_connected = true;
101 if (!CloseOpenHandles(&is_csrss_connected)) 119 if (!CloseOpenHandles(&is_csrss_connected))
102 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_CLOSEHANDLES); 120 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_CLOSEHANDLES);
103 process_state_.SetCsrssConnected(is_csrss_connected); 121 process_state_.SetCsrssConnected(is_csrss_connected);
104 // Enabling mitigations must happen last otherwise handle closing breaks 122 // Enabling mitigations must happen last otherwise handle closing breaks
105 if (g_shared_delayed_mitigations && 123 if (g_shared_delayed_mitigations &&
106 !ApplyProcessMitigationsToCurrentProcess(g_shared_delayed_mitigations)) 124 !ApplyProcessMitigationsToCurrentProcess(g_shared_delayed_mitigations))
107 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_MITIGATION); 125 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_MITIGATION);
108 } 126 }
109 127
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 ResultCode TargetServicesBase::DuplicateHandle(HANDLE source_handle, 230 ResultCode TargetServicesBase::DuplicateHandle(HANDLE source_handle,
213 DWORD target_process_id, 231 DWORD target_process_id,
214 HANDLE* target_handle, 232 HANDLE* target_handle,
215 DWORD desired_access, 233 DWORD desired_access,
216 DWORD options) { 234 DWORD options) {
217 return sandbox::DuplicateHandleProxy(source_handle, target_process_id, 235 return sandbox::DuplicateHandleProxy(source_handle, target_process_id,
218 target_handle, desired_access, options); 236 target_handle, desired_access, options);
219 } 237 }
220 238
221 } // namespace sandbox 239 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/sandbox_types.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698