sandbox_types.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // Copyright (c) 2012 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. #ifndef SANDBOX_WIN_SRC_SANDBOX_TYPES_H_
  5. #define SANDBOX_WIN_SRC_SANDBOX_TYPES_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/process/kill.h"
  8. #include "base/process/launch.h"
  9. namespace sandbox {
  10. // Operation result codes returned by the sandbox API.
  11. //
  12. // Note: These codes are listed in a histogram and any new codes should be added
  13. // at the end. If the underlying type is changed then the forward declaration in
  14. // sandbox_init_win.h must be updated.
  15. //
  16. enum ResultCode : int {
  17. SBOX_ALL_OK = 0,
  18. // Error is originating on the win32 layer. Call GetlastError() for more
  19. // information.
  20. SBOX_ERROR_GENERIC = 1,
  21. // An invalid combination of parameters was given to the API.
  22. SBOX_ERROR_BAD_PARAMS = 2,
  23. // The desired operation is not supported at this time.
  24. SBOX_ERROR_UNSUPPORTED = 3,
  25. // The request requires more memory that allocated or available.
  26. SBOX_ERROR_NO_SPACE = 4,
  27. // The ipc service requested does not exist.
  28. SBOX_ERROR_INVALID_IPC = 5,
  29. // The ipc service did not complete.
  30. SBOX_ERROR_FAILED_IPC = 6,
  31. // The requested handle was not found.
  32. SBOX_ERROR_NO_HANDLE = 7,
  33. // This function was not expected to be called at this time.
  34. SBOX_ERROR_UNEXPECTED_CALL = 8,
  35. // WaitForAllTargets is already called.
  36. SBOX_ERROR_WAIT_ALREADY_CALLED = 9,
  37. // A channel error prevented DoCall from executing.
  38. SBOX_ERROR_CHANNEL_ERROR = 10,
  39. // Failed to create the alternate desktop.
  40. SBOX_ERROR_CANNOT_CREATE_DESKTOP = 11,
  41. // Failed to create the alternate window station.
  42. SBOX_ERROR_CANNOT_CREATE_WINSTATION = 12,
  43. // Failed to switch back to the interactive window station.
  44. SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION = 13,
  45. // The supplied AppContainer is not valid.
  46. SBOX_ERROR_INVALID_APP_CONTAINER = 14,
  47. // The supplied capability is not valid.
  48. SBOX_ERROR_INVALID_CAPABILITY = 15,
  49. // There is a failure initializing the AppContainer.
  50. SBOX_ERROR_CANNOT_INIT_APPCONTAINER = 16,
  51. // Initializing or updating ProcThreadAttributes failed.
  52. SBOX_ERROR_PROC_THREAD_ATTRIBUTES = 17,
  53. // Error in creating process.
  54. SBOX_ERROR_CREATE_PROCESS = 18,
  55. // Failure calling delegate PreSpawnTarget.
  56. SBOX_ERROR_DELEGATE_PRE_SPAWN = 19,
  57. // Could not assign process to job object.
  58. SBOX_ERROR_ASSIGN_PROCESS_TO_JOB_OBJECT = 20,
  59. // Could not assign process to job object.
  60. SBOX_ERROR_SET_THREAD_TOKEN = 21,
  61. // Could not get thread context of new process.
  62. SBOX_ERROR_GET_THREAD_CONTEXT = 22,
  63. // Could not duplicate target info of new process.
  64. SBOX_ERROR_DUPLICATE_TARGET_INFO = 23,
  65. // Could not set low box token.
  66. SBOX_ERROR_SET_LOW_BOX_TOKEN = 24,
  67. // Could not create file mapping for IPC dispatcher.
  68. SBOX_ERROR_CREATE_FILE_MAPPING = 25,
  69. // Could not duplicate shared section into target process for IPC dispatcher.
  70. SBOX_ERROR_DUPLICATE_SHARED_SECTION = 26,
  71. // Could not map view of shared memory in broker.
  72. SBOX_ERROR_MAP_VIEW_OF_SHARED_SECTION = 27,
  73. // Could not apply ASLR mitigations to target process.
  74. SBOX_ERROR_APPLY_ASLR_MITIGATIONS = 28,
  75. // Could not setup one of the required interception services.
  76. SBOX_ERROR_SETUP_BASIC_INTERCEPTIONS = 29,
  77. // Could not setup basic interceptions.
  78. SBOX_ERROR_SETUP_INTERCEPTION_SERVICE = 30,
  79. // Could not initialize interceptions. This usually means 3rd party software
  80. // is stomping on our hooks, or can sometimes mean the syscall format has
  81. // changed.
  82. SBOX_ERROR_INITIALIZE_INTERCEPTIONS = 31,
  83. // Could not setup the imports for ntdll in target process.
  84. SBOX_ERROR_SETUP_NTDLL_IMPORTS = 32,
  85. // Could not setup the handle closer in target process.
  86. SBOX_ERROR_SETUP_HANDLE_CLOSER = 33,
  87. // Cannot get the current Window Station.
  88. SBOX_ERROR_CANNOT_GET_WINSTATION = 34,
  89. // Cannot query the security attributes of the current Window Station.
  90. SBOX_ERROR_CANNOT_QUERY_WINSTATION_SECURITY = 35,
  91. // Cannot get the current Desktop.
  92. SBOX_ERROR_CANNOT_GET_DESKTOP = 36,
  93. // Cannot query the security attributes of the current Desktop.
  94. SBOX_ERROR_CANNOT_QUERY_DESKTOP_SECURITY = 37,
  95. // Cannot setup the interception manager config buffer.
  96. SBOX_ERROR_CANNOT_SETUP_INTERCEPTION_CONFIG_BUFFER = 38,
  97. // Cannot copy data to the child process.
  98. SBOX_ERROR_CANNOT_COPY_DATA_TO_CHILD = 39,
  99. // Cannot setup the interception thunk.
  100. SBOX_ERROR_CANNOT_SETUP_INTERCEPTION_THUNK = 40,
  101. // Cannot resolve the interception thunk.
  102. SBOX_ERROR_CANNOT_RESOLVE_INTERCEPTION_THUNK = 41,
  103. // Cannot write interception thunk to child process.
  104. SBOX_ERROR_CANNOT_WRITE_INTERCEPTION_THUNK = 42,
  105. // Cannot find the base address of the new process.
  106. SBOX_ERROR_CANNOT_FIND_BASE_ADDRESS = 43,
  107. // Cannot create the AppContainer profile.
  108. SBOX_ERROR_CREATE_APPCONTAINER = 44,
  109. // Cannot create the AppContainer as the main executable can't be accessed.
  110. SBOX_ERROR_CREATE_APPCONTAINER_ACCESS_CHECK = 45,
  111. // Cannot create the AppContainer as adding a capability failed.
  112. SBOX_ERROR_CREATE_APPCONTAINER_CAPABILITY = 46,
  113. // Cannot initialize a job object.
  114. SBOX_ERROR_CANNOT_INIT_JOB = 47,
  115. // Invalid LowBox SID string.
  116. SBOX_ERROR_INVALID_LOWBOX_SID = 48,
  117. // Cannot create restricted token.
  118. SBOX_ERROR_CANNOT_CREATE_RESTRICTED_TOKEN = 49,
  119. // Cannot set the integrity level on a desktop object.
  120. SBOX_ERROR_CANNOT_SET_DESKTOP_INTEGRITY = 50,
  121. // Cannot create a LowBox token.
  122. SBOX_ERROR_CANNOT_CREATE_LOWBOX_TOKEN = 51,
  123. // Cannot modify LowBox token's DACL.
  124. SBOX_ERROR_CANNOT_MODIFY_LOWBOX_TOKEN_DACL = 52,
  125. // Cannot create restricted impersonation token.
  126. SBOX_ERROR_CANNOT_CREATE_RESTRICTED_IMP_TOKEN = 53,
  127. // Cannot duplicate target process handle.
  128. SBOX_ERROR_CANNOT_DUPLICATE_PROCESS_HANDLE = 54,
  129. // Cannot load executable for variable transfer.
  130. SBOX_ERROR_CANNOT_LOADLIBRARY_EXECUTABLE = 55,
  131. // Cannot find variable address for transfer.
  132. SBOX_ERROR_CANNOT_FIND_VARIABLE_ADDRESS = 56,
  133. // Cannot write variable value.
  134. SBOX_ERROR_CANNOT_WRITE_VARIABLE_VALUE = 57,
  135. // Short write to variable.
  136. SBOX_ERROR_INVALID_WRITE_VARIABLE_SIZE = 58,
  137. // Cannot initialize BrokerServices.
  138. SBOX_ERROR_CANNOT_INIT_BROKERSERVICES = 59,
  139. // Cannot update job active process limit.
  140. SBOX_ERROR_CANNOT_UPDATE_JOB_PROCESS_LIMIT = 60,
  141. // Cannot create an impersonation lowbox token
  142. SBOX_ERROR_CANNOT_CREATE_LOWBOX_IMPERSONATION_TOKEN = 61,
  143. // Cannot create a sandbox policy for an unsandboxed process.
  144. SBOX_ERROR_UNSANDBOXED_PROCESS = 62,
  145. // Could not create the unsandboxed process. Extended error from
  146. // base::LaunchProcess will be in GetLastError().
  147. SBOX_ERROR_CANNOT_LAUNCH_UNSANDBOXED_PROCESS = 63,
  148. // Attempt to start a sandboxed process from sandbox code hosted not within
  149. // the main EXE. This is an unsupported operation by the sandbox.
  150. SBOX_ERROR_INVALID_LINK_STATE = 64,
  151. // The target process main EXE had a different base address to the broker.
  152. // This should be impossible but might happen if there is a mismatch in the
  153. // running executable image files vs the one disk.
  154. SBOX_ERROR_INVALID_TARGET_BASE_ADDRESS = 65,
  155. // The target process sentinel value cannot be read.
  156. SBOX_ERROR_CANNOT_READ_SENTINEL_VALUE = 66,
  157. // Short read of the target process sentinel value.
  158. SBOX_ERROR_INVALID_READ_SENTINEL_SIZE = 67,
  159. // The target process sentinel value did not match the sentinel in the broker.
  160. SBOX_ERROR_MISMATCH_SENTINEL_VALUE = 68,
  161. // The process of consolidating the ConfigBase for a policy failed.
  162. SBOX_ERROR_FAILED_TO_FREEZE_CONFIG = 69,
  163. // Placeholder for last item of the enum.
  164. SBOX_ERROR_LAST
  165. };
  166. // If the sandbox cannot create a secure environment for the target, the
  167. // target will be forcibly terminated. These are the process exit codes.
  168. enum TerminationCodes {
  169. SBOX_FATAL_INTEGRITY = 7006, // Could not set the integrity level.
  170. SBOX_FATAL_DROPTOKEN = 7007, // Could not lower the token.
  171. SBOX_FATAL_FLUSHANDLES = 7008, // Failed to flush registry handles.
  172. SBOX_FATAL_CACHEDISABLE = 7009, // Failed to forbid HCKU caching.
  173. SBOX_FATAL_CLOSEHANDLES = 7010, // Failed to close pending handles.
  174. SBOX_FATAL_MITIGATION = 7011, // Could not set the mitigation policy.
  175. SBOX_FATAL_MEMORY_EXCEEDED = 7012, // Exceeded the job memory limit.
  176. SBOX_FATAL_WARMUP = 7013, // Failed to warmup.
  177. SBOX_FATAL_LAST
  178. };
  179. #if !defined(SANDBOX_FUZZ_TARGET)
  180. static_assert(SBOX_FATAL_MEMORY_EXCEEDED ==
  181. base::win::kSandboxFatalMemoryExceeded,
  182. "Value for SBOX_FATAL_MEMORY_EXCEEDED must match base.");
  183. #endif // !defined(SANDBOX_FUZZ_TARGET)
  184. class BrokerServices;
  185. class TargetServices;
  186. // Contains the pointer to a target or broker service.
  187. struct SandboxInterfaceInfo {
  188. // TODO(crbug.com/1298696): Chrome crashes with MTECheckedPtr
  189. // enabled. Triage.
  190. raw_ptr<BrokerServices, DegradeToNoOpWhenMTE> broker_services;
  191. raw_ptr<TargetServices> target_services;
  192. };
  193. #define SANDBOX_INTERCEPT extern "C"
  194. enum InterceptionType {
  195. INTERCEPTION_INVALID = 0,
  196. INTERCEPTION_SERVICE_CALL, // Trampoline of an NT native call
  197. INTERCEPTION_EAT,
  198. INTERCEPTION_UNLOAD_MODULE, // Unload the module (don't patch)
  199. INTERCEPTION_LAST // Placeholder for last item in the enumeration
  200. };
  201. } // namespace sandbox
  202. #endif // SANDBOX_WIN_SRC_SANDBOX_TYPES_H_