Search code examples
securityoptimizationopenbsd

Does OpenBSD's concept of W^X prevent self-modifying code optimizations?


I'm interested more conceptually than practically. Write-xor-execute seems to mean that code must remain constant in memory, so self-modification wouldn't be allowed. Is this the case?


Solution

  • No. W^X is just a policy for normal mappings that are created by the toolchain and kernel for running normal programs. It means that the compiler, linker and kernel will not create mappings that will be executable and writeable at the same time.

    It's not a hard restriction enforced by the kernel. There's nothing that prevents you from creating memory mappings that are both writeable and executable. And even if such a restriction existed, nothing prevents you from creating a writeable mapping of memory, writing to it then changing the protection to read-only and executable (this would be a sane thing to do).