OLD | NEW |
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 <process.h> | 7 #include <process.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "sandbox/win/src/crosscall_client.h" | 10 #include "sandbox/win/src/crosscall_client.h" |
11 #include "sandbox/win/src/handle_closer_agent.h" | 11 #include "sandbox/win/src/handle_closer_agent.h" |
12 #include "sandbox/win/src/handle_interception.h" | 12 #include "sandbox/win/src/handle_interception.h" |
13 #include "sandbox/win/src/ipc_tags.h" | 13 #include "sandbox/win/src/ipc_tags.h" |
14 #include "sandbox/win/src/process_mitigations.h" | |
15 #include "sandbox/win/src/restricted_token_utils.h" | 14 #include "sandbox/win/src/restricted_token_utils.h" |
16 #include "sandbox/win/src/sandbox.h" | 15 #include "sandbox/win/src/sandbox.h" |
17 #include "sandbox/win/src/sandbox_types.h" | 16 #include "sandbox/win/src/sandbox_types.h" |
18 #include "sandbox/win/src/sharedmem_ipc_client.h" | 17 #include "sandbox/win/src/sharedmem_ipc_client.h" |
19 #include "sandbox/win/src/sandbox_nt_util.h" | 18 #include "sandbox/win/src/sandbox_nt_util.h" |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 // Flushing a cached key is triggered by just opening the key and closing the | 22 // Flushing a cached key is triggered by just opening the key and closing the |
24 // resulting handle. RegDisablePredefinedCache() is the documented way to flush | 23 // resulting handle. RegDisablePredefinedCache() is the documented way to flush |
(...skipping 30 matching lines...) Expand all Loading... |
55 | 54 |
56 return true; | 55 return true; |
57 } | 56 } |
58 | 57 |
59 } // namespace | 58 } // namespace |
60 | 59 |
61 namespace sandbox { | 60 namespace sandbox { |
62 | 61 |
63 SANDBOX_INTERCEPT IntegrityLevel g_shared_delayed_integrity_level = | 62 SANDBOX_INTERCEPT IntegrityLevel g_shared_delayed_integrity_level = |
64 INTEGRITY_LEVEL_LAST; | 63 INTEGRITY_LEVEL_LAST; |
65 SANDBOX_INTERCEPT MitigationFlags g_shared_delayed_mitigations = 0; | |
66 | 64 |
67 TargetServicesBase::TargetServicesBase() { | 65 TargetServicesBase::TargetServicesBase() { |
68 } | 66 } |
69 | 67 |
70 ResultCode TargetServicesBase::Init() { | 68 ResultCode TargetServicesBase::Init() { |
71 process_state_.SetInitCalled(); | 69 process_state_.SetInitCalled(); |
72 return SBOX_ALL_OK; | 70 return SBOX_ALL_OK; |
73 } | 71 } |
74 | 72 |
75 // Failure here is a breach of security so the process is terminated. | 73 // Failure here is a breach of security so the process is terminated. |
76 void TargetServicesBase::LowerToken() { | 74 void TargetServicesBase::LowerToken() { |
77 if (ERROR_SUCCESS != | 75 if (ERROR_SUCCESS != |
78 SetProcessIntegrityLevel(g_shared_delayed_integrity_level)) | 76 SetProcessIntegrityLevel(g_shared_delayed_integrity_level)) |
79 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_INTEGRITY); | 77 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_INTEGRITY); |
80 process_state_.SetRevertedToSelf(); | 78 process_state_.SetRevertedToSelf(); |
81 // If the client code as called RegOpenKey, advapi32.dll has cached some | 79 // If the client code as called RegOpenKey, advapi32.dll has cached some |
82 // handles. The following code gets rid of them. | 80 // handles. The following code gets rid of them. |
83 if (!::RevertToSelf()) | 81 if (!::RevertToSelf()) |
84 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_DROPTOKEN); | 82 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_DROPTOKEN); |
85 if (!FlushCachedRegHandles()) | 83 if (!FlushCachedRegHandles()) |
86 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_FLUSHANDLES); | 84 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_FLUSHANDLES); |
87 if (ERROR_SUCCESS != ::RegDisablePredefinedCache()) | 85 if (ERROR_SUCCESS != ::RegDisablePredefinedCache()) |
88 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_CACHEDISABLE); | 86 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_CACHEDISABLE); |
89 if (!CloseOpenHandles()) | 87 if (!CloseOpenHandles()) |
90 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_CLOSEHANDLES); | 88 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_CLOSEHANDLES); |
91 // Enabling mitigations must happen last otherwise handle closing breaks | |
92 if (g_shared_delayed_mitigations && | |
93 !ApplyProcessMitigationsToCurrentProcess(g_shared_delayed_mitigations)) | |
94 ::TerminateProcess(::GetCurrentProcess(), SBOX_FATAL_MITIGATION); | |
95 } | 89 } |
96 | 90 |
97 ProcessState* TargetServicesBase::GetState() { | 91 ProcessState* TargetServicesBase::GetState() { |
98 return &process_state_; | 92 return &process_state_; |
99 } | 93 } |
100 | 94 |
101 TargetServicesBase* TargetServicesBase::GetInstance() { | 95 TargetServicesBase* TargetServicesBase::GetInstance() { |
102 static TargetServicesBase instance; | 96 static TargetServicesBase instance; |
103 return &instance; | 97 return &instance; |
104 } | 98 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 ResultCode TargetServicesBase::DuplicateHandle(HANDLE source_handle, | 179 ResultCode TargetServicesBase::DuplicateHandle(HANDLE source_handle, |
186 DWORD target_process_id, | 180 DWORD target_process_id, |
187 HANDLE* target_handle, | 181 HANDLE* target_handle, |
188 DWORD desired_access, | 182 DWORD desired_access, |
189 DWORD options) { | 183 DWORD options) { |
190 return sandbox::DuplicateHandleProxy(source_handle, target_process_id, | 184 return sandbox::DuplicateHandleProxy(source_handle, target_process_id, |
191 target_handle, desired_access, options); | 185 target_handle, desired_access, options); |
192 } | 186 } |
193 | 187 |
194 } // namespace sandbox | 188 } // namespace sandbox |
OLD | NEW |