| Main index | Section 7 | Options |
The following vulnerability mitigations are covered in this document:
Please note that the effectiveness and availability of these mitigations may vary depending on the FreeBSD version and system configuration.
This manual page describes the security mitigations implemented in FreeBSD to enhance the overall security of the operating system. Each mitigation is designed to protect against specific types of attacks and vulnerabilities.
ASLR introduces randomness into the memory layout during process execution, reducing the predictability of memory addresses. ASLR is intended to make exploitation more difficult in the event that an attacker discovers a software vulnerability, such as a buffer overflow.
ASLR can be enabled on both a global and per-process basis. Global control is provided by a separate set of sysctl(8) knobs for 32- and 64-bit processes. It can be or disabled on a per-process basis via proccontrol(1). Note that an ASLR mode change takes effect upon address space change, i.e., upon execve(2).
Global controls for 32-bit processes:
| kern.elf32.aslr.enable | |
| Enable ASLR for 32-bit ELF binaries, other than Position Independent Exectutable (PIE) binaries. | |
| kern.elf32.aslr.pie_enable | |
| Enable ASLR for 32-bit Position Independent Executable (PIE) ELF binaries. | |
| kern.elf32.aslr.honor_sbrk | |
| Reserve the legacy sbrk(2) region for compatibility with older binaries. | |
| kern.elf32.aslr.stack | |
| Randomize the stack location for 32-bit ELF binaries. | |
Global controls for 64-bit processes:
| kern.elf64.aslr.enable | |
| Enable ASLR for 64-bit ELF binaries, other than Position Independent Exectutable (PIE) binaries. | |
| kern.elf64.aslr.pie_enable | |
| Enable ASLR for 64-bit Position Independent Executable (PIE) ELF binaries. | |
| kern.elf64.aslr.honor_sbrk | |
| Reserve the legacy sbrk(2) region for compatibility with older binaries. | |
| kern.elf64.aslr.stack | |
| Randomize the stack location for 64-bit ELF binaries. | |
To execute a command with ASLR enabled or disabled:
proccontrol
Under the W^X mitigation, memory pages may be writable (W) or executable (E), but not both at the same time. This means that code execution is prevented in areas of memory that are designated as writable, and writing or modification of memory is restricted in areas marked for execution. Applications that perform Just In Time (JIT) compilation need to be adapted to be compatible with W^X.
There are separate sysctl(8) knobs to control W^X policy enforcement for 32- and 64-bit processes. The W^X policy is enabled by setting the appropriate allow_wx sysctl to 0.
| kern.elf32.allow_wx | |
| Allow 32-bit processes to map pages simultaneously writable and executable. | |
| kern.elf64.allow_wx | |
| Allow 64-bit processes to map pages simultaneously writable and executable. | |
When enabled in isolation the RELRO option provides partial RELRO support. In this case the Procedure Linkage Table (PLT)-related part of the Global Offset Table (GOT) (in the section typically named .got.plt) remains writable.
RELRO is enabled by default. The src.conf(5) build-time option WITHOUT_RELRO may be used to disable it.
When enabled in combination with RELRO (which is enabled by default) this provides full RELRO. The entire GOT (.got and .got.plt) are made read-only at program startup, preventing attacks on the relocation table. Note that this results in a nonstandard Application Binary Interface (ABI), and it is possible that some applications may not function correctly.
When
WITH_SSP
is enabled, which is the default, world is built with the
In addition to SSP, a "FORTIFY_SOURCE" implementation is supported up to level 2 by defining _FORTIFY_SOURCE to 1 or 2 before including any FreeBSD headers. FreeBSD world builds can set FORTIFY_SOURCE to provide a default value for _FORTIFY_SOURCE. When enabled, "FORTIFY_SOURCE" enables extra bounds checking in various functions that accept buffers to be written into. These functions currently have extra bounds checking support:
| bcopy() | bzero() | fgets() | getcwd() | gets() |
| memcpy() | memmove() | memset() | read() | readlink() |
| snprintf() | sprintf() | stpcpy() | stpncpy() | strcat() |
| strcpy() | strncat() | strncpy() | vsnprintf() | vsprintf() |
"FORTIFY_SOURCE"
requires compiler support from
clang(1)
or
gcc(1),
which provide the
__builtin_object_size(3)
function that is used to determine the bounds of an object.
This feature works best at optimization levels
Similar to SSP, violating the bounds of an object will cause the program to abort in an effort to avoid malicious execution. This effectively provides finer-grained protection than SSP for some class of function and system calls, along with some protection for buffers allocated as part of the program data.
| Architecture | Feature | Access Type Prevented |
amd64 | SMAP | Read / Write |
amd64 | SMEP | Execute |
arm64 | PAN | Read / Write |
arm64 | PXN | Execute |
riscv | SUM | Read / Write |
riscv | - | Execute |
These features are automatically used by the kernel. There is no user-facing configuration.
Platform firmware updates, if available from the manufacturer, are the best defense as they provide coverage during early boot. Install them with sysutils/flashrom from the FreeBSD Ports Collection.
If platform firmware updates are no longer available, packaged microcode is available for installation at sysutils/cpu-microcode and can be loaded at runtime using loader.conf(5), see the package message for more details.
The best defense overall against hardware vulnerabilities is to timely apply these updates when available, as early as possible in the boot process, and to disable the affected hardware's problematic functionalities when possible (e.g., CPU Simultaneous Multi-Threading). Software mitigations are only partial substitutes for these, but they can be helpful on out-of-support hardware or as complements for just-discovered vulnerabilities not yet addressed by vendors. Some software mitigations depend on hardware capabilities provided by a microcode update.
According to the vulnerability's discoverer, all Zen2-based processors are
affected
(see
.Lk https://lock.cmpxchg8b.com/zenbleed.html
).
As of August 2023, AMD has not publicly listed any corresponding errata but has
issued a security bulletin
(AMD-SB-7008)
entitled
"Cross-Process Information Leak"
indicating that platform firmware fixing the vulnerability will be distributed
to manufacturers no sooner than the end of 2023, except for Rome processors for
which it is already available.
No standalone CPU microcodes have been announced so far.
The only readily-applicable fix mentioned by the discoverer is to set a bit of
an undocumented MSR, which reportedly completely stops XMM register leaks.
FreeBSD currently sets this bit by default on all Zen2 processors. In the future, it might set it by default only on those Zen2 processors whose microcode has not been updated to revisions fixing the vulnerability, once such microcode updates have been actually released and community-tested. To this mitigation are associated the following knobs:
| machdep.mitigations.zenbleed.enable | |
| A read-write integer tunable and sysctl indicating whether the mitigation should be forcibly disabled (0), enabled (1) or if it is left to FreeBSD to selectively apply it (2). Any other integer value is silently converted to and treated as value 2. Note that this setting is silently ignored when running on non-Zen2 processors to ease applying a common configuration to heterogeneous machines. | |
| machdep.mitigations.zenbleed.state | |
| A read-only string indicating the current mitigation state. It can be either "Not applicable", if the processor is not Zen2-based, "Mitigation enabled" or "Mitigation disabled". This state is automatically updated each time the sysctl machdep.mitigations.zenbleed.enable is written to. Note that it can become inaccurate if the chicken bit is set or cleared directly via cpuctl(4) (which includes the cpucontrol(8) utility ). | |
The performance impact and threat models related to these mitigations should be considered when configuring and deploying them in a FreeBSD system.
Additional mitigation knobs are listed in the KNOBS AND TWEAKS section of security(7).
| MITIGATIONS (7) | June 1, 2024 |
| Main index | Section 7 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
| “ | The most horrifying thing about Unix is that, no matter how many times you hit yourself over the head with it, you never quite manage to lose consciousness. It just goes on and on. | ” |
| — Patrick Sobalvarro | ||