shared_memory_security_policy.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2020 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 BASE_MEMORY_SHARED_MEMORY_SECURITY_POLICY_H_
  5. #define BASE_MEMORY_SHARED_MEMORY_SECURITY_POLICY_H_
  6. #include <stddef.h>
  7. #include "base/base_export.h"
  8. namespace mojo {
  9. namespace core {
  10. class ChannelLinux;
  11. } // namespace core
  12. } // namespace mojo
  13. namespace base {
  14. namespace subtle {
  15. class PlatformSharedMemoryRegion;
  16. } // namespace subtle
  17. // Helper to enforce a limit for the total amount of shared memory that can be
  18. // mapped. This can help prevent an attacker from spraying the address space of
  19. // a process with shared memory mappings to bypass ASLR. For more details, see
  20. // https://googleprojectzero.blogspot.com/2019/04/virtually-unlimited-memory-escaping.html
  21. class BASE_EXPORT SharedMemorySecurityPolicy {
  22. private:
  23. friend class subtle::PlatformSharedMemoryRegion;
  24. friend class SharedMemoryMapping;
  25. friend class mojo::core::ChannelLinux;
  26. // Checks that a mapping with |size| can be created. Returns false if there is
  27. // an overflow in internal calculations, or the max limit has been reached.
  28. [[nodiscard]] static bool AcquireReservationForMapping(size_t size);
  29. // Releases a reservation that was previously acquired.
  30. static void ReleaseReservationForMapping(size_t size);
  31. };
  32. } // namespace base
  33. #endif // BASE_MEMORY_SHARED_MEMORY_SECURITY_POLICY_H_