1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/win/src/named_pipe_interception.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +// Copyright (c) 2006-2008 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/named_pipe_interception.h" 1.9 + 1.10 +#include "sandbox/win/src/crosscall_client.h" 1.11 +#include "sandbox/win/src/ipc_tags.h" 1.12 +#include "sandbox/win/src/policy_params.h" 1.13 +#include "sandbox/win/src/policy_target.h" 1.14 +#include "sandbox/win/src/sandbox_factory.h" 1.15 +#include "sandbox/win/src/sandbox_nt_util.h" 1.16 +#include "sandbox/win/src/sharedmem_ipc_client.h" 1.17 +#include "sandbox/win/src/target_services.h" 1.18 + 1.19 +namespace sandbox { 1.20 + 1.21 +HANDLE WINAPI TargetCreateNamedPipeW( 1.22 + CreateNamedPipeWFunction orig_CreateNamedPipeW, LPCWSTR pipe_name, 1.23 + DWORD open_mode, DWORD pipe_mode, DWORD max_instance, DWORD out_buffer_size, 1.24 + DWORD in_buffer_size, DWORD default_timeout, 1.25 + LPSECURITY_ATTRIBUTES security_attributes) { 1.26 + HANDLE pipe = orig_CreateNamedPipeW(pipe_name, open_mode, pipe_mode, 1.27 + max_instance, out_buffer_size, 1.28 + in_buffer_size, default_timeout, 1.29 + security_attributes); 1.30 + if (INVALID_HANDLE_VALUE != pipe) 1.31 + return pipe; 1.32 + 1.33 + DWORD original_error = ::GetLastError(); 1.34 + 1.35 + // We don't trust that the IPC can work this early. 1.36 + if (!SandboxFactory::GetTargetServices()->GetState()->InitCalled()) 1.37 + return INVALID_HANDLE_VALUE; 1.38 + 1.39 + // We don't support specific Security Attributes. 1.40 + if (security_attributes) 1.41 + return INVALID_HANDLE_VALUE; 1.42 + 1.43 + do { 1.44 + void* memory = GetGlobalIPCMemory(); 1.45 + if (NULL == memory) 1.46 + break; 1.47 + 1.48 + CountedParameterSet<NameBased> params; 1.49 + params[NameBased::NAME] = ParamPickerMake(pipe_name); 1.50 + 1.51 + if (!QueryBroker(IPC_CREATENAMEDPIPEW_TAG, params.GetBase())) 1.52 + break; 1.53 + 1.54 + SharedMemIPCClient ipc(memory); 1.55 + CrossCallReturn answer = {0}; 1.56 + ResultCode code = CrossCall(ipc, IPC_CREATENAMEDPIPEW_TAG, pipe_name, 1.57 + open_mode, pipe_mode, max_instance, 1.58 + out_buffer_size, in_buffer_size, 1.59 + default_timeout, &answer); 1.60 + if (SBOX_ALL_OK != code) 1.61 + break; 1.62 + 1.63 + ::SetLastError(answer.win32_result); 1.64 + 1.65 + if (ERROR_SUCCESS != answer.win32_result) 1.66 + return INVALID_HANDLE_VALUE; 1.67 + 1.68 + return answer.handle; 1.69 + } while (false); 1.70 + 1.71 + ::SetLastError(original_error); 1.72 + return INVALID_HANDLE_VALUE; 1.73 +} 1.74 + 1.75 +} // namespace sandbox