[all-commits] [llvm/llvm-project] 50a5c4: [Sanitizers][Apple] Fix logic bugs that break Rest...

thetruestblue via All-commits all-commits at lists.llvm.org
Thu Jan 30 15:55:36 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 50a5c4f6b9ea8046f90aefdffb8170d1ffb790cd
      https://github.com/llvm/llvm-project/commit/50a5c4f6b9ea8046f90aefdffb8170d1ffb790cd
  Author: thetruestblue <bblueconway at gmail.com>
  Date:   2025-01-30 (Thu, 30 Jan 2025)

  Changed paths:
    M compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp

  Log Message:
  -----------
  [Sanitizers][Apple] Fix logic bugs that break RestrictMemoryToMaxAddress (#124712)

There are two logic bugs breaking RestrictMemoryToMaxAddress.
1. adding left_padding within MapDynamicShadow.
- RoundUpTo((uptr)free_begin + left_padding, alignment) already adjusts
for left padding. Adding this additionally within MapDynamicShadow
causes us to allocate a page larger than necessary.
- This incorrect calculation also means RestrictMemoryToMaxAddress will
never find a big enough gap.


2. There is also an issue with the expectation of hitting
KERN_INVALID_ADDRESS when we are beyond the addressable regions.
- For most embedded scenarios, we exceed vm_max_address without getting
KREN_INVALID_ADDRESS so we setting max_occupied_address to a memory
region the process doesn't have access to, beyond the max address, and
that space is never marked as available so we never find a valid gap in
those regions.
- At some point previous it seems the assumption was once we were beyond
the Max address we could expect KREN_INVALID_ADDRESS, which is no longer
true up through the extended space not given to most processes.
- Because of this, the check` if (new_max_vm < max_occupied_addr)` will
always fail and we will never restrict the address on smaller devices.
- Additionally because of the extra page added by adding left_padding,
and how we only minimally restrict the vm, there's a chance we restrict
the vm only enough for the correctly calculated size of shadow. In these
cases, restricting the vm max address and will always fail due to the
extra page added to space size.

credit to @delcypher for the left_padding diagnosis, remembered his old
radar and PR when investigating this. https://reviews.llvm.org/D85389

Will monitor closely for fall out.

rdar://66603866



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list