-
Notifications
You must be signed in to change notification settings - Fork 62
Description
Miri now contains some quite cursed hacks in native-lib / FFI mode where it will mprotect(PROT_NONE) a bunch of memory before invoking native C code, and some cursed ptrace magic then kicks in when the program actually accesses those pages. That got me to wonder, which ways of using mprotect are actually sound?
What Miri does could be sound because the cursed ptrace logic conspires to make all memory accesses still work as normal. We just run some extra code on each access. So even if LLVM decided to move some memory accesses around the mprotect calls, that would just confuse our tracing, but the accesses should work as excpected.
Is that the only way mprotect can be used soundly? Just taking away memory that Rust thinks it can access cannot work in general, so it seems quite tricky to use mprotect correctly.