{"id":987,"date":"2016-12-12T11:05:55","date_gmt":"2016-12-12T19:05:55","guid":{"rendered":"https:\/\/outflux.net\/blog\/?p=987"},"modified":"2017-04-24T13:03:52","modified_gmt":"2017-04-24T20:03:52","slug":"security-things-in-linux-v4-9","status":"publish","type":"post","link":"https:\/\/outflux.net\/blog\/archives\/2016\/12\/12\/security-things-in-linux-v4-9\/","title":{"rendered":"security things in Linux v4.9"},"content":{"rendered":"<p>Previously: <a href=\"\/blog\/archives\/2016\/10\/04\/security-things-in-linux-v4-8\/\">v4.8<\/a>.<\/p>\n<p>Here are a bunch of security things I&#8217;m excited about in the newly released Linux v4.9:<\/p>\n<p><strong>Latent Entropy GCC plugin<\/strong><\/p>\n<p>Building on her <a href=\"\/blog\/archives\/2016\/10\/04\/security-things-in-linux-v4-8\/\">earlier work<\/a> to bring GCC plugin support to the Linux kernel, Emese Revfy ported PaX&#8217;s <a href=\"https:\/\/git.kernel.org\/linus\/38addce8b600ca335dc86fa3d48c890f1c6fa1f4\">Latent Entropy GCC plugin<\/a> to upstream. This plugin is significantly more complex than the others that have already been ported, and performs extensive instrumentation of functions <a href=\"https:\/\/git.kernel.org\/linus\/0766f788eb727e2e330d55d30545db65bcf2623f\">marked<\/a> with <code>__latent_entropy<\/code>. These functions have their branches and loops adjusted to mix random values (selected at build time) into a global entropy gathering variable. Since the branch and loop ordering is very specific to boot conditions, CPU quirks, memory layout, etc, this provides some additional uncertainty to the kernel&#8217;s entropy pool. Since the entropy actually gathered is hard to measure, no entropy is &#8220;credited&#8221;, but rather used to mix the existing pool further. Probably the best place to enable this plugin is on small devices without other strong sources of entropy.<\/p>\n<p><strong>vmapped kernel stack and thread_info relocation on x86<\/strong><\/p>\n<p>Normally, kernel stacks are mapped together in memory. This meant that attackers could use forms of stack exhaustion (or stack buffer overflows) to reach past the end of a stack and start writing over another process&#8217;s stack. This is bad, and one way to stop it is to provide guard pages between stacks, which is provided by <code>vmalloc<\/code>ed memory. Andy Lutomirski did a bunch of work to move to vmapped kernel stack via <a href=\"https:\/\/git.kernel.org\/linus\/e37e43a497d5a8b7c0cc1736d56986f432c394c9\"><code>CONFIG_VMAP_STACK<\/code><\/a> on x86_64. Now when writing past the end of the stack, the kernel will immediately fault instead of just continuing to blindly write.<\/p>\n<p>Related to this, the kernel was storing <code>thread_info<\/code> (which contained sensitive values like <code>addr_limit<\/code>) at the bottom of the kernel stack, which was an easy target for attackers to hit. Between a combination of explicitly <a href=\"https:\/\/git.kernel.org\/linus\/13d4ea097d18b419ad2a2b696063d44bf59acec0\">moving targets out of <code>thread_info<\/code><\/a>, removing needless fields, and entirely <a href=\"https:\/\/git.kernel.org\/linus\/c65eacbe290b8141554c71b2c94489e73ade8c8d\"<a>moving <code>thread_info<\/code> off the stack<\/a>, Andy Lutomirski and Linus Torvalds created <code>CONFIG_THREAD_INFO_IN_TASK<\/code> for x86.<\/p>\n<p><strong>CONFIG_DEBUG_RODATA mandatory on arm64<\/strong><\/p>\n<p>As <a href=\"\/blog\/archives\/2016\/09\/30\/security-things-in-linux-v4-6\/\">recently done for x86<\/a>, Mark Rutland made <a href=\"https:\/\/git.kernel.org\/linus\/40982fd6b975de4a51ce5147bc1d698c3b075634\">CONFIG_DEBUG_RODATA mandatory on arm64<\/a>. This feature controls whether the kernel enforces proper memory protections on its own memory regions (code memory is executable and read-only, read-only data is actually read-only and non-executable, and writable data is non-executable). This protection is a fundamental security primitive for kernel self-protection, so there&#8217;s no reason to make the protection optional.<\/p>\n<p><strong><code>random_page()<\/code> cleanup<\/strong><\/p>\n<p>Cleaning up the code around the userspace ASLR implementations makes them easier to reason about. This has been happening for things like the recent <a href=\"https:\/\/git.kernel.org\/linus\/d1fd836dcf00d2028c700c7e44d2c23404062c90\">consolidation on <code>arch_mmap_rnd()<\/code> for <code>ET_DYN<\/code><\/a> and during the <a href=\"https:\/\/git.kernel.org\/linus\/5ef11c35ce86b94bfb878b684de4cdaf96f54b2f\">addition of the entropy sysctl<\/a>. Both uncovered some awkward uses of <code>get_random_int()<\/code> (or similar) in and around <code>arch_mmap_rnd()<\/code> (which is used for <code>mmap<\/code> (and therefore shared library) and PIE ASLR), as well as in <code>randomize_stack_top()<\/code> (which is used for stack ASLR). Jason Cooper cleaned things up further by doing away with <code>randomize_range()<\/code> entirely and replacing it with the saner <a href=\"https:\/\/git.kernel.org\/linus\/99fdafdeacfa99ca9047641b684fa2aaf094a661\"<\/a><code>random_page()<\/code><\/a>, making the per-architecture <code>arch_randomize_brk()<\/code> (responsible for <code>brk<\/code> ASLR) much easier to understand.<\/p>\n<p><em>Edit: missed this next feature when I first posted!<\/em><\/p>\n<p><strong>User namespace restrictions<\/strong><\/p>\n<p>Eric Biederman <a href=\"http:\/\/git.kernel.org\/linus\/f6b2db1a3e8d141dd144df58900fb0444d5d7c53\">landed a sysctl<\/a> to control how many user namespaces can be created (on a per-user and per-namespace basis) via <code>\/proc\/sys\/user\/max_user_namespaces<\/code>. The ability to limit access to user namespaces has been <a href=\"https:\/\/lwn.net\/Articles\/673597\/\">desired for a while<\/a>, since a large amount of attack surface gets exposed from within a user namespace, due to it allowing various interfaces to operate within the namespace that were originally limited to the true root user before. A system can now disable user namespaces by writing <code>0<\/code> to the sysctl.<\/p>\n<p>That&#8217;s it for now! Let me know if there are other fun things to call attention to in <a href=\"\/blog\/archives\/2017\/02\/27\/security-things-in-linux-v4-10\/\">v4.10<\/a>.<\/p>\n<p style='text-align:left'>&copy; 2016 &#8211; 2017, <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.8. Here are a bunch of security things I&#8217;m excited about in the newly released Linux v4.9: Latent Entropy GCC plugin Building on her earlier work to bring GCC plugin support to the Linux kernel, Emese Revfy ported PaX&#8217;s Latent Entropy GCC plugin to upstream. This plugin is significantly more complex than the others [&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\/987"}],"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=987"}],"version-history":[{"count":8,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/987\/revisions"}],"predecessor-version":[{"id":1015,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/987\/revisions\/1015"}],"wp:attachment":[{"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/media?parent=987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/categories?post=987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/tags?post=987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}