Skip to content

How can mprotect be used soundly? #580

@RalfJung

Description

@RalfJung

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions