{"id":1121,"date":"2018-04-12T17:04:22","date_gmt":"2018-04-13T00:04:22","guid":{"rendered":"https:\/\/outflux.net\/blog\/?p=1121"},"modified":"2019-02-26T11:58:05","modified_gmt":"2019-02-26T19:58:05","slug":"security-things-in-linux-v4-16","status":"publish","type":"post","link":"https:\/\/outflux.net\/blog\/archives\/2018\/04\/12\/security-things-in-linux-v4-16\/","title":{"rendered":"security things in Linux v4.16"},"content":{"rendered":"<p>Previously: <a href=\"\/blog\/archives\/2018\/02\/05\/security-things-in-linux-v4-15\/\">v4.15<\/a>.<br \/>\n\ufffc<br \/>\nLinux kernel <a href=\"https:\/\/lkml.org\/lkml\/2018\/4\/1\/175\">v4.16 was released<\/a> last week. I really should write these posts in advance, otherwise I get distracted by the merge window. Regardless, here are some of the security things I think are interesting:<\/p>\n<p><strong>KPTI on arm64<\/strong><\/p>\n<p>Will Deacon, Catalin Marinas, and several other folks brought <a href=\"\/blog\/archives\/2018\/02\/05\/security-things-in-linux-v4-15\/\">Kernel Page Table Isolation<\/a> (via <a href=\"https:\/\/git.kernel.org\/linus\/0aebc6a440b942df6221a7765f077f02217e0114\"><code>CONFIG_UNMAP_KERNEL_AT_EL0<\/code><\/a>) to arm64. While most ARMv8+ CPUs were not vulnerable to the primary Meltdown flaw, the <a href=\"https:\/\/developer.arm.com\/support\/security-update\">Cortex-A75<\/a> does need KPTI to be safe from memory content leaks. It&#8217;s worth noting, though, that KPTI does protect other ARMv8+ CPU models from having <a href=\"https:\/\/github.com\/lgeek\/spec_poc_arm\">privileged register contents exposed<\/a>. So, whatever your threat model, it&#8217;s very nice to have this clean isolation between kernel and userspace page tables for all ARMv8+ CPUs.<\/p>\n<p><strong>hardened usercopy whitelisting<\/strong><\/p>\n<p>While whole-object bounds checking was implemented in <a href=\"\/blog\/archives\/2016\/10\/04\/security-things-in-linux-v4-8\/\">CONFIG_HARDENED_USERCOPY already<\/a>, David Windsor and I finished another part of the porting work of grsecurity&#8217;s PAX_USERCOPY protection: <a href=\"https:\/\/git.kernel.org\/linus\/afcc90f8621e289cd082ba97900e76f01afe778c\">usercopy whitelisting<\/a>. This further tightens the scope of slab allocations that can be copied to\/from userspace. Now, instead of allowing all objects in slab memory to be copied, only the whitelisted areas (where a subsystem has specifically marked the memory region allowed) can be copied. For example, only the <a href=\"https:\/\/git.kernel.org\/linus\/07dcd7fe89938934ddad65f738bc5aac89b8e54d\">auxv array out of the larger mm_struct<\/a>.<\/p>\n<p>As mentioned in the <a href=\"https:\/\/git.kernel.org\/linus\/8eb8284b412906181357c2b0110d879d5af95e52\">first commit from the series<\/a>, this reduces the scope of slab memory that could be copied out of the kernel in the face of a bug to under 15%. As can be seen, one area of work remaining are the <code>kmalloc<\/code> regions. Those are regularly used for copying things in and out of userspace, but they&#8217;re also used for small simple allocations that aren&#8217;t meant to be exposed to userspace. Working to separate these <code>kmalloc<\/code> users needs some careful auditing.<\/p>\n<pre>\r\n<blockquote>Total Slab Memory:           48074720\r\nUsercopyable Memory:          6367532  13.2%\r\n         task_struct                    0.2%         4480\/1630720\r\n         RAW                            0.3%            300\/96000\r\n         RAWv6                          2.1%           1408\/64768\r\n         ext4_inode_cache               3.0%       269760\/8740224\r\n         dentry                        11.1%       585984\/5273856\r\n         mm_struct                     29.1%         54912\/188448\r\n         kmalloc-8                    100.0%          24576\/24576\r\n         kmalloc-16                   100.0%          28672\/28672\r\n         kmalloc-32                   100.0%          81920\/81920\r\n         kmalloc-192                  100.0%          96768\/96768\r\n         kmalloc-128                  100.0%        143360\/143360\r\n         names_cache                  100.0%        163840\/163840\r\n         kmalloc-64                   100.0%        167936\/167936\r\n         kmalloc-256                  100.0%        339968\/339968\r\n         kmalloc-512                  100.0%        350720\/350720\r\n         kmalloc-96                   100.0%        455616\/455616\r\n         kmalloc-8192                 100.0%        655360\/655360\r\n         kmalloc-1024                 100.0%        812032\/812032\r\n         kmalloc-4096                 100.0%        819200\/819200\r\n         kmalloc-2048                 100.0%      1310720\/1310720\r\n<\/blockquote>\r\n<\/pre>\n<p>This series took quite a while to land (you can see David&#8217;s original patch date as back in June of last year). Partly this was due to having to spend a lot of time researching the code paths so that each whitelist could be explained for commit logs, partly due to making various adjustments from maintainer feedback, and partly due to the short merge window in v4.15 (when it was originally proposed for merging) combined with some last-minute glitches that made Linus nervous. After baking in <code>linux-next<\/code> for almost two full development cycles, it finally landed. (Though be sure to <em>disable<\/em> <code>CONFIG_HARDENED_USERCOPY_FALLBACK<\/code> to gain enforcement of the whitelists &#8212; by default it only warns and falls back to the full-object checking.)<\/p>\n<p><strong>automatic stack-protector<\/strong><\/p>\n<p>While the stack-protector features of the kernel have existed for quite some time, it has never been enabled by default. This was mainly due to needing to evaluate compiler support for the feature, and <code>Kconfig<\/code> didn&#8217;t have a way to check the compiler features before offering <code>CONFIG_*<\/code> options. As a defense technology, the stack protector is pretty mature. Having it on by default would have greatly reduced the impact of things like the <a href=\"https:\/\/www.armis.com\/blueborne\/\">BlueBorne<\/a> attack (CVE-2017-1000251), as fewer systems would have lacked the defense.<\/p>\n<p>After spending quite a bit of time <a href=\"https:\/\/patchwork.kernel.org\/patch\/10012347\/\">fighting <\/a>with ancient compiler versions (*cough*GCC 4.4.4*cough*), I landed <a href=\"https:\/\/git.kernel.org\/linus\/44c6dc940b190cf22b044a784f3e00a7e7f08b2f\"><code>CONFIG_CC_STACKPROTECTOR_AUTO<\/code><\/a>, which is default on, and tries to use the stack protector if it is available. The implementation of the solution, however, did not please Linus, though he allowed it to be merged. In the future, <a href=\"https:\/\/patchwork.kernel.org\/patch\/10309269\/\">Kconfig will gain the knowledge to make better decisions<\/a> which lets the kernel expose the availability of (the now default) stack protector directly in <code>Kconfig<\/code>, rather than depending on rather ugly <code>Makefile<\/code> hacks.<\/p>\n<p><strong>execute-only memory for PowerPC<\/strong><\/p>\n<p>Similar to the Protection Keys (<a href=\"http:\/\/man7.org\/linux\/man-pages\/man7\/pkeys.7.html\">pkeys<\/a>) hardware support that landed in <a href=\"\/blog\/archives\/2016\/09\/30\/security-things-in-linux-v4-6\/\">v4.6 for x86<\/a>, Ram Pai landed <a href=\"https:\/\/git.kernel.org\/linus\/03f51d4efa2287cc628bb20b0c032036d2a9e66a\">pkeys support for Power7\/8\/9<\/a>. This should expand the scope of what&#8217;s possible in the dynamic loader to avoid having arbitrary read flaws allow an exploit to read out all of executable memory in order to find ROP gadgets.<\/p>\n<p>That&#8217;s it for now; let me know if you think I should add anything! The <a href=\"https:\/\/outflux.net\/blog\/archives\/2018\/06\/14\/security-things-in-linux-v4-17\/\">v4.17<\/a> merge window is open. :)<\/p>\n<p><em>Edit<\/em>: added details on ARM register leaks, thanks to Daniel Micay.<\/p>\n<p><em>Edit<\/em>: added section on protection keys for POWER, thanks to Florian Weimer.<\/p>\n<p style='text-align:left'>&copy; 2018 &#8211; 2019, <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: v4.15. \ufffc Linux kernel v4.16 was released last week. I really should write these posts in advance, otherwise I get distracted by the merge window. Regardless, here are some of the security things I think are interesting: KPTI on arm64 Will Deacon, Catalin Marinas, and several other folks brought Kernel Page Table Isolation (via [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,18,21,6,14,19],"tags":[],"_links":{"self":[{"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/1121"}],"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=1121"}],"version-history":[{"count":18,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/1121\/revisions"}],"predecessor-version":[{"id":1237,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/1121\/revisions\/1237"}],"wp:attachment":[{"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/media?parent=1121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/categories?post=1121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/tags?post=1121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}