security/sandbox/win/src/sync_interception.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/sandbox/win/src/sync_interception.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,107 @@
     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/sync_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 TargetCreateEventW(CreateEventWFunction orig_CreateEvent,
    1.22 +                                 LPSECURITY_ATTRIBUTES security_attributes,
    1.23 +                                 BOOL manual_reset, BOOL initial_state,
    1.24 +                                 LPCWSTR name) {
    1.25 +  // Check if the process can create it first.
    1.26 +  HANDLE handle = orig_CreateEvent(security_attributes, manual_reset,
    1.27 +                                   initial_state, name);
    1.28 +  DWORD original_error = ::GetLastError();
    1.29 +  if (NULL != handle)
    1.30 +    return handle;
    1.31 +
    1.32 +  // We don't trust that the IPC can work this early.
    1.33 +  if (!SandboxFactory::GetTargetServices()->GetState()->InitCalled())
    1.34 +    return NULL;
    1.35 +
    1.36 +  do {
    1.37 +    if (security_attributes)
    1.38 +      break;
    1.39 +
    1.40 +    void* memory = GetGlobalIPCMemory();
    1.41 +    if (NULL == memory)
    1.42 +      break;
    1.43 +
    1.44 +    CountedParameterSet<NameBased> params;
    1.45 +    params[NameBased::NAME] = ParamPickerMake(name);
    1.46 +
    1.47 +    if (!QueryBroker(IPC_CREATEEVENT_TAG, params.GetBase()))
    1.48 +      break;
    1.49 +
    1.50 +    SharedMemIPCClient ipc(memory);
    1.51 +    CrossCallReturn answer = {0};
    1.52 +    ResultCode code = CrossCall(ipc, IPC_CREATEEVENT_TAG, name, manual_reset,
    1.53 +                                initial_state, &answer);
    1.54 +
    1.55 +    if (SBOX_ALL_OK != code)
    1.56 +      break;
    1.57 +
    1.58 +    ::SetLastError(answer.win32_result);
    1.59 +    return answer.handle;
    1.60 +  } while (false);
    1.61 +
    1.62 +  ::SetLastError(original_error);
    1.63 +  return NULL;
    1.64 +}
    1.65 +
    1.66 +// Interception of OpenEventW on the child process.
    1.67 +// It should never be called directly
    1.68 +HANDLE WINAPI TargetOpenEventW(OpenEventWFunction orig_OpenEvent,
    1.69 +                               ACCESS_MASK desired_access, BOOL inherit_handle,
    1.70 +                               LPCWSTR name) {
    1.71 +  // Check if the process can open it first.
    1.72 +  HANDLE handle = orig_OpenEvent(desired_access, inherit_handle, name);
    1.73 +  DWORD original_error = ::GetLastError();
    1.74 +  if (NULL != handle)
    1.75 +    return handle;
    1.76 +
    1.77 +  // We don't trust that the IPC can work this early.
    1.78 +  if (!SandboxFactory::GetTargetServices()->GetState()->InitCalled())
    1.79 +    return NULL;
    1.80 +
    1.81 +  do {
    1.82 +    void* memory = GetGlobalIPCMemory();
    1.83 +    if (NULL == memory)
    1.84 +      break;
    1.85 +
    1.86 +    uint32 inherit_handle_ipc = inherit_handle;
    1.87 +    CountedParameterSet<OpenEventParams> params;
    1.88 +    params[OpenEventParams::NAME] = ParamPickerMake(name);
    1.89 +    params[OpenEventParams::ACCESS] = ParamPickerMake(desired_access);
    1.90 +
    1.91 +    if (!QueryBroker(IPC_OPENEVENT_TAG, params.GetBase()))
    1.92 +      break;
    1.93 +
    1.94 +    SharedMemIPCClient ipc(memory);
    1.95 +    CrossCallReturn answer = {0};
    1.96 +    ResultCode code = CrossCall(ipc, IPC_OPENEVENT_TAG, name, desired_access,
    1.97 +                                inherit_handle_ipc, &answer);
    1.98 +
    1.99 +    if (SBOX_ALL_OK != code)
   1.100 +      break;
   1.101 +
   1.102 +    ::SetLastError(answer.win32_result);
   1.103 +    return answer.handle;
   1.104 +  } while (false);
   1.105 +
   1.106 +  ::SetLastError(original_error);
   1.107 +  return NULL;
   1.108 +}
   1.109 +
   1.110 +}  // namespace sandbox

mercurial