Page MenuHomePhabricator

[TSan] Add interceptors for mach_vm_[de]allocate

Authored by yln on Aug 22 2019, 12:51 PM.

Diff Detail


Event Timeline

yln created this revision.Aug 22 2019, 12:51 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 22 2019, 12:51 PM
Herald added subscribers: llvm-commits, Restricted Project, jfb, mgorny. · View Herald Transcript
yln updated this revision to Diff 216696.Aug 22 2019, 1:22 PM

Fix warning in test.

kubamracek added inline comments.Aug 23 2019, 3:19 PM
748–749 ↗(On Diff #216696)

is this related? or just a co-incidental change?

42–45 ↗(On Diff #216696)

This is copied from mmap, right? Can it be extracted into a common function instead?

58–62 ↗(On Diff #216696)

ditto here

yln marked 2 inline comments as done.Aug 23 2019, 6:45 PM
yln added inline comments.
748–749 ↗(On Diff #216696)

Related. It took me a while to understand what it is doing, so I left a comment.

void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);

1) addr=0, flags=... -> kernel picks address, best most portable option
2) addr=0x123, flags=... -> kernel picks address, 'addr' is treated as a hint, no guarantees
3) addr=0x123, flag=MAP_FIXED -> mmap fails if allocation cannot be placed at 'addr'

This function ensures that we never call the real mmap with an addr that points into the shadow. For 2) it discards the hint, for 3) we return with failure without forwarding to the real mmap.

vm_mach_allocate only has cases 1) and 3). I named the function intersects_with_shadow

42–45 ↗(On Diff #216696)

I tried extracting a function and then parameterizing it for most of the interceptor, but that turned messy really quickly. I can certainly do it for the above 4 lines.

yln marked 3 inline comments as done.Aug 26 2019, 11:23 AM
yln updated this revision to Diff 217213.Aug 26 2019, 11:27 AM

Extract UnmapShadow and MemoryRangeImitateWriteOrResetRange
helper functions to reduce code duplication.

Looks good to me. @dvyukov ?

yln added a comment.Sep 4 2019, 9:17 AM

@dvyukov, do you want to weigh in here?

yln added a comment.Sep 6 2019, 2:38 PM

Any comments before I ask Kuba to waive this through?

vitalybuka accepted this revision.Sep 6 2019, 4:29 PM
vitalybuka added inline comments.
34 ↗(On Diff #217213)

maybe drop {} on one-liners for consistency

This revision is now accepted and ready to land.Sep 6 2019, 4:29 PM
yln updated this revision to Diff 219396.Sep 9 2019, 10:51 AM

Drop {} on one-liners for consistency.

yln marked an inline comment as done.Sep 9 2019, 10:51 AM
This revision was automatically updated to reflect the committed changes.