This is an archive of the discontinued LLVM Phabricator instance.

[Sanitizers][Darwin] Fix invalid gap found by FindAvailableMemoryRange
ClosedPublic

Authored by wrotki on Sep 28 2022, 3:38 PM.

Details

Summary

An application running with ASAN can fail during shadow memory allocation, with an error
indicating a failure to map shadow memory region due to negative size parameter passed to mmap.

It turns out that the mach_vm_region_recurse() call can return an address of a module
which is beyond the range of the VM address space available to the iOS process,
i.e. greater than the value returned by GetMaxVirtualAddress(). It leads the FindAvailableMemoryRange function
to the an incorrect conclusion that it has found a suitable gap where the shadow memory can fit in,
while the shadow memory cannot be really allocated in this case.

The fix just takes the maximum VM address into account, causing the function to return 0,
meaning that the VM gap to fit the requested size could not be found.

rdar://66530705

Diff Detail

Event Timeline

wrotki created this revision.Sep 28 2022, 3:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 28 2022, 3:38 PM
Herald added a subscriber: Enna1. · View Herald Transcript
wrotki requested review of this revision.Sep 28 2022, 3:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 28 2022, 3:38 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
wrotki updated this revision to Diff 463692.Sep 28 2022, 3:46 PM

There are no changes in strncat-verlap.cpp test, correcting.

yln accepted this revision.Oct 4 2022, 11:27 AM

LGTM, thanks for seeing this through @wrotki!

This revision is now accepted and ready to land.Oct 4 2022, 11:27 AM