security/sandbox/win/src/interceptors_64.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/sandbox/win/src/interceptors_64.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,268 @@
     1.4 +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#include "sandbox/win/src/interceptors_64.h"
     1.9 +
    1.10 +#include "sandbox/win/src/interceptors.h"
    1.11 +#include "sandbox/win/src/filesystem_interception.h"
    1.12 +#include "sandbox/win/src/named_pipe_interception.h"
    1.13 +#include "sandbox/win/src/policy_target.h"
    1.14 +#include "sandbox/win/src/process_thread_interception.h"
    1.15 +#include "sandbox/win/src/registry_interception.h"
    1.16 +#include "sandbox/win/src/sandbox_nt_types.h"
    1.17 +#include "sandbox/win/src/sandbox_types.h"
    1.18 +#include "sandbox/win/src/sync_interception.h"
    1.19 +#include "sandbox/win/src/target_interceptions.h"
    1.20 +
    1.21 +namespace sandbox {
    1.22 +
    1.23 +SANDBOX_INTERCEPT NtExports g_nt;
    1.24 +SANDBOX_INTERCEPT OriginalFunctions g_originals;
    1.25 +
    1.26 +NTSTATUS WINAPI TargetNtMapViewOfSection64(
    1.27 +    HANDLE section, HANDLE process, PVOID *base, ULONG_PTR zero_bits,
    1.28 +    SIZE_T commit_size, PLARGE_INTEGER offset, PSIZE_T view_size,
    1.29 +    SECTION_INHERIT inherit, ULONG allocation_type, ULONG protect) {
    1.30 +  NtMapViewOfSectionFunction orig_fn = reinterpret_cast<
    1.31 +      NtMapViewOfSectionFunction>(g_originals[MAP_VIEW_OF_SECTION_ID]);
    1.32 +
    1.33 +  return TargetNtMapViewOfSection(orig_fn, section, process, base, zero_bits,
    1.34 +                                  commit_size, offset, view_size, inherit,
    1.35 +                                  allocation_type, protect);
    1.36 +}
    1.37 +
    1.38 +NTSTATUS WINAPI TargetNtUnmapViewOfSection64(HANDLE process, PVOID base) {
    1.39 +  NtUnmapViewOfSectionFunction orig_fn = reinterpret_cast<
    1.40 +      NtUnmapViewOfSectionFunction>(g_originals[UNMAP_VIEW_OF_SECTION_ID]);
    1.41 +  return TargetNtUnmapViewOfSection(orig_fn, process, base);
    1.42 +}
    1.43 +
    1.44 +// -----------------------------------------------------------------------
    1.45 +
    1.46 +NTSTATUS WINAPI TargetNtSetInformationThread64(
    1.47 +    HANDLE thread, NT_THREAD_INFORMATION_CLASS thread_info_class,
    1.48 +    PVOID thread_information, ULONG thread_information_bytes) {
    1.49 +  NtSetInformationThreadFunction orig_fn = reinterpret_cast<
    1.50 +      NtSetInformationThreadFunction>(g_originals[SET_INFORMATION_THREAD_ID]);
    1.51 +  return TargetNtSetInformationThread(orig_fn, thread, thread_info_class,
    1.52 +                                      thread_information,
    1.53 +                                      thread_information_bytes);
    1.54 +}
    1.55 +
    1.56 +NTSTATUS WINAPI TargetNtOpenThreadToken64(
    1.57 +    HANDLE thread, ACCESS_MASK desired_access, BOOLEAN open_as_self,
    1.58 +    PHANDLE token) {
    1.59 +  NtOpenThreadTokenFunction orig_fn = reinterpret_cast<
    1.60 +      NtOpenThreadTokenFunction>(g_originals[OPEN_THREAD_TOKEN_ID]);
    1.61 +  return TargetNtOpenThreadToken(orig_fn, thread, desired_access, open_as_self,
    1.62 +                                 token);
    1.63 +}
    1.64 +
    1.65 +NTSTATUS WINAPI TargetNtOpenThreadTokenEx64(
    1.66 +    HANDLE thread, ACCESS_MASK desired_access, BOOLEAN open_as_self,
    1.67 +    ULONG handle_attributes, PHANDLE token) {
    1.68 +  NtOpenThreadTokenExFunction orig_fn = reinterpret_cast<
    1.69 +      NtOpenThreadTokenExFunction>(g_originals[OPEN_THREAD_TOKEN_EX_ID]);
    1.70 +  return TargetNtOpenThreadTokenEx(orig_fn, thread, desired_access,
    1.71 +                                   open_as_self, handle_attributes, token);
    1.72 +}
    1.73 +
    1.74 +HANDLE WINAPI TargetCreateThread64(
    1.75 +    LPSECURITY_ATTRIBUTES thread_attributes, SIZE_T stack_size,
    1.76 +    LPTHREAD_START_ROUTINE start_address, PVOID parameter, DWORD creation_flags,
    1.77 +    LPDWORD thread_id) {
    1.78 +  CreateThreadFunction orig_fn = reinterpret_cast<
    1.79 +      CreateThreadFunction>(g_originals[CREATE_THREAD_ID]);
    1.80 +  return TargetCreateThread(orig_fn, thread_attributes, stack_size,
    1.81 +                            start_address, parameter, creation_flags,
    1.82 +                            thread_id);
    1.83 +}
    1.84 +
    1.85 +LCID WINAPI TargetGetUserDefaultLCID64(void) {
    1.86 +  GetUserDefaultLCIDFunction orig_fn = reinterpret_cast<
    1.87 +      GetUserDefaultLCIDFunction>(g_originals[GET_USER_DEFAULT_LCID_ID]);
    1.88 +  return TargetGetUserDefaultLCID(orig_fn);
    1.89 +}
    1.90 +
    1.91 +// -----------------------------------------------------------------------
    1.92 +
    1.93 +SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtCreateFile64(
    1.94 +    PHANDLE file, ACCESS_MASK desired_access,
    1.95 +    POBJECT_ATTRIBUTES object_attributes, PIO_STATUS_BLOCK io_status,
    1.96 +    PLARGE_INTEGER allocation_size, ULONG file_attributes, ULONG sharing,
    1.97 +    ULONG disposition, ULONG options, PVOID ea_buffer, ULONG ea_length) {
    1.98 +  NtCreateFileFunction orig_fn = reinterpret_cast<
    1.99 +      NtCreateFileFunction>(g_originals[CREATE_FILE_ID]);
   1.100 +  return TargetNtCreateFile(orig_fn, file, desired_access, object_attributes,
   1.101 +                            io_status, allocation_size, file_attributes,
   1.102 +                            sharing, disposition, options, ea_buffer,
   1.103 +                            ea_length);
   1.104 +}
   1.105 +
   1.106 +SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtOpenFile64(
   1.107 +    PHANDLE file, ACCESS_MASK desired_access,
   1.108 +    POBJECT_ATTRIBUTES object_attributes, PIO_STATUS_BLOCK io_status,
   1.109 +    ULONG sharing, ULONG options) {
   1.110 +  NtOpenFileFunction orig_fn = reinterpret_cast<
   1.111 +      NtOpenFileFunction>(g_originals[OPEN_FILE_ID]);
   1.112 +  return TargetNtOpenFile(orig_fn, file, desired_access, object_attributes,
   1.113 +                          io_status, sharing, options);
   1.114 +}
   1.115 +
   1.116 +SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtQueryAttributesFile64(
   1.117 +    POBJECT_ATTRIBUTES object_attributes,
   1.118 +    PFILE_BASIC_INFORMATION file_attributes) {
   1.119 +  NtQueryAttributesFileFunction orig_fn = reinterpret_cast<
   1.120 +      NtQueryAttributesFileFunction>(g_originals[QUERY_ATTRIB_FILE_ID]);
   1.121 +  return TargetNtQueryAttributesFile(orig_fn, object_attributes,
   1.122 +                                     file_attributes);
   1.123 +}
   1.124 +
   1.125 +SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtQueryFullAttributesFile64(
   1.126 +    POBJECT_ATTRIBUTES object_attributes,
   1.127 +    PFILE_NETWORK_OPEN_INFORMATION file_attributes) {
   1.128 +  NtQueryFullAttributesFileFunction orig_fn = reinterpret_cast<
   1.129 +      NtQueryFullAttributesFileFunction>(
   1.130 +          g_originals[QUERY_FULL_ATTRIB_FILE_ID]);
   1.131 +  return TargetNtQueryFullAttributesFile(orig_fn, object_attributes,
   1.132 +                                         file_attributes);
   1.133 +}
   1.134 +
   1.135 +SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtSetInformationFile64(
   1.136 +    HANDLE file, PIO_STATUS_BLOCK io_status, PVOID file_information,
   1.137 +    ULONG length, FILE_INFORMATION_CLASS file_information_class) {
   1.138 +  NtSetInformationFileFunction orig_fn = reinterpret_cast<
   1.139 +      NtSetInformationFileFunction>(g_originals[SET_INFO_FILE_ID]);
   1.140 +  return TargetNtSetInformationFile(orig_fn, file, io_status, file_information,
   1.141 +                                    length, file_information_class);
   1.142 +}
   1.143 +
   1.144 +// -----------------------------------------------------------------------
   1.145 +
   1.146 +SANDBOX_INTERCEPT HANDLE WINAPI TargetCreateNamedPipeW64(
   1.147 +    LPCWSTR pipe_name, DWORD open_mode, DWORD pipe_mode, DWORD max_instance,
   1.148 +    DWORD out_buffer_size, DWORD in_buffer_size, DWORD default_timeout,
   1.149 +    LPSECURITY_ATTRIBUTES security_attributes) {
   1.150 +  CreateNamedPipeWFunction orig_fn = reinterpret_cast<
   1.151 +      CreateNamedPipeWFunction>(g_originals[CREATE_NAMED_PIPE_ID]);
   1.152 +  return TargetCreateNamedPipeW(orig_fn, pipe_name, open_mode, pipe_mode,
   1.153 +                                max_instance, out_buffer_size, in_buffer_size,
   1.154 +                                default_timeout, security_attributes);
   1.155 +}
   1.156 +
   1.157 +// -----------------------------------------------------------------------
   1.158 +
   1.159 +SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtOpenThread64(
   1.160 +    PHANDLE thread, ACCESS_MASK desired_access,
   1.161 +    POBJECT_ATTRIBUTES object_attributes, PCLIENT_ID client_id) {
   1.162 +  NtOpenThreadFunction orig_fn = reinterpret_cast<
   1.163 +      NtOpenThreadFunction>(g_originals[OPEN_TREAD_ID]);
   1.164 +  return TargetNtOpenThread(orig_fn, thread, desired_access, object_attributes,
   1.165 +                            client_id);
   1.166 +}
   1.167 +
   1.168 +SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtOpenProcess64(
   1.169 +    PHANDLE process, ACCESS_MASK desired_access,
   1.170 +    POBJECT_ATTRIBUTES object_attributes, PCLIENT_ID client_id) {
   1.171 +  NtOpenProcessFunction orig_fn = reinterpret_cast<
   1.172 +      NtOpenProcessFunction>(g_originals[OPEN_PROCESS_ID]);
   1.173 +  return TargetNtOpenProcess(orig_fn, process, desired_access,
   1.174 +                             object_attributes, client_id);
   1.175 +}
   1.176 +
   1.177 +SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtOpenProcessToken64(
   1.178 +    HANDLE process, ACCESS_MASK desired_access, PHANDLE token) {
   1.179 +  NtOpenProcessTokenFunction orig_fn = reinterpret_cast<
   1.180 +      NtOpenProcessTokenFunction>(g_originals[OPEN_PROCESS_TOKEN_ID]);
   1.181 +  return TargetNtOpenProcessToken(orig_fn, process, desired_access, token);
   1.182 +}
   1.183 +
   1.184 +SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtOpenProcessTokenEx64(
   1.185 +    HANDLE process, ACCESS_MASK desired_access, ULONG handle_attributes,
   1.186 +    PHANDLE token) {
   1.187 +  NtOpenProcessTokenExFunction orig_fn = reinterpret_cast<
   1.188 +      NtOpenProcessTokenExFunction>(g_originals[OPEN_PROCESS_TOKEN_EX_ID]);
   1.189 +  return TargetNtOpenProcessTokenEx(orig_fn, process, desired_access,
   1.190 +                                    handle_attributes, token);
   1.191 +}
   1.192 +
   1.193 +SANDBOX_INTERCEPT BOOL WINAPI TargetCreateProcessW64(
   1.194 +    LPCWSTR application_name, LPWSTR command_line,
   1.195 +    LPSECURITY_ATTRIBUTES process_attributes,
   1.196 +    LPSECURITY_ATTRIBUTES thread_attributes, BOOL inherit_handles, DWORD flags,
   1.197 +    LPVOID environment, LPCWSTR current_directory, LPSTARTUPINFOW startup_info,
   1.198 +    LPPROCESS_INFORMATION process_information) {
   1.199 +  CreateProcessWFunction orig_fn = reinterpret_cast<
   1.200 +      CreateProcessWFunction>(g_originals[CREATE_PROCESSW_ID]);
   1.201 +  return TargetCreateProcessW(orig_fn, application_name, command_line,
   1.202 +                              process_attributes, thread_attributes,
   1.203 +                              inherit_handles, flags, environment,
   1.204 +                              current_directory, startup_info,
   1.205 +                              process_information);
   1.206 +}
   1.207 +
   1.208 +SANDBOX_INTERCEPT BOOL WINAPI TargetCreateProcessA64(
   1.209 +    LPCSTR application_name, LPSTR command_line,
   1.210 +    LPSECURITY_ATTRIBUTES process_attributes,
   1.211 +    LPSECURITY_ATTRIBUTES thread_attributes, BOOL inherit_handles, DWORD flags,
   1.212 +    LPVOID environment, LPCSTR current_directory, LPSTARTUPINFOA startup_info,
   1.213 +    LPPROCESS_INFORMATION process_information) {
   1.214 +  CreateProcessAFunction orig_fn = reinterpret_cast<
   1.215 +      CreateProcessAFunction>(g_originals[CREATE_PROCESSA_ID]);
   1.216 +  return TargetCreateProcessA(orig_fn, application_name, command_line,
   1.217 +                              process_attributes, thread_attributes,
   1.218 +                              inherit_handles, flags, environment,
   1.219 +                              current_directory, startup_info,
   1.220 +                              process_information);
   1.221 +}
   1.222 +
   1.223 +// -----------------------------------------------------------------------
   1.224 +
   1.225 +SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtCreateKey64(
   1.226 +    PHANDLE key, ACCESS_MASK desired_access,
   1.227 +    POBJECT_ATTRIBUTES object_attributes, ULONG title_index,
   1.228 +    PUNICODE_STRING class_name, ULONG create_options, PULONG disposition) {
   1.229 +  NtCreateKeyFunction orig_fn = reinterpret_cast<
   1.230 +      NtCreateKeyFunction>(g_originals[CREATE_KEY_ID]);
   1.231 +  return TargetNtCreateKey(orig_fn, key, desired_access, object_attributes,
   1.232 +                           title_index, class_name, create_options,
   1.233 +                           disposition);
   1.234 +}
   1.235 +
   1.236 +SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtOpenKey64(
   1.237 +    PHANDLE key, ACCESS_MASK desired_access,
   1.238 +    POBJECT_ATTRIBUTES object_attributes) {
   1.239 +  NtOpenKeyFunction orig_fn = reinterpret_cast<
   1.240 +      NtOpenKeyFunction>(g_originals[OPEN_KEY_ID]);
   1.241 +  return TargetNtOpenKey(orig_fn, key, desired_access, object_attributes);
   1.242 +}
   1.243 +
   1.244 +SANDBOX_INTERCEPT NTSTATUS WINAPI TargetNtOpenKeyEx64(
   1.245 +    PHANDLE key, ACCESS_MASK desired_access,
   1.246 +    POBJECT_ATTRIBUTES object_attributes, ULONG open_options) {
   1.247 +  NtOpenKeyExFunction orig_fn = reinterpret_cast<
   1.248 +      NtOpenKeyExFunction>(g_originals[OPEN_KEY_EX_ID]);
   1.249 +  return TargetNtOpenKeyEx(orig_fn, key, desired_access, object_attributes,
   1.250 +                           open_options);
   1.251 +}
   1.252 +
   1.253 +// -----------------------------------------------------------------------
   1.254 +
   1.255 +SANDBOX_INTERCEPT HANDLE WINAPI TargetCreateEventW64(
   1.256 +    LPSECURITY_ATTRIBUTES security_attributes, BOOL manual_reset,
   1.257 +    BOOL initial_state, LPCWSTR name) {
   1.258 +  CreateEventWFunction orig_fn = reinterpret_cast<
   1.259 +      CreateEventWFunction>(g_originals[CREATE_EVENT_ID]);
   1.260 +  return TargetCreateEventW(orig_fn, security_attributes, manual_reset,
   1.261 +                            initial_state, name);
   1.262 +}
   1.263 +
   1.264 +SANDBOX_INTERCEPT HANDLE WINAPI TargetOpenEventW64(
   1.265 +    ACCESS_MASK desired_access, BOOL inherit_handle, LPCWSTR name) {
   1.266 +  OpenEventWFunction orig_fn = reinterpret_cast<
   1.267 +      OpenEventWFunction>(g_originals[OPEN_EVENT_ID]);
   1.268 +  return TargetOpenEventW(orig_fn, desired_access, inherit_handle, name);
   1.269 +}
   1.270 +
   1.271 +}  // namespace sandbox

mercurial