signed_dispatcher.cc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "sandbox/win/src/signed_dispatcher.h"
  5. #include <stdint.h>
  6. #include <string>
  7. #include "base/strings/string_util.h"
  8. #include "base/win/scoped_handle.h"
  9. #include "sandbox/win/src/crosscall_client.h"
  10. #include "sandbox/win/src/interception.h"
  11. #include "sandbox/win/src/interceptors.h"
  12. #include "sandbox/win/src/ipc_tags.h"
  13. #include "sandbox/win/src/policy_params.h"
  14. #include "sandbox/win/src/sandbox.h"
  15. #include "sandbox/win/src/signed_interception.h"
  16. #include "sandbox/win/src/signed_policy.h"
  17. #include "sandbox/win/src/win_utils.h"
  18. namespace sandbox {
  19. SignedDispatcher::SignedDispatcher(PolicyBase* policy_base)
  20. : policy_base_(policy_base) {
  21. static const IPCCall create_params = {
  22. {IpcTag::NTCREATESECTION, {VOIDPTR_TYPE}},
  23. reinterpret_cast<CallbackGeneric>(&SignedDispatcher::CreateSection)};
  24. ipc_calls_.push_back(create_params);
  25. }
  26. bool SignedDispatcher::SetupService(InterceptionManager* manager,
  27. IpcTag service) {
  28. if (service == IpcTag::NTCREATESECTION)
  29. return INTERCEPT_NT(manager, NtCreateSection, CREATE_SECTION_ID, 32);
  30. return false;
  31. }
  32. bool SignedDispatcher::CreateSection(IPCInfo* ipc, HANDLE file_handle) {
  33. // Duplicate input handle from target to broker.
  34. HANDLE local_file_handle = nullptr;
  35. if (!::DuplicateHandle((*ipc->client_info).process, file_handle,
  36. ::GetCurrentProcess(), &local_file_handle,
  37. FILE_MAP_EXECUTE, false, 0)) {
  38. return false;
  39. }
  40. base::win::ScopedHandle local_handle(local_file_handle);
  41. std::wstring path;
  42. if (!GetPathFromHandle(local_handle.Get(), &path))
  43. return false;
  44. const wchar_t* module_name = path.c_str();
  45. CountedParameterSet<NameBased> params;
  46. params[NameBased::NAME] = ParamPickerMake(module_name);
  47. EvalResult result =
  48. policy_base_->EvalPolicy(IpcTag::NTCREATESECTION, params.GetBase());
  49. // Return operation status on the IPC.
  50. HANDLE section_handle = nullptr;
  51. ipc->return_info.nt_status = SignedPolicy::CreateSectionAction(
  52. result, *ipc->client_info, local_handle, &section_handle);
  53. ipc->return_info.handle = section_handle;
  54. return true;
  55. }
  56. } // namespace sandbox