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

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

Issue 2726733003: CSRSS lockdown: destroy CSRSS heap (Closed)
Patch Set: refactor heap code to heap_helper, add some explicit tests of these heap_helper functions Created 3 years, 9 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
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 #include <stdint.h> 10 #include <stdint.h>
11 11
12 #include "base/win/windows_version.h" 12 #include "base/win/windows_version.h"
13 #include "sandbox/win/src/crosscall_client.h" 13 #include "sandbox/win/src/crosscall_client.h"
14 #include "sandbox/win/src/handle_closer_agent.h" 14 #include "sandbox/win/src/handle_closer_agent.h"
15 #include "sandbox/win/src/heap_helper.h"
15 #include "sandbox/win/src/ipc_tags.h" 16 #include "sandbox/win/src/ipc_tags.h"
16 #include "sandbox/win/src/process_mitigations.h" 17 #include "sandbox/win/src/process_mitigations.h"
17 #include "sandbox/win/src/restricted_token_utils.h" 18 #include "sandbox/win/src/restricted_token_utils.h"
18 #include "sandbox/win/src/sandbox.h" 19 #include "sandbox/win/src/sandbox.h"
19 #include "sandbox/win/src/sandbox_nt_util.h" 20 #include "sandbox/win/src/sandbox_nt_util.h"
20 #include "sandbox/win/src/sandbox_types.h" 21 #include "sandbox/win/src/sandbox_types.h"
21 #include "sandbox/win/src/sharedmem_ipc_client.h" 22 #include "sandbox/win/src/sharedmem_ipc_client.h"
22 23
23 namespace { 24 namespace {
24 25
(...skipping 13 matching lines...) Expand all
38 // that were made during calls to RegOpenkey and RegOpenKeyEx if it is called 39 // that were made during calls to RegOpenkey and RegOpenKeyEx if it is called
39 // with a more restrictive token. Returns true if the flushing is succesful 40 // with a more restrictive token. Returns true if the flushing is succesful
40 // although this behavior is undocumented and there is no guarantee that in 41 // although this behavior is undocumented and there is no guarantee that in
41 // fact this will happen in future versions of windows. 42 // fact this will happen in future versions of windows.
42 bool FlushCachedRegHandles() { 43 bool FlushCachedRegHandles() {
43 return (FlushRegKey(HKEY_LOCAL_MACHINE) && 44 return (FlushRegKey(HKEY_LOCAL_MACHINE) &&
44 FlushRegKey(HKEY_CLASSES_ROOT) && 45 FlushRegKey(HKEY_CLASSES_ROOT) &&
45 FlushRegKey(HKEY_USERS)); 46 FlushRegKey(HKEY_USERS));
46 } 47 }
47 48
49 // Cleans up this process if CSRSS will be disconnected, as this disconnection
50 // is not supported Windows behavior.
51 // Currently, this step requires closing a heap that this shared with csrss.exe.
52 // Closing the ALPC Port handle to csrss.exe leaves this heap in an invalid
53 // state. This causes problems if anyone enumerates the heap.
54 bool CsrssDisconnectCleanup() {
55 PVOID csr_port_heap = sandbox::FindCsrPortHeap();
Will Harris 2017/03/22 19:21:49 are we not already in sandbox namespace. hmm? stra
Will Harris 2017/03/22 19:21:49 implicit cast from HANDLE to PVOID - is this what
liamjm (20p) 2017/04/14 17:27:20 No. changed to HANDLE. Thanks.
liamjm (20p) 2017/04/14 17:27:20 Yeah... Just in an unnamed namespace at this poin
Will Harris 2017/05/01 18:33:15 yes it seems to make sense to move all these funct
56 if (nullptr == csr_port_heap) {
Will Harris 2017/03/22 19:21:49 !csr_port_heap
liamjm (20p) 2017/04/14 17:27:20 Done.
57 LOG(ERROR) << "Failed to find CSR Port heap handle" return false;
Will Harris 2017/03/22 19:21:49 win\src\target_services.cc(57): error C2143: synta
liamjm (20p) 2017/04/14 17:27:20 Done.
58 }
59 HeapDestroy(csr_port_heap);
60 return true;
61 }
62
48 // Checks if we have handle entries pending and runs the closer. 63 // Checks if we have handle entries pending and runs the closer.
49 // Updates is_csrss_connected based on which handle types are closed. 64 // Updates is_csrss_connected based on which handle types are closed.
50 bool CloseOpenHandles(bool* is_csrss_connected) { 65 bool CloseOpenHandles(bool* is_csrss_connected) {
51 if (sandbox::HandleCloserAgent::NeedsHandlesClosed()) { 66 if (sandbox::HandleCloserAgent::NeedsHandlesClosed()) {
52 sandbox::HandleCloserAgent handle_closer; 67 sandbox::HandleCloserAgent handle_closer;
53 handle_closer.InitializeHandlesToClose(is_csrss_connected); 68 handle_closer.InitializeHandlesToClose(is_csrss_connected);
69 if (!*is_csrss_connected) {
70 if (!CsrssDisconnectCleanup()) {
71 return false;
72 }
73 }
54 if (!handle_closer.CloseHandles()) 74 if (!handle_closer.CloseHandles())
55 return false; 75 return false;
56 } 76 }
57
58 return true; 77 return true;
59 } 78 }
60 79
61 // GetUserDefaultLocaleName is not available on WIN XP. So we'll 80 // GetUserDefaultLocaleName is not available on WIN XP. So we'll
62 // load it on-the-fly. 81 // load it on-the-fly.
63 const wchar_t kKernel32DllName[] = L"kernel32.dll"; 82 const wchar_t kKernel32DllName[] = L"kernel32.dll";
64 typedef decltype(GetUserDefaultLocaleName)* GetUserDefaultLocaleNameFunction; 83 typedef decltype(GetUserDefaultLocaleName)* GetUserDefaultLocaleNameFunction;
65 84
66 // Warm up language subsystems before the sandbox is turned on. 85 // Warm up language subsystems before the sandbox is turned on.
67 // Tested on Win8.1 x64: 86 // Tested on Win8.1 x64:
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 void ProcessState::SetRevertedToSelf() { 257 void ProcessState::SetRevertedToSelf() {
239 if (process_state_ < 3) 258 if (process_state_ < 3)
240 process_state_ = 3; 259 process_state_ = 3;
241 } 260 }
242 261
243 void ProcessState::SetCsrssConnected(bool csrss_connected) { 262 void ProcessState::SetCsrssConnected(bool csrss_connected) {
244 csrss_connected_ = csrss_connected; 263 csrss_connected_ = csrss_connected;
245 } 264 }
246 265
247 } // namespace sandbox 266 } // namespace sandbox
OLDNEW
« sandbox/win/src/lpc_policy_test.cc ('K') | « sandbox/win/src/lpc_policy_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698