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

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

Issue 31933005: Replace the CreateEvent/OpenEvent patches with their Nt counterparts like NtOpenEvent and NtCreateE… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « sandbox/win/src/sync_policy.h ('k') | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <string> 5 #include <string>
6 6
7 #include "sandbox/win/src/sync_policy.h" 7 #include "sandbox/win/src/sync_policy.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/stringprintf.h"
10 #include "sandbox/win/src/ipc_tags.h" 11 #include "sandbox/win/src/ipc_tags.h"
12 #include "sandbox/win/src/nt_internals.h"
11 #include "sandbox/win/src/policy_engine_opcodes.h" 13 #include "sandbox/win/src/policy_engine_opcodes.h"
12 #include "sandbox/win/src/policy_params.h" 14 #include "sandbox/win/src/policy_params.h"
13 #include "sandbox/win/src/sandbox_types.h" 15 #include "sandbox/win/src/sandbox_types.h"
14 #include "sandbox/win/src/sandbox_utils.h" 16 #include "sandbox/win/src/sandbox_utils.h"
17 #include "sandbox/win/src/sync_interception.h"
18 #include "sandbox/win/src/win_utils.h"
15 19
16 namespace sandbox { 20 namespace sandbox {
17 21
22 NTSTATUS GetBaseNamedObjectsDirectory(HANDLE* directory) {
23 static HANDLE base_named_objects_handle = NULL;
24 if (base_named_objects_handle) {
25 *directory = base_named_objects_handle;
26 return STATUS_SUCCESS;
27 }
28
29 NtOpenDirectoryObjectFunction NtOpenDirectoryObject = NULL;
30 ResolveNTFunctionPtr("NtOpenDirectoryObject", &NtOpenDirectoryObject);
31
32 DWORD session_id = 0;
33 ProcessIdToSessionId(::GetCurrentProcessId(), &session_id);
34
35 std::wstring base_named_objects_path =
36 base::StringPrintf(L"\\Sessions\\%d\\BaseNamedObjects", session_id);
37
38 UNICODE_STRING directory_name = {};
39 OBJECT_ATTRIBUTES object_attributes = {};
40 InitObjectAttribs(base_named_objects_path, OBJ_CASE_INSENSITIVE, NULL,
41 &object_attributes, &directory_name);
42 NTSTATUS status = NtOpenDirectoryObject(&base_named_objects_handle,
43 DIRECTORY_ALL_ACCESS,
44 &object_attributes);
45 if (status == STATUS_SUCCESS)
46 *directory = base_named_objects_handle;
47 return status;
48 }
49
18 bool SyncPolicy::GenerateRules(const wchar_t* name, 50 bool SyncPolicy::GenerateRules(const wchar_t* name,
19 TargetPolicy::Semantics semantics, 51 TargetPolicy::Semantics semantics,
20 LowLevelPolicy* policy) { 52 LowLevelPolicy* policy) {
21 std::wstring mod_name(name); 53 std::wstring mod_name(name);
22 if (mod_name.empty()) { 54 if (mod_name.empty()) {
23 return false; 55 return false;
24 } 56 }
25 57
26 if (TargetPolicy::EVENTS_ALLOW_ANY != semantics && 58 if (TargetPolicy::EVENTS_ALLOW_ANY != semantics &&
27 TargetPolicy::EVENTS_ALLOW_READONLY != semantics) { 59 TargetPolicy::EVENTS_ALLOW_READONLY != semantics) {
(...skipping 29 matching lines...) Expand all
57 if (!policy->AddRule(IPC_CREATEEVENT_TAG, &create)) 89 if (!policy->AddRule(IPC_CREATEEVENT_TAG, &create))
58 return false; 90 return false;
59 } 91 }
60 92
61 return true; 93 return true;
62 } 94 }
63 95
64 DWORD SyncPolicy::CreateEventAction(EvalResult eval_result, 96 DWORD SyncPolicy::CreateEventAction(EvalResult eval_result,
65 const ClientInfo& client_info, 97 const ClientInfo& client_info,
66 const std::wstring &event_name, 98 const std::wstring &event_name,
67 uint32 manual_reset, 99 uint32 event_type,
68 uint32 initial_state, 100 uint32 initial_state,
69 HANDLE *handle) { 101 HANDLE *handle) {
102 NtCreateEventFunction NtCreateEvent = NULL;
103 ResolveNTFunctionPtr("NtCreateEvent", &NtCreateEvent);
104
105 NtCloseFunction NtClose = NULL;
106 ResolveNTFunctionPtr("NtClose", &NtClose);
107
70 // The only action supported is ASK_BROKER which means create the requested 108 // The only action supported is ASK_BROKER which means create the requested
71 // file as specified. 109 // file as specified.
72 if (ASK_BROKER != eval_result) 110 if (ASK_BROKER != eval_result)
73 return false; 111 return false;
74 112
75 HANDLE local_handle = ::CreateEvent(NULL, manual_reset, initial_state, 113 HANDLE object_directory = NULL;
76 event_name.c_str()); 114 NTSTATUS status = GetBaseNamedObjectsDirectory(&object_directory);
115 if (status != STATUS_SUCCESS)
116 return status;
117
118 UNICODE_STRING unicode_event_name = {};
119 OBJECT_ATTRIBUTES object_attributes = {};
120 InitObjectAttribs(event_name, OBJ_CASE_INSENSITIVE, object_directory,
121 &object_attributes, &unicode_event_name);
122
123 HANDLE local_handle = NULL;
124 status = NtCreateEvent(&local_handle, EVENT_ALL_ACCESS, &object_attributes,
125 static_cast<EVENT_TYPE>(event_type), initial_state);
77 if (NULL == local_handle) 126 if (NULL == local_handle)
78 return ::GetLastError(); 127 return status;
79 128
80 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, 129 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle,
81 client_info.process, handle, 0, FALSE, 130 client_info.process, handle, 0, FALSE,
82 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { 131 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
83 return ERROR_ACCESS_DENIED; 132 return STATUS_ACCESS_DENIED;
84 } 133 }
85 return ERROR_SUCCESS; 134 return status;
86 } 135 }
87 136
88 DWORD SyncPolicy::OpenEventAction(EvalResult eval_result, 137 DWORD SyncPolicy::OpenEventAction(EvalResult eval_result,
89 const ClientInfo& client_info, 138 const ClientInfo& client_info,
90 const std::wstring &event_name, 139 const std::wstring &event_name,
91 uint32 desired_access, 140 uint32 desired_access,
92 uint32 inherit_handle,
93 HANDLE *handle) { 141 HANDLE *handle) {
142 NtOpenEventFunction NtOpenEvent = NULL;
143 ResolveNTFunctionPtr("NtOpenEvent", &NtOpenEvent);
144
94 // The only action supported is ASK_BROKER which means create the requested 145 // The only action supported is ASK_BROKER which means create the requested
95 // file as specified. 146 // event as specified.
96 if (ASK_BROKER != eval_result) 147 if (ASK_BROKER != eval_result)
97 return false; 148 return false;
98 149
99 HANDLE local_handle = ::OpenEvent(desired_access, FALSE, 150 HANDLE object_directory = NULL;
100 event_name.c_str()); 151 NTSTATUS status = GetBaseNamedObjectsDirectory(&object_directory);
152 if (status != STATUS_SUCCESS)
153 return status;
154
155 UNICODE_STRING unicode_event_name = {};
156 OBJECT_ATTRIBUTES object_attributes = {};
157 InitObjectAttribs(event_name, OBJ_CASE_INSENSITIVE, object_directory,
158 &object_attributes, &unicode_event_name);
159
160 HANDLE local_handle = NULL;
161 status = NtOpenEvent(&local_handle, desired_access, &object_attributes);
101 if (NULL == local_handle) 162 if (NULL == local_handle)
102 return ::GetLastError(); 163 return status;
103 164
104 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, 165 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle,
105 client_info.process, handle, 0, inherit_handle, 166 client_info.process, handle, 0, FALSE,
106 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { 167 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
107 return ERROR_ACCESS_DENIED; 168 return STATUS_ACCESS_DENIED;
108 } 169 }
109 return ERROR_SUCCESS; 170 return status;
110 } 171 }
111 172
112 } // namespace sandbox 173 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/sync_policy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698