€•F¥Œsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ,/translations/zh_CN/security/self-protection”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ,/translations/zh_TW/security/self-protection”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ,/translations/it_IT/security/self-protection”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ,/translations/ja_JP/security/self-protection”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ,/translations/ko_KR/security/self-protection”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒPortuguese (Brazilian)”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ,/translations/pt_BR/security/self-protection”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ,/translations/sp_SP/security/self-protection”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒKernel Self-Protection”h]”hŒKernel Self-Protection”…””}”(hh¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhh·h²hh³ŒF/var/lib/git/docbuild/linux/Documentation/security/self-protection.rst”h´KubhŒ paragraph”“”)”}”(hXïKernel self-protection is the design and implementation of systems and structures within the Linux kernel to protect against security flaws in the kernel itself. This covers a wide range of issues, including removing entire classes of bugs, blocking security flaw exploitation methods, and actively detecting attack attempts. Not all topics are explored in this document, but it should serve as a reasonable starting point and answer any frequently asked questions. (Patches welcome, of course!)”h]”hXïKernel self-protection is the design and implementation of systems and structures within the Linux kernel to protect against security flaws in the kernel itself. This covers a wide range of issues, including removing entire classes of bugs, blocking security flaw exploitation methods, and actively detecting attack attempts. Not all topics are explored in this document, but it should serve as a reasonable starting point and answer any frequently asked questions. (Patches welcome, of course!)”…””}”(hhÍh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khh·h²hubhÌ)”}”(hX<In the worst-case scenario, we assume an unprivileged local attacker has arbitrary read and write access to the kernel's memory. In many cases, bugs being exploited will not provide this level of access, but with systems in place that defend against the worst case we'll cover the more limited cases as well. A higher bar, and one that should still be kept in mind, is protecting the kernel against a _privileged_ local attacker, since the root user has access to a vastly increased attack surface. (Especially when they have the ability to load arbitrary kernel modules.)”h]”hX@In the worst-case scenario, we assume an unprivileged local attacker has arbitrary read and write access to the kernel’s memory. In many cases, bugs being exploited will not provide this level of access, but with systems in place that defend against the worst case we’ll cover the more limited cases as well. A higher bar, and one that should still be kept in mind, is protecting the kernel against a _privileged_ local attacker, since the root user has access to a vastly increased attack surface. (Especially when they have the ability to load arbitrary kernel modules.)”…””}”(hhÛh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K hh·h²hubhÌ)”}”(hXpThe goals for successful self-protection systems would be that they are effective, on by default, require no opt-in by developers, have no performance impact, do not impede kernel debugging, and have tests. It is uncommon that all these goals can be met, but it is worth explicitly mentioning them, since these aspects need to be explored, dealt with, and/or accepted.”h]”hXpThe goals for successful self-protection systems would be that they are effective, on by default, require no opt-in by developers, have no performance impact, do not impede kernel debugging, and have tests. It is uncommon that all these goals can be met, but it is worth explicitly mentioning them, since these aspects need to be explored, dealt with, and/or accepted.”…””}”(hhéh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khh·h²hubh¶)”}”(hhh]”(h»)”}”(hŒAttack Surface Reduction”h]”hŒAttack Surface Reduction”…””}”(hhúh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhh÷h²hh³hÊh´K ubhÌ)”}”(hX*The most fundamental defense against security exploits is to reduce the areas of the kernel that can be used to redirect execution. This ranges from limiting the exposed APIs available to userspace, making in-kernel APIs hard to use incorrectly, minimizing the areas of writable kernel memory, etc.”h]”hX*The most fundamental defense against security exploits is to reduce the areas of the kernel that can be used to redirect execution. This ranges from limiting the exposed APIs available to userspace, making in-kernel APIs hard to use incorrectly, minimizing the areas of writable kernel memory, etc.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K"hh÷h²hubh¶)”}”(hhh]”(h»)”}”(hŒ Strict kernel memory permissions”h]”hŒ Strict kernel memory permissions”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´K)ubhÌ)”}”(hŒÕWhen all of kernel memory is writable, it becomes trivial for attacks to redirect execution flow. To reduce the availability of these targets the kernel needs to protect its memory with a tight set of permissions.”h]”hŒÕWhen all of kernel memory is writable, it becomes trivial for attacks to redirect execution flow. To reduce the availability of these targets the kernel needs to protect its memory with a tight set of permissions.”…””}”(hj'h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K+hjh²hubh¶)”}”(hhh]”(h»)”}”(hŒ7Executable code and read-only data must not be writable”h]”hŒ7Executable code and read-only data must not be writable”…””}”(hj8h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj5h²hh³hÊh´K0ubhÌ)”}”(hXðAny areas of the kernel with executable memory must not be writable. While this obviously includes the kernel text itself, we must consider all additional places too: kernel modules, JIT memory, etc. (There are temporary exceptions to this rule to support things like instruction alternatives, breakpoints, kprobes, etc. If these must exist in a kernel, they are implemented in a way where the memory is temporarily made writable during the update, and then returned to the original permissions.)”h]”hXðAny areas of the kernel with executable memory must not be writable. While this obviously includes the kernel text itself, we must consider all additional places too: kernel modules, JIT memory, etc. (There are temporary exceptions to this rule to support things like instruction alternatives, breakpoints, kprobes, etc. If these must exist in a kernel, they are implemented in a way where the memory is temporarily made writable during the update, and then returned to the original permissions.)”…””}”(hjFh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K2hj5h²hubhÌ)”}”(hŒ×In support of this are ``CONFIG_STRICT_KERNEL_RWX`` and ``CONFIG_STRICT_MODULE_RWX``, which seek to make sure that code is not writable, data is not executable, and read-only data is neither writable nor executable.”h]”(hŒIn support of this are ”…””}”(hjTh²hh³Nh´NubhŒliteral”“”)”}”(hŒ``CONFIG_STRICT_KERNEL_RWX``”h]”hŒCONFIG_STRICT_KERNEL_RWX”…””}”(hj^h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j\hjTubhŒ and ”…””}”(hjTh²hh³Nh´Nubj])”}”(hŒ``CONFIG_STRICT_MODULE_RWX``”h]”hŒCONFIG_STRICT_MODULE_RWX”…””}”(hjph²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j\hjTubhŒƒ, which seek to make sure that code is not writable, data is not executable, and read-only data is neither writable nor executable.”…””}”(hjTh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K;hj5h²hubhÌ)”}”(hXaMost architectures have these options on by default and not user selectable. For some architectures like arm that wish to have these be selectable, the architecture Kconfig can select ARCH_OPTIONAL_KERNEL_RWX to enable a Kconfig prompt. ``CONFIG_ARCH_OPTIONAL_KERNEL_RWX_DEFAULT`` determines the default setting when ARCH_OPTIONAL_KERNEL_RWX is enabled.”h]”(hŒíMost architectures have these options on by default and not user selectable. For some architectures like arm that wish to have these be selectable, the architecture Kconfig can select ARCH_OPTIONAL_KERNEL_RWX to enable a Kconfig prompt. ”…””}”(hjˆh²hh³Nh´Nubj])”}”(hŒ+``CONFIG_ARCH_OPTIONAL_KERNEL_RWX_DEFAULT``”h]”hŒ'CONFIG_ARCH_OPTIONAL_KERNEL_RWX_DEFAULT”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j\hjˆubhŒI determines the default setting when ARCH_OPTIONAL_KERNEL_RWX is enabled.”…””}”(hjˆh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K@hj5h²hubeh}”(h]”Œ7executable-code-and-read-only-data-must-not-be-writable”ah ]”h"]”Œ7executable code and read-only data must not be writable”ah$]”h&]”uh1hµhjh²hh³hÊh´K0ubh¶)”}”(hhh]”(h»)”}”(hŒ>Function pointers and sensitive variables must not be writable”h]”hŒ>Function pointers and sensitive variables must not be writable”…””}”(hj³h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj°h²hh³hÊh´KGubhÌ)”}”(hXVast areas of kernel memory contain function pointers that are looked up by the kernel and used to continue execution (e.g. descriptor/vector tables, file/network/etc operation structures, etc). The number of these variables must be reduced to an absolute minimum.”h]”hXVast areas of kernel memory contain function pointers that are looked up by the kernel and used to continue execution (e.g. descriptor/vector tables, file/network/etc operation structures, etc). The number of these variables must be reduced to an absolute minimum.”…””}”(hjÁh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KIhj°h²hubhÌ)”}”(hŒëMany such variables can be made read-only by setting them "const" so that they live in the .rodata section instead of the .data section of the kernel, gaining the protection of the kernel's strict memory permissions as described above.”h]”hŒñMany such variables can be made read-only by setting them “const†so that they live in the .rodata section instead of the .data section of the kernel, gaining the protection of the kernel’s strict memory permissions as described above.”…””}”(hjÏh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KNhj°h²hubhÌ)”}”(hŒwFor variables that are initialized once at ``__init`` time, these can be marked with the ``__ro_after_init`` attribute.”h]”(hŒ+For variables that are initialized once at ”…””}”(hjÝh²hh³Nh´Nubj])”}”(hŒ ``__init``”h]”hŒ__init”…””}”(hjåh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j\hjÝubhŒ$ time, these can be marked with the ”…””}”(hjÝh²hh³Nh´Nubj])”}”(hŒ``__ro_after_init``”h]”hŒ__ro_after_init”…””}”(hj÷h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j\hjÝubhŒ attribute.”…””}”(hjÝh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KShj°h²hubhÌ)”}”(hXvWhat remains are variables that are updated rarely (e.g. GDT). These will need another infrastructure (similar to the temporary exceptions made to kernel code mentioned above) that allow them to spend the rest of their lifetime read-only. (For example, when being updated, only the CPU thread performing the update would be given uninterruptible write access to the memory.)”h]”hXvWhat remains are variables that are updated rarely (e.g. GDT). These will need another infrastructure (similar to the temporary exceptions made to kernel code mentioned above) that allow them to spend the rest of their lifetime read-only. (For example, when being updated, only the CPU thread performing the update would be given uninterruptible write access to the memory.)”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KVhj°h²hubeh}”(h]”Œ>function-pointers-and-sensitive-variables-must-not-be-writable”ah ]”h"]”Œ>function pointers and sensitive variables must not be writable”ah$]”h&]”uh1hµhjh²hh³hÊh´KGubh¶)”}”(hhh]”(h»)”}”(hŒ2Segregation of kernel memory from userspace memory”h]”hŒ2Segregation of kernel memory from userspace memory”…””}”(hj(h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj%h²hh³hÊh´K^ubhÌ)”}”(hXÖThe kernel must never execute userspace memory. The kernel must also never access userspace memory without explicit expectation to do so. These rules can be enforced either by support of hardware-based restrictions (x86's SMEP/SMAP, ARM's PXN/PAN) or via emulation (ARM's Memory Domains). By blocking userspace memory in this way, execution and data parsing cannot be passed to trivially-controlled userspace memory, forcing attacks to operate entirely in kernel memory.”h]”hXÜThe kernel must never execute userspace memory. The kernel must also never access userspace memory without explicit expectation to do so. These rules can be enforced either by support of hardware-based restrictions (x86’s SMEP/SMAP, ARM’s PXN/PAN) or via emulation (ARM’s Memory Domains). By blocking userspace memory in this way, execution and data parsing cannot be passed to trivially-controlled userspace memory, forcing attacks to operate entirely in kernel memory.”…””}”(hj6h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K`hj%h²hubeh}”(h]”Œ2segregation-of-kernel-memory-from-userspace-memory”ah ]”h"]”Œ2segregation of kernel memory from userspace memory”ah$]”h&]”uh1hµhjh²hh³hÊh´K^ubeh}”(h]”Œ strict-kernel-memory-permissions”ah ]”h"]”Œ strict kernel memory permissions”ah$]”h&]”uh1hµhh÷h²hh³hÊh´K)ubh¶)”}”(hhh]”(h»)”}”(hŒReduced access to syscalls”h]”hŒReduced access to syscalls”…””}”(hjWh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjTh²hh³hÊh´KiubhÌ)”}”(hŒ‘One trivial way to eliminate many syscalls for 64-bit systems is building without ``CONFIG_COMPAT``. However, this is rarely a feasible scenario.”h]”(hŒROne trivial way to eliminate many syscalls for 64-bit systems is building without ”…””}”(hjeh²hh³Nh´Nubj])”}”(hŒ``CONFIG_COMPAT``”h]”hŒ CONFIG_COMPAT”…””}”(hjmh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j\hjeubhŒ.. However, this is rarely a feasible scenario.”…””}”(hjeh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KkhjTh²hubhÌ)”}”(hX)The "seccomp" system provides an opt-in feature made available to userspace, which provides a way to reduce the number of kernel entry points available to a running process. This limits the breadth of kernel code that can be reached, possibly reducing the availability of a given bug to an attack.”h]”hX-The “seccomp†system provides an opt-in feature made available to userspace, which provides a way to reduce the number of kernel entry points available to a running process. This limits the breadth of kernel code that can be reached, possibly reducing the availability of a given bug to an attack.”…””}”(hj…h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KnhjTh²hubhÌ)”}”(hX*An area of improvement would be creating viable ways to keep access to things like compat, user namespaces, BPF creation, and perf limited only to trusted processes. This would keep the scope of kernel entry points restricted to the more regular set of normally available to unprivileged userspace.”h]”hX*An area of improvement would be creating viable ways to keep access to things like compat, user namespaces, BPF creation, and perf limited only to trusted processes. This would keep the scope of kernel entry points restricted to the more regular set of normally available to unprivileged userspace.”…””}”(hj“h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KthjTh²hubeh}”(h]”Œreduced-access-to-syscalls”ah ]”h"]”Œreduced access to syscalls”ah$]”h&]”uh1hµhh÷h²hh³hÊh´Kiubh¶)”}”(hhh]”(h»)”}”(hŒ$Restricting access to kernel modules”h]”hŒ$Restricting access to kernel modules”…””}”(hj¬h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj©h²hh³hÊh´K{ubhÌ)”}”(hXMThe kernel should never allow an unprivileged user the ability to load specific kernel modules, since that would provide a facility to unexpectedly extend the available attack surface. (The on-demand loading of modules via their predefined subsystems, e.g. MODULE_ALIAS_*, is considered "expected" here, though additional consideration should be given even to these.) For example, loading a filesystem module via an unprivileged socket API is nonsense: only the root or physically local user should trigger filesystem module loading. (And even this can be up for debate in some scenarios.)”h]”hXQThe kernel should never allow an unprivileged user the ability to load specific kernel modules, since that would provide a facility to unexpectedly extend the available attack surface. (The on-demand loading of modules via their predefined subsystems, e.g. MODULE_ALIAS_*, is considered “expected†here, though additional consideration should be given even to these.) For example, loading a filesystem module via an unprivileged socket API is nonsense: only the root or physically local user should trigger filesystem module loading. (And even this can be up for debate in some scenarios.)”…””}”(hjºh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K}hj©h²hubhÌ)”}”(hXMTo protect against even privileged users, systems may need to either disable module loading entirely (e.g. monolithic kernel builds or modules_disabled sysctl), or provide signed modules (e.g. ``CONFIG_MODULE_SIG_FORCE``, or dm-crypt with LoadPin), to keep from having root load arbitrary kernel code via the module loader interface.”h]”(hŒÁTo protect against even privileged users, systems may need to either disable module loading entirely (e.g. monolithic kernel builds or modules_disabled sysctl), or provide signed modules (e.g. ”…””}”(hjÈh²hh³Nh´Nubj])”}”(hŒ``CONFIG_MODULE_SIG_FORCE``”h]”hŒCONFIG_MODULE_SIG_FORCE”…””}”(hjÐh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j\hjÈubhŒq, or dm-crypt with LoadPin), to keep from having root load arbitrary kernel code via the module loader interface.”…””}”(hjÈh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K‡hj©h²hubeh}”(h]”Œ$restricting-access-to-kernel-modules”ah ]”h"]”Œ$restricting access to kernel modules”ah$]”h&]”uh1hµhh÷h²hh³hÊh´K{ubeh}”(h]”Œattack-surface-reduction”ah ]”h"]”Œattack surface reduction”ah$]”h&]”uh1hµhh·h²hh³hÊh´K ubh¶)”}”(hhh]”(h»)”}”(hŒMemory integrity”h]”hŒMemory integrity”…””}”(hjûh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjøh²hh³hÊh´KubhÌ)”}”(hX]There are many memory structures in the kernel that are regularly abused to gain execution control during an attack, By far the most commonly understood is that of the stack buffer overflow in which the return address stored on the stack is overwritten. Many other examples of this kind of attack exist, and protections exist to defend against them.”h]”hX]There are many memory structures in the kernel that are regularly abused to gain execution control during an attack, By far the most commonly understood is that of the stack buffer overflow in which the return address stored on the stack is overwritten. Many other examples of this kind of attack exist, and protections exist to defend against them.”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K‘hjøh²hubh¶)”}”(hhh]”(h»)”}”(hŒStack buffer overflow”h]”hŒStack buffer overflow”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´K˜ubhÌ)”}”(hX²The classic stack buffer overflow involves writing past the expected end of a variable stored on the stack, ultimately writing a controlled value to the stack frame's stored return address. The most widely used defense is the presence of a stack canary between the stack variables and the return address (``CONFIG_STACKPROTECTOR``), which is verified just before the function returns. Other defenses include things like shadow stacks.”h]”(hX3The classic stack buffer overflow involves writing past the expected end of a variable stored on the stack, ultimately writing a controlled value to the stack frame’s stored return address. The most widely used defense is the presence of a stack canary between the stack variables and the return address (”…””}”(hj(h²hh³Nh´Nubj])”}”(hŒ``CONFIG_STACKPROTECTOR``”h]”hŒCONFIG_STACKPROTECTOR”…””}”(hj0h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j\hj(ubhŒh), which is verified just before the function returns. Other defenses include things like shadow stacks.”…””}”(hj(h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kšhjh²hubeh}”(h]”Œstack-buffer-overflow”ah ]”h"]”Œstack buffer overflow”ah$]”h&]”uh1hµhjøh²hh³hÊh´K˜ubh¶)”}”(hhh]”(h»)”}”(hŒStack depth overflow”h]”hŒStack depth overflow”…””}”(hjSh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjPh²hh³hÊh´K¢ubhÌ)”}”(hXÝA less well understood attack is using a bug that triggers the kernel to consume stack memory with deep function calls or large stack allocations. With this attack it is possible to write beyond the end of the kernel's preallocated stack space and into sensitive structures. Two important changes need to be made for better protections: moving the sensitive thread_info structure elsewhere, and adding a faulting memory hole at the bottom of the stack to catch these overflows.”h]”hXßA less well understood attack is using a bug that triggers the kernel to consume stack memory with deep function calls or large stack allocations. With this attack it is possible to write beyond the end of the kernel’s preallocated stack space and into sensitive structures. Two important changes need to be made for better protections: moving the sensitive thread_info structure elsewhere, and adding a faulting memory hole at the bottom of the stack to catch these overflows.”…””}”(hjah²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¤hjPh²hubeh}”(h]”Œstack-depth-overflow”ah ]”h"]”Œstack depth overflow”ah$]”h&]”uh1hµhjøh²hh³hÊh´K¢ubh¶)”}”(hhh]”(h»)”}”(hŒHeap memory integrity”h]”hŒHeap memory integrity”…””}”(hjzh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjwh²hh³hÊh´K­ubhÌ)”}”(hŒ¦The structures used to track heap free lists can be sanity-checked during allocation and freeing to make sure they aren't being used to manipulate other memory areas.”h]”hŒ¨The structures used to track heap free lists can be sanity-checked during allocation and freeing to make sure they aren’t being used to manipulate other memory areas.”…””}”(hjˆh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¯hjwh²hubeh}”(h]”Œheap-memory-integrity”ah ]”h"]”Œheap memory integrity”ah$]”h&]”uh1hµhjøh²hh³hÊh´K­ubh¶)”}”(hhh]”(h»)”}”(hŒCounter integrity”h]”hŒCounter integrity”…””}”(hj¡h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjžh²hh³hÊh´K´ubhÌ)”}”(hXMany places in the kernel use atomic counters to track object references or perform similar lifetime management. When these counters can be made to wrap (over or under) this traditionally exposes a use-after-free flaw. By trapping atomic wrapping, this class of bug vanishes.”h]”hXMany places in the kernel use atomic counters to track object references or perform similar lifetime management. When these counters can be made to wrap (over or under) this traditionally exposes a use-after-free flaw. By trapping atomic wrapping, this class of bug vanishes.”…””}”(hj¯h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¶hjžh²hubeh}”(h]”Œcounter-integrity”ah ]”h"]”Œcounter integrity”ah$]”h&]”uh1hµhjøh²hh³hÊh´K´ubh¶)”}”(hhh]”(h»)”}”(hŒ#Size calculation overflow detection”h]”hŒ#Size calculation overflow detection”…””}”(hjÈh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÅh²hh³hÊh´K¼ubhÌ)”}”(hŒÕSimilar to counter overflow, integer overflows (usually size calculations) need to be detected at runtime to kill this class of bug, which traditionally leads to being able to write past the end of kernel buffers.”h]”hŒÕSimilar to counter overflow, integer overflows (usually size calculations) need to be detected at runtime to kill this class of bug, which traditionally leads to being able to write past the end of kernel buffers.”…””}”(hjÖh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K¾hjÅh²hubeh}”(h]”Œ#size-calculation-overflow-detection”ah ]”h"]”Œ#size calculation overflow detection”ah$]”h&]”uh1hµhjøh²hh³hÊh´K¼ubeh}”(h]”Œmemory-integrity”ah ]”h"]”Œmemory integrity”ah$]”h&]”uh1hµhh·h²hh³hÊh´Kubh¶)”}”(hhh]”(h»)”}”(hŒProbabilistic defenses”h]”hŒProbabilistic defenses”…””}”(hj÷h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjôh²hh³hÊh´KÄubhÌ)”}”(hX1While many protections can be considered deterministic (e.g. read-only memory cannot be written to), some protections provide only statistical defense, in that an attack must gather enough information about a running system to overcome the defense. While not perfect, these do provide meaningful defenses.”h]”hX1While many protections can be considered deterministic (e.g. read-only memory cannot be written to), some protections provide only statistical defense, in that an attack must gather enough information about a running system to overcome the defense. While not perfect, these do provide meaningful defenses.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KÆhjôh²hubh¶)”}”(hhh]”(h»)”}”(hŒ%Canaries, blinding, and other secrets”h]”hŒ%Canaries, blinding, and other secrets”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´KÍubhÌ)”}”(hŒÝIt should be noted that things like the stack canary discussed earlier are technically statistical defenses, since they rely on a secret value, and such values may become discoverable through an information exposure flaw.”h]”hŒÝIt should be noted that things like the stack canary discussed earlier are technically statistical defenses, since they rely on a secret value, and such values may become discoverable through an information exposure flaw.”…””}”(hj$h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KÏhjh²hubhÌ)”}”(hŒ™Blinding literal values for things like JITs, where the executable contents may be partially under the control of userspace, need a similar secret value.”h]”hŒ™Blinding literal values for things like JITs, where the executable contents may be partially under the control of userspace, need a similar secret value.”…””}”(hj2h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KÔhjh²hubhÌ)”}”(hŒ¶It is critical that the secret values used must be separate (e.g. different canary per stack) and high entropy (e.g. is the RNG actually working?) in order to maximize their success.”h]”hŒ¶It is critical that the secret values used must be separate (e.g. different canary per stack) and high entropy (e.g. is the RNG actually working?) in order to maximize their success.”…””}”(hj@h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KØhjh²hubeh}”(h]”Œ#canaries-blinding-and-other-secrets”ah ]”h"]”Œ%canaries, blinding, and other secrets”ah$]”h&]”uh1hµhjôh²hh³hÊh´KÍubh¶)”}”(hhh]”(h»)”}”(hŒ1Kernel Address Space Layout Randomization (KASLR)”h]”hŒ1Kernel Address Space Layout Randomization (KASLR)”…””}”(hjYh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjVh²hh³hÊh´KÝubhÌ)”}”(hX4Since the location of kernel memory is almost always instrumental in mounting a successful attack, making the location non-deterministic raises the difficulty of an exploit. (Note that this in turn makes the value of information exposures higher, since they may be used to discover desired memory locations.)”h]”hX4Since the location of kernel memory is almost always instrumental in mounting a successful attack, making the location non-deterministic raises the difficulty of an exploit. (Note that this in turn makes the value of information exposures higher, since they may be used to discover desired memory locations.)”…””}”(hjgh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KßhjVh²hubh¶)”}”(hhh]”(h»)”}”(hŒText and module base”h]”hŒText and module base”…””}”(hjxh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjuh²hh³hÊh´KæubhÌ)”}”(hXrBy relocating the physical and virtual base address of the kernel at boot-time (``CONFIG_RANDOMIZE_BASE``), attacks needing kernel code will be frustrated. Additionally, offsetting the module loading base address means that even systems that load the same set of modules in the same order every boot will not share a common base address with the rest of the kernel text.”h]”(hŒPBy relocating the physical and virtual base address of the kernel at boot-time (”…””}”(hj†h²hh³Nh´Nubj])”}”(hŒ``CONFIG_RANDOMIZE_BASE``”h]”hŒCONFIG_RANDOMIZE_BASE”…””}”(hjŽh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j\hj†ubhX ), attacks needing kernel code will be frustrated. Additionally, offsetting the module loading base address means that even systems that load the same set of modules in the same order every boot will not share a common base address with the rest of the kernel text.”…””}”(hj†h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kèhjuh²hubeh}”(h]”Œtext-and-module-base”ah ]”h"]”Œtext and module base”ah$]”h&]”uh1hµhjVh²hh³hÊh´Kæubh¶)”}”(hhh]”(h»)”}”(hŒ Stack base”h]”hŒ Stack base”…””}”(hj±h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj®h²hh³hÊh´KðubhÌ)”}”(hŒ±If the base address of the kernel stack is not the same between processes, or even not the same between syscalls, targets on or beyond the stack become more difficult to locate.”h]”hŒ±If the base address of the kernel stack is not the same between processes, or even not the same between syscalls, targets on or beyond the stack become more difficult to locate.”…””}”(hj¿h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kòhj®h²hubeh}”(h]”Œ stack-base”ah ]”h"]”Œ stack base”ah$]”h&]”uh1hµhjVh²hh³hÊh´Kðubh¶)”}”(hhh]”(h»)”}”(hŒDynamic memory base”h]”hŒDynamic memory base”…””}”(hjØh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjÕh²hh³hÊh´K÷ubhÌ)”}”(hX;Much of the kernel's dynamic memory (e.g. kmalloc, vmalloc, etc) ends up being relatively deterministic in layout due to the order of early-boot initializations. If the base address of these areas is not the same between boots, targeting them is frustrated, requiring an information exposure specific to the region.”h]”hX=Much of the kernel’s dynamic memory (e.g. kmalloc, vmalloc, etc) ends up being relatively deterministic in layout due to the order of early-boot initializations. If the base address of these areas is not the same between boots, targeting them is frustrated, requiring an information exposure specific to the region.”…””}”(hjæh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KùhjÕh²hubeh}”(h]”Œdynamic-memory-base”ah ]”h"]”Œdynamic memory base”ah$]”h&]”uh1hµhjVh²hh³hÊh´K÷ubh¶)”}”(hhh]”(h»)”}”(hŒStructure layout”h]”hŒStructure layout”…””}”(hjÿh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjüh²hh³hÊh´MubhÌ)”}”(hŒÚBy performing a per-build randomization of the layout of sensitive structures, attacks must either be tuned to known kernel builds or expose enough kernel memory to determine structure layouts before manipulating them.”h]”hŒÚBy performing a per-build randomization of the layout of sensitive structures, attacks must either be tuned to known kernel builds or expose enough kernel memory to determine structure layouts before manipulating them.”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Mhjüh²hubeh}”(h]”Œstructure-layout”ah ]”h"]”Œstructure layout”ah$]”h&]”uh1hµhjVh²hh³hÊh´Mubeh}”(h]”Œ/kernel-address-space-layout-randomization-kaslr”ah ]”h"]”Œ1kernel address space layout randomization (kaslr)”ah$]”h&]”uh1hµhjôh²hh³hÊh´KÝubeh}”(h]”Œprobabilistic-defenses”ah ]”h"]”Œprobabilistic defenses”ah$]”h&]”uh1hµhh·h²hh³hÊh´KÄubh¶)”}”(hhh]”(h»)”}”(hŒ Preventing Information Exposures”h]”hŒ Preventing Information Exposures”…””}”(hj6h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj3h²hh³hÊh´M ubhÌ)”}”(hX Since the locations of sensitive structures are the primary target for attacks, it is important to defend against exposure of both kernel memory addresses and kernel memory contents (since they may contain kernel addresses or other sensitive things like canary values).”h]”hX Since the locations of sensitive structures are the primary target for attacks, it is important to defend against exposure of both kernel memory addresses and kernel memory contents (since they may contain kernel addresses or other sensitive things like canary values).”…””}”(hjDh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M hj3h²hubh¶)”}”(hhh]”(h»)”}”(hŒKernel addresses”h]”hŒKernel addresses”…””}”(hjUh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjRh²hh³hÊh´MubhÌ)”}”(hX_Printing kernel addresses to userspace leaks sensitive information about the kernel memory layout. Care should be exercised when using any printk specifier that prints the raw address, currently %px, %p[ad], (and %p[sSb] in certain circumstances [*]). Any file written to using one of these specifiers should be readable only by privileged processes.”h]”hX_Printing kernel addresses to userspace leaks sensitive information about the kernel memory layout. Care should be exercised when using any printk specifier that prints the raw address, currently %px, %p[ad], (and %p[sSb] in certain circumstances [*]). Any file written to using one of these specifiers should be readable only by privileged processes.”…””}”(hjch²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MhjRh²hubhÌ)”}”(hŒ‹Kernels 4.14 and older printed the raw address using %p. As of 4.15-rc1 addresses printed with the specifier %p are hashed before printing.”h]”hŒ‹Kernels 4.14 and older printed the raw address using %p. As of 4.15-rc1 addresses printed with the specifier %p are hashed before printing.”…””}”(hjqh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MhjRh²hubhÌ)”}”(hŒ†[*] If KALLSYMS is enabled and symbol lookup fails, the raw address is printed. If KALLSYMS is not enabled the raw address is printed.”h]”hŒ†[*] If KALLSYMS is enabled and symbol lookup fails, the raw address is printed. If KALLSYMS is not enabled the raw address is printed.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´MhjRh²hubeh}”(h]”Œkernel-addresses”ah ]”h"]”Œkernel addresses”ah$]”h&]”uh1hµhj3h²hh³hÊh´Mubh¶)”}”(hhh]”(h»)”}”(hŒUnique identifiers”h]”hŒUnique identifiers”…””}”(hj˜h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj•h²hh³hÊh´M ubhÌ)”}”(hŒ•Kernel memory addresses must never be used as identifiers exposed to userspace. Instead, use an atomic counter, an idr, or similar unique identifier.”h]”hŒ•Kernel memory addresses must never be used as identifiers exposed to userspace. Instead, use an atomic counter, an idr, or similar unique identifier.”…””}”(hj¦h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M"hj•h²hubeh}”(h]”Œunique-identifiers”ah ]”h"]”Œunique identifiers”ah$]”h&]”uh1hµhj3h²hh³hÊh´M ubh¶)”}”(hhh]”(h»)”}”(hŒMemory initialization”h]”hŒMemory initialization”…””}”(hj¿h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj¼h²hh³hÊh´M'ubhÌ)”}”(hŒ¬Memory copied to userspace must always be fully initialized. If not explicitly memset(), this will require changes to the compiler to make sure structure holes are cleared.”h]”hŒ¬Memory copied to userspace must always be fully initialized. If not explicitly memset(), this will require changes to the compiler to make sure structure holes are cleared.”…””}”(hjÍh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M)hj¼h²hubeh}”(h]”Œmemory-initialization”ah ]”h"]”Œmemory initialization”ah$]”h&]”uh1hµhj3h²hh³hÊh´M'ubh¶)”}”(hhh]”(h»)”}”(hŒMemory poisoning”h]”hŒMemory poisoning”…””}”(hjæh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjãh²hh³hÊh´M.ubhÌ)”}”(hXXWhen releasing memory, it is best to poison the contents, to avoid reuse attacks that rely on the old contents of memory. E.g., clear stack on a syscall return (``CONFIG_KSTACK_ERASE``), wipe heap memory on a free. This frustrates many uninitialized variable attacks, stack content exposures, heap content exposures, and use-after-free attacks.”h]”(hŒ¡When releasing memory, it is best to poison the contents, to avoid reuse attacks that rely on the old contents of memory. E.g., clear stack on a syscall return (”…””}”(hjôh²hh³Nh´Nubj])”}”(hŒ``CONFIG_KSTACK_ERASE``”h]”hŒCONFIG_KSTACK_ERASE”…””}”(hjüh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j\hjôubhŒ ), wipe heap memory on a free. This frustrates many uninitialized variable attacks, stack content exposures, heap content exposures, and use-after-free attacks.”…””}”(hjôh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M0hjãh²hubeh}”(h]”Œmemory-poisoning”ah ]”h"]”Œmemory poisoning”ah$]”h&]”uh1hµhj3h²hh³hÊh´M.ubh¶)”}”(hhh]”(h»)”}”(hŒDestination tracking”h]”hŒDestination tracking”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjh²hh³hÊh´M7ubhÌ)”}”(hXTo help kill classes of bugs that result in kernel addresses being written to userspace, the destination of writes needs to be tracked. If the buffer is destined for userspace (e.g. seq_file backed ``/proc`` files), it should automatically censor sensitive values.”h]”(hŒÆTo help kill classes of bugs that result in kernel addresses being written to userspace, the destination of writes needs to be tracked. If the buffer is destined for userspace (e.g. seq_file backed ”…””}”(hj-h²hh³Nh´Nubj])”}”(hŒ ``/proc``”h]”hŒ/proc”…””}”(hj5h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j\hj-ubhŒ9 files), it should automatically censor sensitive values.”…””}”(hj-h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´M9hjh²hubeh}”(h]”Œdestination-tracking”ah ]”h"]”Œdestination tracking”ah$]”h&]”uh1hµhj3h²hh³hÊh´M7ubeh}”(h]”Œ preventing-information-exposures”ah ]”h"]”Œ preventing information exposures”ah$]”h&]”uh1hµhh·h²hh³hÊh´M ubeh}”(h]”Œkernel-self-protection”ah ]”h"]”Œkernel self-protection”ah$]”h&]”uh1hµhhh²hh³hÊh´Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÊuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(hºNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jˆŒerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÊŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(jbj_jõjòjQjNj­jªj"jjIjFj¦j£jíjêjñjîjMjJjtjqj›j˜jÂj¿jéjæj0j-jSjPj(j%j«j¨jÒjÏjùjöj jjZjWj’jj¹j¶jàjÝjjjRjOuŒ nametypes”}”(jb‰jõ‰jQ‰j­‰j"‰jI‰j¦‰jí‰jñ‰jM‰jt‰j›‰j‰jé‰j0‰jS‰j(‰j«‰jÒ‰jù‰j ‰jZ‰j’‰j¹‰jà‰j‰jR‰uh}”(j_h·jòh÷jNjjªj5jj°jFj%j£jTjêj©jîjøjJjjqjPj˜jwj¿jžjæjÅj-jôjPjj%jVj¨jujÏj®jöjÕjjüjWj3jjRj¶j•jÝj¼jjãjOjuŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nh²hub.