security/sandbox/win/src/interceptors_64.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "sandbox/win/src/interceptors_64.h"
michael@0 6
michael@0 7 #include "sandbox/win/src/interceptors.h"
michael@0 8 #include "sandbox/win/src/filesystem_interception.h"
michael@0 9 #include "sandbox/win/src/named_pipe_interception.h"
michael@0 10 #include "sandbox/win/src/policy_target.h"
michael@0 11 #include "sandbox/win/src/process_thread_interception.h"
michael@0 12 #include "sandbox/win/src/registry_interception.h"
michael@0 13 #include "sandbox/win/src/sandbox_nt_types.h"
michael@0 14 #include "sandbox/win/src/sandbox_types.h"
michael@0 15 #include "sandbox/win/src/sync_interception.h"
michael@0 16 #include "sandbox/win/src/target_interceptions.h"
michael@0 17
michael@0 18 namespace sandbox {
michael@0 19
michael@0 20 SANDBOX_INTERCEPT NtExports g_nt;
michael@0 21 SANDBOX_INTERCEPT OriginalFunctions g_originals;
michael@0 22
michael@0 23 NTSTATUS WINAPI TargetNtMapViewOfSection64(
michael@0 24 HANDLE section, HANDLE process, PVOID *base, ULONG_PTR zero_bits,
michael@0 25 SIZE_T commit_size, PLARGE_INTEGER offset, PSIZE_T view_size,
michael@0 26 SECTION_INHERIT inherit, ULONG allocation_type, ULONG protect) {
michael@0 27 NtMapViewOfSectionFunction orig_fn = reinterpret_cast<
michael@0 28 NtMapViewOfSectionFunction>(g_originals[MAP_VIEW_OF_SECTION_ID]);
michael@0 29
michael@0 30 return TargetNtMapViewOfSection(orig_fn, section, process, base, zero_bits,
michael@0 31 commit_size, offset, view_size, inherit,
michael@0 32 allocation_type, protect);
michael@0 33 }
michael@0 34
michael@0 35 NTSTATUS WINAPI TargetNtUnmapViewOfSection64(HANDLE process, PVOID base) {
michael@0 36 NtUnmapViewOfSectionFunction orig_fn = reinterpret_cast<
michael@0 37 NtUnmapViewOfSectionFunction>(g_originals[UNMAP_VIEW_OF_SECTION_ID]);
michael@0 38 return TargetNtUnmapViewOfSection(orig_fn, process, base);
michael@0 39 }
michael@0 40
michael@0 41 // -----------------------------------------------------------------------
michael@0 42
michael@0 43 NTSTATUS WINAPI TargetNtSetInformationThread64(
michael@0 44 HANDLE thread, NT_THREAD_INFORMATION_CLASS thread_info_class,
michael@0 45 PVOID thread_information, ULONG thread_information_bytes) {
michael@0 46 NtSetInformationThreadFunction orig_fn = reinterpret_cast<
michael@0 47 NtSetInformationThreadFunction>(g_originals[SET_INFORMATION_THREAD_ID]);
michael@0 48 return TargetNtSetInformationThread(orig_fn, thread, thread_info_class,
michael@0 49 thread_information,
michael@0 50 thread_information_bytes);
michael@0 51 }
michael@0 52
michael@0 53 NTSTATUS WINAPI TargetNtOpenThreadToken64(
michael@0 54 HANDLE thread, ACCESS_MASK desired_access, BOOLEAN open_as_self,
michael@0 55 PHANDLE token) {
michael@0 56 NtOpenThreadTokenFunction orig_fn = reinterpret_cast<
michael@0 57 NtOpenThreadTokenFunction>(g_originals[OPEN_THREAD_TOKEN_ID]);
michael@0 58 return TargetNtOpenThreadToken(orig_fn, thread, desired_access, open_as_self,
michael@0 59 token);
michael@0 60 }
michael@0 61
michael@0 62 NTSTATUS WINAPI TargetNtOpenThreadTokenEx64(
michael@0 63 HANDLE thread, ACCESS_MASK desired_access, BOOLEAN open_as_self,
michael@0 64 ULONG handle_attributes, PHANDLE token) {
michael@0 65 NtOpenThreadTokenExFunction orig_fn = reinterpret_cast<
michael@0 66 NtOpenThreadTokenExFunction>(g_originals[OPEN_THREAD_TOKEN_EX_ID]);
michael@0 67 return TargetNtOpenThreadTokenEx(orig_fn, thread, desired_access,
michael@0 68 open_as_self, handle_attributes, token);
michael@0 69 }
michael@0 70
michael@0 71 HANDLE WINAPI TargetCreateThread64(
michael@0 72 LPSECURITY_ATTRIBUTES thread_attributes, SIZE_T stack_size,
michael@0 73 LPTHREAD_START_ROUTINE start_address, PVOID parameter, DWORD creation_flags,
michael@0 74 LPDWORD thread_id) {
michael@0 75 CreateThreadFunction orig_fn = reinterpret_cast<
michael@0 76 CreateThreadFunction>(g_originals[CREATE_THREAD_ID]);
michael@0 77 return TargetCreateThread(orig_fn, thread_attributes, stack_size,
michael@0 78 start_address, parameter, creation_flags,
michael@0 79 thread_id);
michael@0 80 }
michael@0 81
michael@0 82 LCID WINAPI TargetGetUserDefaultLCID64(void) {
michael@0 83 GetUserDefaultLCIDFunction orig_fn = reinterpret_cast<
michael@0 84 GetUserDefaultLCIDFunction>(g_originals[GET_USER_DEFAULT_LCID_ID]);
michael@0 85 return TargetGetUserDefaultLCID(orig_fn);
michael@0 86 }
michael@0 87
michael@0 88 // -----------------------------------------------------------------------
michael@0 89
michael@0 90 SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtCreateFile64(
michael@0 91 PHANDLE file, ACCESS_MASK desired_access,
michael@0 92 POBJECT_ATTRIBUTES object_attributes, PIO_STATUS_BLOCK io_status,
michael@0 93 PLARGE_INTEGER allocation_size, ULONG file_attributes, ULONG sharing,
michael@0 94 ULONG disposition, ULONG options, PVOID ea_buffer, ULONG ea_length) {
michael@0 95 NtCreateFileFunction orig_fn = reinterpret_cast<
michael@0 96 NtCreateFileFunction>(g_originals[CREATE_FILE_ID]);
michael@0 97 return TargetNtCreateFile(orig_fn, file, desired_access, object_attributes,
michael@0 98 io_status, allocation_size, file_attributes,
michael@0 99 sharing, disposition, options, ea_buffer,
michael@0 100 ea_length);
michael@0 101 }
michael@0 102
michael@0 103 SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtOpenFile64(
michael@0 104 PHANDLE file, ACCESS_MASK desired_access,
michael@0 105 POBJECT_ATTRIBUTES object_attributes, PIO_STATUS_BLOCK io_status,
michael@0 106 ULONG sharing, ULONG options) {
michael@0 107 NtOpenFileFunction orig_fn = reinterpret_cast<
michael@0 108 NtOpenFileFunction>(g_originals[OPEN_FILE_ID]);
michael@0 109 return TargetNtOpenFile(orig_fn, file, desired_access, object_attributes,
michael@0 110 io_status, sharing, options);
michael@0 111 }
michael@0 112
michael@0 113 SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtQueryAttributesFile64(
michael@0 114 POBJECT_ATTRIBUTES object_attributes,
michael@0 115 PFILE_BASIC_INFORMATION file_attributes) {
michael@0 116 NtQueryAttributesFileFunction orig_fn = reinterpret_cast<
michael@0 117 NtQueryAttributesFileFunction>(g_originals[QUERY_ATTRIB_FILE_ID]);
michael@0 118 return TargetNtQueryAttributesFile(orig_fn, object_attributes,
michael@0 119 file_attributes);
michael@0 120 }
michael@0 121
michael@0 122 SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtQueryFullAttributesFile64(
michael@0 123 POBJECT_ATTRIBUTES object_attributes,
michael@0 124 PFILE_NETWORK_OPEN_INFORMATION file_attributes) {
michael@0 125 NtQueryFullAttributesFileFunction orig_fn = reinterpret_cast<
michael@0 126 NtQueryFullAttributesFileFunction>(
michael@0 127 g_originals[QUERY_FULL_ATTRIB_FILE_ID]);
michael@0 128 return TargetNtQueryFullAttributesFile(orig_fn, object_attributes,
michael@0 129 file_attributes);
michael@0 130 }
michael@0 131
michael@0 132 SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtSetInformationFile64(
michael@0 133 HANDLE file, PIO_STATUS_BLOCK io_status, PVOID file_information,
michael@0 134 ULONG length, FILE_INFORMATION_CLASS file_information_class) {
michael@0 135 NtSetInformationFileFunction orig_fn = reinterpret_cast<
michael@0 136 NtSetInformationFileFunction>(g_originals[SET_INFO_FILE_ID]);
michael@0 137 return TargetNtSetInformationFile(orig_fn, file, io_status, file_information,
michael@0 138 length, file_information_class);
michael@0 139 }
michael@0 140
michael@0 141 // -----------------------------------------------------------------------
michael@0 142
michael@0 143 SANDBOX_INTERCEPT HANDLE WINAPI TargetCreateNamedPipeW64(
michael@0 144 LPCWSTR pipe_name, DWORD open_mode, DWORD pipe_mode, DWORD max_instance,
michael@0 145 DWORD out_buffer_size, DWORD in_buffer_size, DWORD default_timeout,
michael@0 146 LPSECURITY_ATTRIBUTES security_attributes) {
michael@0 147 CreateNamedPipeWFunction orig_fn = reinterpret_cast<
michael@0 148 CreateNamedPipeWFunction>(g_originals[CREATE_NAMED_PIPE_ID]);
michael@0 149 return TargetCreateNamedPipeW(orig_fn, pipe_name, open_mode, pipe_mode,
michael@0 150 max_instance, out_buffer_size, in_buffer_size,
michael@0 151 default_timeout, security_attributes);
michael@0 152 }
michael@0 153
michael@0 154 // -----------------------------------------------------------------------
michael@0 155
michael@0 156 SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtOpenThread64(
michael@0 157 PHANDLE thread, ACCESS_MASK desired_access,
michael@0 158 POBJECT_ATTRIBUTES object_attributes, PCLIENT_ID client_id) {
michael@0 159 NtOpenThreadFunction orig_fn = reinterpret_cast<
michael@0 160 NtOpenThreadFunction>(g_originals[OPEN_TREAD_ID]);
michael@0 161 return TargetNtOpenThread(orig_fn, thread, desired_access, object_attributes,
michael@0 162 client_id);
michael@0 163 }
michael@0 164
michael@0 165 SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtOpenProcess64(
michael@0 166 PHANDLE process, ACCESS_MASK desired_access,
michael@0 167 POBJECT_ATTRIBUTES object_attributes, PCLIENT_ID client_id) {
michael@0 168 NtOpenProcessFunction orig_fn = reinterpret_cast<
michael@0 169 NtOpenProcessFunction>(g_originals[OPEN_PROCESS_ID]);
michael@0 170 return TargetNtOpenProcess(orig_fn, process, desired_access,
michael@0 171 object_attributes, client_id);
michael@0 172 }
michael@0 173
michael@0 174 SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtOpenProcessToken64(
michael@0 175 HANDLE process, ACCESS_MASK desired_access, PHANDLE token) {
michael@0 176 NtOpenProcessTokenFunction orig_fn = reinterpret_cast<
michael@0 177 NtOpenProcessTokenFunction>(g_originals[OPEN_PROCESS_TOKEN_ID]);
michael@0 178 return TargetNtOpenProcessToken(orig_fn, process, desired_access, token);
michael@0 179 }
michael@0 180
michael@0 181 SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtOpenProcessTokenEx64(
michael@0 182 HANDLE process, ACCESS_MASK desired_access, ULONG handle_attributes,
michael@0 183 PHANDLE token) {
michael@0 184 NtOpenProcessTokenExFunction orig_fn = reinterpret_cast<
michael@0 185 NtOpenProcessTokenExFunction>(g_originals[OPEN_PROCESS_TOKEN_EX_ID]);
michael@0 186 return TargetNtOpenProcessTokenEx(orig_fn, process, desired_access,
michael@0 187 handle_attributes, token);
michael@0 188 }
michael@0 189
michael@0 190 SANDBOX_INTERCEPT BOOL WINAPI TargetCreateProcessW64(
michael@0 191 LPCWSTR application_name, LPWSTR command_line,
michael@0 192 LPSECURITY_ATTRIBUTES process_attributes,
michael@0 193 LPSECURITY_ATTRIBUTES thread_attributes, BOOL inherit_handles, DWORD flags,
michael@0 194 LPVOID environment, LPCWSTR current_directory, LPSTARTUPINFOW startup_info,
michael@0 195 LPPROCESS_INFORMATION process_information) {
michael@0 196 CreateProcessWFunction orig_fn = reinterpret_cast<
michael@0 197 CreateProcessWFunction>(g_originals[CREATE_PROCESSW_ID]);
michael@0 198 return TargetCreateProcessW(orig_fn, application_name, command_line,
michael@0 199 process_attributes, thread_attributes,
michael@0 200 inherit_handles, flags, environment,
michael@0 201 current_directory, startup_info,
michael@0 202 process_information);
michael@0 203 }
michael@0 204
michael@0 205 SANDBOX_INTERCEPT BOOL WINAPI TargetCreateProcessA64(
michael@0 206 LPCSTR application_name, LPSTR command_line,
michael@0 207 LPSECURITY_ATTRIBUTES process_attributes,
michael@0 208 LPSECURITY_ATTRIBUTES thread_attributes, BOOL inherit_handles, DWORD flags,
michael@0 209 LPVOID environment, LPCSTR current_directory, LPSTARTUPINFOA startup_info,
michael@0 210 LPPROCESS_INFORMATION process_information) {
michael@0 211 CreateProcessAFunction orig_fn = reinterpret_cast<
michael@0 212 CreateProcessAFunction>(g_originals[CREATE_PROCESSA_ID]);
michael@0 213 return TargetCreateProcessA(orig_fn, application_name, command_line,
michael@0 214 process_attributes, thread_attributes,
michael@0 215 inherit_handles, flags, environment,
michael@0 216 current_directory, startup_info,
michael@0 217 process_information);
michael@0 218 }
michael@0 219
michael@0 220 // -----------------------------------------------------------------------
michael@0 221
michael@0 222 SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtCreateKey64(
michael@0 223 PHANDLE key, ACCESS_MASK desired_access,
michael@0 224 POBJECT_ATTRIBUTES object_attributes, ULONG title_index,
michael@0 225 PUNICODE_STRING class_name, ULONG create_options, PULONG disposition) {
michael@0 226 NtCreateKeyFunction orig_fn = reinterpret_cast<
michael@0 227 NtCreateKeyFunction>(g_originals[CREATE_KEY_ID]);
michael@0 228 return TargetNtCreateKey(orig_fn, key, desired_access, object_attributes,
michael@0 229 title_index, class_name, create_options,
michael@0 230 disposition);
michael@0 231 }
michael@0 232
michael@0 233 SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtOpenKey64(
michael@0 234 PHANDLE key, ACCESS_MASK desired_access,
michael@0 235 POBJECT_ATTRIBUTES object_attributes) {
michael@0 236 NtOpenKeyFunction orig_fn = reinterpret_cast<
michael@0 237 NtOpenKeyFunction>(g_originals[OPEN_KEY_ID]);
michael@0 238 return TargetNtOpenKey(orig_fn, key, desired_access, object_attributes);
michael@0 239 }
michael@0 240
michael@0 241 SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtOpenKeyEx64(
michael@0 242 PHANDLE key, ACCESS_MASK desired_access,
michael@0 243 POBJECT_ATTRIBUTES object_attributes, ULONG open_options) {
michael@0 244 NtOpenKeyExFunction orig_fn = reinterpret_cast<
michael@0 245 NtOpenKeyExFunction>(g_originals[OPEN_KEY_EX_ID]);
michael@0 246 return TargetNtOpenKeyEx(orig_fn, key, desired_access, object_attributes,
michael@0 247 open_options);
michael@0 248 }
michael@0 249
michael@0 250 // -----------------------------------------------------------------------
michael@0 251
michael@0 252 SANDBOX_INTERCEPT HANDLE WINAPI TargetCreateEventW64(
michael@0 253 LPSECURITY_ATTRIBUTES security_attributes, BOOL manual_reset,
michael@0 254 BOOL initial_state, LPCWSTR name) {
michael@0 255 CreateEventWFunction orig_fn = reinterpret_cast<
michael@0 256 CreateEventWFunction>(g_originals[CREATE_EVENT_ID]);
michael@0 257 return TargetCreateEventW(orig_fn, security_attributes, manual_reset,
michael@0 258 initial_state, name);
michael@0 259 }
michael@0 260
michael@0 261 SANDBOX_INTERCEPT HANDLE WINAPI TargetOpenEventW64(
michael@0 262 ACCESS_MASK desired_access, BOOL inherit_handle, LPCWSTR name) {
michael@0 263 OpenEventWFunction orig_fn = reinterpret_cast<
michael@0 264 OpenEventWFunction>(g_originals[OPEN_EVENT_ID]);
michael@0 265 return TargetOpenEventW(orig_fn, desired_access, inherit_handle, name);
michael@0 266 }
michael@0 267
michael@0 268 } // namespace sandbox

mercurial