W^X Explained

W^X ("write xor execute", pronounced W xor X) is a security feature in operating systems and virtual machines. It is a memory protection policy whereby every page in a process's or kernel's address space may be 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. W^X is the Unix-like terminology for a strict use of the general concept of executable space protection, controlled via the system call.

W^X is relatively simple on processor architectures that support fine-grained page permissions, such as Sun's SPARC and SPARC64, AMD's x86-64, Hewlett-Packard's PA-RISC, HP's (originally Digital Equipment Corporation's) 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.[1] Enforcing restrictions on file permissions can also close gaps in W^X enforcement caused by memory mapped files.[2] [3] Outright forbidding the usage of arbitrary native code can also mitigate kernel and CPU vulnerabilities not exposed via the existing code on the computer.[4] 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.

Compatibility

Some early Intel 64 processors lacked the NX bit required for W^X, but this appeared in later chips. On more limited processors such as the Intel i386, W^X requires using the CS code segment limit as a "line in the sand", a point in the address space above which execution is not permitted and data is located, and below which it is allowed and executable pages are placed. This scheme was used in Exec Shield.[5]

Linker changes are generally required to separate data from code (such as trampolines that are needed for linker and library runtime functions). The switch allowing mixing is usually called execstack on Unix-like systems

W^X can also pose a minor problem for just-in-time compilation, which involves an interpreter generating machine code on the fly and then running it. The simple solution used by most, historically including Firefox, involves just making the page executable after the interpreter is done writing machine code, using on Windows or on Unix-like operating systems. The other solution involves mapping the same region of memory to two pages, one with RW and the other with RX. There is no simple consensus on which solution is safer: supporters of the latter approach believe allowing a page that has ever been writable to be executed defeats the point of W^X (there exists an SELinux policy to control such operations called) and that address space layout randomization would make it safe to put both pages in the same process. Supporters of the former approach believe that the latter approach is only safe when the two pages are given to two separate processes, and inter-process communication would be costlier than calling .

History

W^X was first implemented in OpenBSD 3.3, released May 2003. In 2004, Microsoft introduced a similar feature called DEP (Data Execution Prevention) in Windows XP. Similar features are available for other operating systems, including the PaX and Exec Shield patches for Linux, and NetBSD's implementation of PaX. In Red Hat Enterprise Linux (and automatically CentOS) version 5, or by Linux Kernel 2.6.18-8, SELinux received the,, and policies that provide W^X when disabled.

Although W^X (or DEP) has only protected userland programs for most of its existence, in 2012 Microsoft extended it to the Windows kernel on the x86 and ARM architectures.[6] In late 2014 and early 2015, W^X was added in the OpenBSD kernel on the AMD64 architecture.[7] In early 2016, W^X was fully implemented on NetBSD's AMD64 kernel and partially on the i386 kernel.

macOS computers running on Apple silicon processors enforce W^X for all programs. Intel-based Macs enforce the policy only for programs that use the OS's Hardened Runtime mode.[8] [9]

Starting with Firefox 46 in 2016 and ending with Firefox 116 in 2023, Firefox's virtual machine for JavaScript implemented the W^X policy.[10] This was later rolled back on some platforms for performance reasons, though remained in others which enforce W^X for all programs.[11]

Starting with .NET 6.0 in 2021, .NET now uses W^X.[12]

External links

Notes and References

  1. Web site: Enforce execve restrictions for API > 28.
  2. Web site: Zack's Kernel News.
  3. Web site: S.A.R.A. a new stacked LSM.
  4. Web site: Hardening the Linux Kernel (series 2.0.x).
  5. Web site: i386 W^X. 2003-04-17 . 19 June 2014.
  6. Web site: Exploit mitigation improvements in Win8.
  7. Web site: W^X protection for the AMD64 kernel.
  8. Web site: Porting Just-In-Time Compilers to Apple Silicon . 2022-04-17 . developer.apple.com.
  9. Web site: 2020-07-17 . ARM Macs FAQ . 2022-04-17 . SecureMac . en.
  10. Web site: W^X JIT-code enabled in Firefox. 2016-04-29.
  11. Web site: 1835876 - Consider disabling code memory protection in the content process . bugzilla.mozilla.org . Mozilla . 1 July 2024 . en-us.
  12. Web site: What's new in .NET 6 . docs.microsoft.com . Microsoft . 9 November 2021 . en-us.