{"id":1349,"date":"2019-11-14T17:36:21","date_gmt":"2019-11-15T01:36:21","guid":{"rendered":"https:\/\/outflux.net\/blog\/?p=1349"},"modified":"2020-08-03T14:51:39","modified_gmt":"2020-08-03T21:51:39","slug":"security-things-in-linux-v5-3","status":"publish","type":"post","link":"https:\/\/outflux.net\/blog\/archives\/2019\/11\/14\/security-things-in-linux-v5-3\/","title":{"rendered":"security things in Linux v5.3"},"content":{"rendered":"<p>Previously: <a href=\"\/blog\/archives\/2019\/07\/17\/security-things-in-linux-v5-2\/\">v5.2<\/a>.<\/p>\n<p>Linux kernel <a href=\"https:\/\/lore.kernel.org\/lkml\/CAHk-=wiP4K8DRJWsCo=20hn_6054xBamGKF2kPgUzpB5aMaofA@mail.gmail.com\/\">v5.3 was released<\/a>! I let this blog post get away from me, but it&#8217;s up now! :) Here are some security-related things I found interesting:<\/p>\n<p><strong>heap variable initialization<\/strong><br \/>\nIn the continuing work to <a href=\"\/blog\/archives\/2019\/07\/17\/security-things-in-linux-v5-2\/\">remove &#8220;uninitialized&#8221; variables<\/a> from the kernel, Alexander Potapenko added new <a href=\"https:\/\/git.kernel.org\/linus\/6471384af2a6530696fc0203bafe4de41a23c9ef\">&#8220;<code>init_on_alloc<\/code>&#8221; and &#8220;<code>init_on_free<\/code>&#8221; boot parameters<\/a> (with associated Kconfig defaults) to perform zeroing of heap memory either at allocation time (i.e. all <code>kmalloc()<\/code>s effectively become <code>kzalloc()<\/code>s), at free time (i.e. all <code>kfree()<\/code>s effectively become <code>kzfree()<\/code>s), or both. The performance impact of the former under most workloads appears to be under 1%, if it&#8217;s measurable at all. The &#8220;init_on_free&#8221; option, however, is more costly but adds the benefit of reducing the lifetime of heap contents after they have been freed (which might be useful for some use-after-free attacks or side-channel attacks). Everyone should enable <code>CONFIG_INIT_ON_ALLOC_DEFAULT_ON=1<\/code> (or boot with &#8220;<code>init_on_alloc=1<\/code>&#8220;), and the more paranoid system builders should add <code>CONFIG_INIT_ON_FREE_DEFAULT_ON=1<\/code> (or &#8220;<code>init_on_free=1<\/code>&#8221; at boot). As workloads are found that cause performance concerns, tweaks to the initialization coverage can be added.<\/p>\n<p><strong><code>pidfd_open()<\/code> added<\/strong><br \/>\nChristian Brauner has continued his <a href=\"\/blog\/archives\/2019\/07\/17\/security-things-in-linux-v5-2\/\"><code>pidfd<\/code> work<\/a> by <a href=\"https:\/\/git.kernel.org\/linus\/32fcb426ec001cb6d5a4a195091a8486ea77e2df\">creating the next needed syscall: <code>pidfd_open()<\/code><\/a>, which takes a <code>pid<\/code> and returns a <code>pidfd<\/code>. This is useful for cases where process creation isn&#8217;t yet using <code>CLONE_PIDFD<\/code>, and where <code>\/proc<\/code> may not be mounted.<\/p>\n<p><strong><code>-Wimplicit-fallthrough<\/code> enabled globally<\/strong><br \/>\nGustavo A.R. Silva landed the last handful of <a href=\"\/blog\/archives\/2019\/07\/17\/security-things-in-linux-v5-2\/\">implicit fallthrough<\/a> fixes left in the kernel, which allows for <a href=\"https:\/\/git.kernel.org\/linus\/88c5083442454e5e8a505b11fa16f32d2879651e\"><code>-Wimplicit-fallthrough<\/code> to be globally enabled<\/a> for all kernel builds. This will keep any new instances of this bad code pattern from entering the kernel again. With several hundred implicit fallthroughs identified and fixed, something like 1 in 10 were missing breaks, which is way higher than I was expecting, making this work even more well justified.<\/p>\n<p><strong>x86 CR4 &#038; CR0 pinning<\/strong><br \/>\nIn <a href=\"https:\/\/googleprojectzero.blogspot.com\/2017\/05\/exploiting-linux-kernel-via-packet.html\">recent exploits<\/a>, one of the steps for making the attacker&#8217;s life easier is to disable CPU protections like Supervisor Mode Access (and Execute) Prevention (SMAP and SMEP) by finding a way to write to CPU control registers to disable these features. For example, CR4 controls SMAP and SMEP, where disabling those would let an attacker access and execute userspace memory from kernel code again, opening up the attack to much greater flexibility. CR0 controls Write Protect (WP), which when disabled would allow an attacker to write to read-only memory like the kernel code itself. Attacks have been using the kernel&#8217;s CR4 and CR0 writing functions to make these changes (since it&#8217;s easier to gain that level of execute control), but now the kernel will attempt to <a href=\"https:\/\/git.kernel.org\/linus\/873d50d58f67ef15d2777b5e7f7a5268bb1fbae2\">&#8220;pin&#8221; sensitive bits in CR4<\/a> and <a href=\"https:\/\/git.kernel.org\/linus\/8dbec27a242cd3e2816eeb98d3237b9f57cf6232\">CR0<\/a> to avoid them getting disabled. This forces attacks to do more work to enact such register changes going forward. (I&#8217;d like to see KVM enforce this too, which would actually protect guest kernels from all attempts to change protected register bits.)<\/p>\n<p><strong>additional <code>kfree()<\/code> sanity checking<\/strong><br \/>\nIn order to avoid corrupted pointers doing crazy things when they&#8217;re freed (as seen in <a href=\"https:\/\/github.com\/ThomasKing2014\/slides\/raw\/master\/Building%20universal%20Android%20rooting%20with%20a%20type%20confusion%20vulnerability.pdf\">recent exploits<\/a>), I added additional sanity checks to <a href=\"https:\/\/git.kernel.org\/linus\/598a0717a816abc8f5d3c4598628338b9190d127\">verify kmem cache membership<\/a> and to make sure that <a href=\"https:\/\/git.kernel.org\/linus\/a64b53780ec35b77daf817210c88aa42d172c98f\">objects actually belong to the kernel slab heap<\/a>. As a reminder, everyone should be building with <code>CONFIG_SLAB_FREELIST_HARDENED=1<\/code>.<\/p>\n<p><strong>KASLR enabled by default on arm64<\/strong><br \/>\nJust as Kernel Address Space Layout Randomization (KASLR) was <a href=\"\/blog\/archives\/2017\/07\/10\/security-things-in-linux-v4-12\/\">enabled by default on x86<\/a>, now <a href=\"https:\/\/git.kernel.org\/linus\/8049672bb17a53f2545fbeaa6cfbb48055f51cde\">KASLR has been enabled by default on arm64<\/a> too. It&#8217;s worth noting, though, that in order to benefit from this setting, the bootloader used for such arm64 systems needs to either support the UEFI RNG function or provide entropy via the &#8220;<code>\/chosen\/kaslr-seed<\/code>&#8221; Device Tree property.<\/p>\n<p><strong>hardware security embargo documentation<\/strong><br \/>\nAs there continues to be a long tail of hardware flaws that need to be reported to the Linux kernel community under embargo, a well-defined <a href=\"https:\/\/git.kernel.org\/linus\/ddaedbbece90add970faeac87f7d7d40341936ce\">process has been documented<\/a>. This will let vendors unfamiliar with how to handle things follow the established best practices for interacting with the Linux kernel community in a way that lets mitigations get developed before embargoes are lifted. The latest (and HTML rendered) version of this process should always be available <a href=\"https:\/\/www.kernel.org\/doc\/html\/latest\/process\/embargoed-hardware-issues.html\">here<\/a>.<\/p>\n<p>Those are the things I had on my radar. Please let me know if there are other things I should add! <a href=\"\/blog\/archives\/2020\/02\/18\/security-things-in-linux-v5-4\/\">Linux v5.4<\/a> is almost here&#8230;<\/p>\n<p style='text-align:left'>&copy; 2019 &#8211; 2020, <a href=\"https:\/\/outflux.net\/blog\/\">Kees Cook<\/a>. This work is licensed under a <a rel=\"license\" href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/\">Creative Commons Attribution-ShareAlike 4.0 License<\/a>.<br \/><a rel=\"license\" href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/\"><img decoding=\"async\" alt=\"CC BY-SA 4.0\" style=\"border-width:0\" src=\"https:\/\/i.creativecommons.org\/l\/by-sa\/4.0\/88x31.png\" \/><\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Previously: v5.2. Linux kernel v5.3 was released! I let this blog post get away from me, but it&#8217;s up now! :) Here are some security-related things I found interesting: heap variable initialization In the continuing work to remove &#8220;uninitialized&#8221; variables from the kernel, Alexander Potapenko added new &#8220;init_on_alloc&#8221; and &#8220;init_on_free&#8221; boot parameters (with associated Kconfig [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,20,18,21,6,14,19],"tags":[],"_links":{"self":[{"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/1349"}],"collection":[{"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/comments?post=1349"}],"version-history":[{"count":19,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/1349\/revisions"}],"predecessor-version":[{"id":1401,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/1349\/revisions\/1401"}],"wp:attachment":[{"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/media?parent=1349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/categories?post=1349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/tags?post=1349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}