W^X (write xor execute, pronounced W xr X) is a security policy in operating systems and software frameworks. It implements executable space protection by ensuring every memory page (a fixed-size block in a program’s virtual address space, the memory layout it uses) is either writable or executable, but not both. Without such protection, a program can write (as data "W") CPU instructions in an area of memory intended for data and then run (as executable "X"; or read-execute "RX") those instructions. This can be dangerous if the writer of the memory is malicious.
The terminology was first introduced in 2003 for Unix-like systems, but is today also used by some multi-platform systems (such as .NET). Other operating systems have adopted similar policies under different names (e.g., DEP in Windows).
In Unix, W^X is typically controlled via the mprotect system call. It is relatively simple on processor architectures supporting fine-grained page permissions, such as SPARC, x86-64, PA-RISC, Alpha, and ARM.
The term W^X has also been applied to file system write/execute permissions to mitigate file write vulnerabilities (as with in memory) and attacker persistence. Enforcing restrictions on file permissions can also close gaps in W^X enforcement caused by memory mapped files. Outright forbidding the usage of arbitrary native code can also mitigate kernel and CPU vulnerabilities not exposed via the existing code on the computer. A less intrusive approach is to lock a file for the duration of any mapping into executable memory, which suffices to prevent post-inspection bypasses.