{"id":1390,"date":"2020-02-18T16:37:02","date_gmt":"2020-02-19T00:37:02","guid":{"rendered":"https:\/\/outflux.net\/blog\/?p=1390"},"modified":"2020-08-03T14:52:00","modified_gmt":"2020-08-03T21:52:00","slug":"security-things-in-linux-v5-4","status":"publish","type":"post","link":"https:\/\/outflux.net\/blog\/archives\/2020\/02\/18\/security-things-in-linux-v5-4\/","title":{"rendered":"security things in Linux v5.4"},"content":{"rendered":"<p>Previously: <a href=\"\/blog\/archives\/2019\/11\/14\/security-things-in-linux-v5-3\/\">v5.3<\/a>.<\/p>\n<p>Linux kernel <a href=\"https:\/\/lore.kernel.org\/lkml\/CAHk-=wjmzaD=BZ1hjUYu+RTnSGDLfCRwCdg99GeQpCjEwo9uzw@mail.gmail.com\/\">v5.4 was released<\/a> in late November. The holidays got the best of me, but better late than never! ;) Here are some security-related things I found interesting:<\/p>\n<p><strong><code>waitid()<\/code> gains <code>P_PIDFD<\/code><\/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\/3695eae5fee0605f316fbaad0b9e3de791d7dfaf\">adding a critical mode to <code>waitid()<\/code>: <code>P_PIDFD<\/code><\/a>. This makes it possible to reap child processes via a <code>pidfd<\/code>, and completes the interfaces needed for the bulk of programs performing process lifecycle management. (i.e. a <code>pidfd<\/code> can come from <code>\/proc<\/code> or <code>clone()<\/code>, and can be waited on with <code>waitid()<\/code>.)<\/p>\n<p><strong>kernel lockdown<\/strong><br \/>\nAfter something on the order of <a href=\"https:\/\/lwn.net\/Articles\/514985\/\">8 years<\/a>, Linux can now <a href=\"https:\/\/git.kernel.org\/linus\/000d388ed3bbed745f366ce71b2bb7c2ee70f449\">draw a bright line<\/a> between &#8220;ring 0&#8221; (kernel memory) and &#8220;uid 0&#8221; (highest privilege level in userspace). The &#8220;kernel lockdown&#8221; feature, which has been an out-of-tree patch series in most Linux distros for almost as many years, attempts to enumerate all the <em>intentional<\/em> ways (i.e. interfaces not flaws) userspace might be able to read or modify kernel memory (or execute in kernel space), and disable them. While Matthew Garrett made the internal details fine-grained controllable, the basic lockdown LSM can be set to either disabled, &#8220;integrity&#8221; (kernel memory can be read but not written), or &#8220;confidentiality&#8221; (no kernel memory reads or writes). Beyond closing the many holes between userspace and the kernel, if new interfaces are added to the kernel that might violate kernel integrity or confidentiality, now there is a place to put the access control to make everyone happy and there doesn&#8217;t need to be a rehashing of the age old fight between &#8220;but root has full kernel access&#8221; vs &#8220;not in some system configurations&#8221;.<\/p>\n<p><strong>tagged memory relaxed syscall ABI<\/strong><br \/>\nAndrey Konovalov (with Catalin Marinas and others) introduced a way to enable a <a href=\"https:\/\/git.kernel.org\/linus\/63f0c60379650d82250f22e4cf4137ef3dc4f43d\">&#8220;relaxed&#8221; tagged memory syscall ABI<\/a> in the kernel. This means programs running on hardware that supports <a href=\"https:\/\/www.linuxplumbersconf.org\/event\/4\/contributions\/571\/attachments\/399\/642\/MTE_LPC.pdf\">memory tags<\/a> (or &#8220;versioning&#8221;, or &#8220;coloring&#8221;) in the upper (non-VMA) bits of a pointer address can use these addresses with the kernel without things going crazy. This is effectively teaching the kernel to ignore these high bits in places where they make no sense (i.e. mathematical comparisons) and keeping them in place where they have meaning (i.e. pointer dereferences).<\/p>\n<p>As an example, if a userspace memory allocator had returned the address 0x0<strong>f<\/strong>00000010000000 (VMA address 0x10000000, with, say, a &#8220;high bits&#8221; tag of 0x0f), and a program used this range during a syscall that ultimately called <code>copy_from_user()<\/code> on it, the initial range check would fail if the tag bits were left in place: &#8220;that&#8217;s not a userspace address; it is greater than <code>TASK_SIZE<\/code> (0x0000800000000000)!&#8221;, so they are stripped for that check. During the actual copy into kernel memory, the tag is left in place so that when the hardware dereferences the pointer, the pointer tag can be checked against the expected tag assigned to referenced memory region. If there is a mismatch, the hardware will trigger the memory tagging protection.<\/p>\n<p>Right now programs running on Sparc M7 CPUs with ADI (Application Data Integrity) can use this for hardware tagged memory, ARMv8 CPUs can use TBI (Top Byte Ignore) for software memory tagging, and eventually there will be ARMv8.5-A CPUs with MTE (Memory Tagging Extension).<\/p>\n<p><strong>boot entropy improvement<\/strong><br \/>\nThomas Gleixner got fed up with poor boot-time entropy and <a href=\"https:\/\/lore.kernel.org\/lkml\/alpine.DEB.2.21.1909290010500.2636@nanos.tec.linutronix.de\/\">trolled<\/a> Linus into coming up with reasonable way to <a href=\"https:\/\/git.kernel.org\/linus\/50ee7529ec4500c88f8664560770a7a1b65db72b\">add entropy on modern CPUs<\/a>, taking advantage of timing noise, cycle counter jitter, and perhaps even the variability of speculative execution. This means that there shouldn&#8217;t be mysterious multi-second (or multi-minute!) <a href=\"https:\/\/lwn.net\/Articles\/800509\/\">hangs at boot<\/a> when some systems don&#8217;t have enough entropy to service <code>getrandom()<\/code> syscalls from <code>systemd<\/code> or the like.<\/p>\n<p><strong>userspace writes to swap files blocked<\/strong><br \/>\nFrom the department of &#8220;how did this go unnoticed for so long?&#8221;, Darrick J. Wong fixed the kernel to not allow writes from userspace to active swap files. Without this, it was possible for a user (usually root) with write access to a swap file to modify its contents, thereby changing memory contents of a process once it got paged back in. While root normally could just use <code>CAP_PTRACE<\/code> to modify a running process directly, this was a loophole that allowed lesser-privileged users (e.g. anyone in the &#8220;disk&#8221; group) without the needed capabilities to still bypass ptrace restrictions.<\/p>\n<p><strong>limit <code>strscpy()<\/code> sizes to <code>INT_MAX<\/code><\/strong><br \/>\nGenerally speaking, if a size variable ends up larger than <code>INT_MAX<\/code>, some calculation somewhere has overflowed. And even if not, it&#8217;s probably going to hit code somewhere nearby that won&#8217;t deal well with the result. As already done in the VFS core, and <code>vsprintf()<\/code>, I added a check to <code>strscpy()<\/code> to <a href=\"https:\/\/git.kernel.org\/linus\/9a156466147b61504f4cbe97ea503e67c21e117a\">reject sizes larger than <code>INT_MAX<\/code><\/a>.<\/p>\n<p><strong><code>ld.gold<\/code> support removed<\/strong><br \/>\nThomas Gleixner <a href=\"https:\/\/git.kernel.org\/linus\/75959d44f9dc8e44410667009724e4e238515502\">removed support for the gold linker<\/a>. While this isn&#8217;t providing a direct security benefit, <code>ld.gold<\/code> has been a constant source of weird bugs. Specifically where I&#8217;ve noticed, it had been pain while developing KASLR, and has more recently been causing problems while stabilizing building the kernel with Clang. Having this linker support removed makes things much easier going forward. There are enough weird bugs to fix in Clang and <code>ld.lld<\/code>. ;)<\/p>\n<p><strong>Intel TSX disabled<\/strong><br \/>\nGiven the use of Intel&#8217;s Transactional Synchronization Extensions (TSX) CPU feature by attackers to exploit speculation flaws, Pawan Gupta <a href=\"https:\/\/git.kernel.org\/linus\/95c5824f75f3ba4c9e8e5a4b1a623c95390ac266\">disabled the feature by default<\/a> on CPUs that support disabling TSX.<\/p>\n<p>That&#8217;s all I have for this version. Let me know if I missed anything. :) Next up is <a href=\"\/blog\/archives\/2020\/05\/27\/security-things-in-linux-v5-5\/\">Linux v5.5<\/a>!<\/p>\n<p style='text-align:left'>&copy; 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.3. Linux kernel v5.4 was released in late November. The holidays got the best of me, but better late than never! ;) Here are some security-related things I found interesting: waitid() gains P_PIDFD Christian Brauner has continued his pidfd work by adding a critical mode to waitid(): P_PIDFD. This makes it possible to reap [&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\/1390"}],"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=1390"}],"version-history":[{"count":13,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/1390\/revisions"}],"predecessor-version":[{"id":1419,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/1390\/revisions\/1419"}],"wp:attachment":[{"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/media?parent=1390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/categories?post=1390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/tags?post=1390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}