{"id":1406,"date":"2020-05-27T13:04:24","date_gmt":"2020-05-27T20:04:24","guid":{"rendered":"https:\/\/outflux.net\/blog\/?p=1406"},"modified":"2020-09-02T16:23:18","modified_gmt":"2020-09-02T23:23:18","slug":"security-things-in-linux-v5-5","status":"publish","type":"post","link":"https:\/\/outflux.net\/blog\/archives\/2020\/05\/27\/security-things-in-linux-v5-5\/","title":{"rendered":"security things in Linux v5.5"},"content":{"rendered":"<p>Previously: <a href=\"\/blog\/archives\/2020\/02\/18\/security-things-in-linux-v5-4\/\">v5.4<\/a>.<\/p>\n<p>I got a bit behind on this blog post series! Let&#8217;s get caught up. Here are a bunch of security things I found interesting in the <a href=\"https:\/\/lore.kernel.org\/lkml\/CAHk-=wigRZ6TSJU09bMk3Df2DiOw83B7TrQUq+iXroQCK5EVAQ@mail.gmail.com\/\">Linux kernel v5.5 release<\/a>:<\/p>\n<p><strong>restrict <code>perf_event_open()<\/code> from LSM<\/strong><br \/>\nGiven the recurring flaws in the perf subsystem, there has been a strong desire to be able to entirely disable the interface. While the <code>kernel.perf_event_paranoid<\/code> sysctl knob has existed for a while, attempts to extend its control to &#8220;block all <code>perf_event_open()<\/code> calls&#8221; have <a href=\"https:\/\/lwn.net\/Articles\/696216\/\">failed in the past<\/a>. Distribution kernels have carried the rejected sysctl patch for many years, but now Joel Fernandes has implemented a solution that was deemed acceptable: instead of extending the sysctl, <a href=\"https:\/\/git.kernel.org\/linus\/da97e18458fb42d7c00fac5fd1c56a3896ec666e\">add LSM hooks<\/a> so that LSMs (e.g. SELinux, Apparmor, etc) can make these choices as part of their overall system policy.<\/p>\n<p><strong>generic fast full <code>refcount_t<\/code><\/strong><br \/>\nWill Deacon took the recent <code>refcount_t<\/code> hardening work for both x86 and arm64 and distilled the implementations into a <a href=\"https:\/\/git.kernel.org\/linus\/dcb786493f3e48da3272b710028d42ec608cfda1\">single architecture-agnostic C version<\/a>. The result was almost as fast as the x86 assembly version, but it covered more cases (e.g. increment-from-zero), and is now available by <a href=\"https:\/\/git.kernel.org\/linus\/fb041bb7c0a918b95c6889fc965cdc4a75b4c0ca\">default for all architectures<\/a>. (There is no longer any Kconfig associated with <code>refcount_t<\/code>; the use of the primitive provides full coverage.)<\/p>\n<p><strong>linker script cleanup for exception tables<\/strong><br \/>\nWhen Rick Edgecombe <a href=\"https:\/\/www.youtube.com\/watch?v=BkRI9TFS8Eo&#038;list=PLVsQ_xZBEyN2Ol7y8axxhbTsG47Va3Se2&#038;index=10&#038;t=0s\">presented<\/a> his work on building <a href=\"https:\/\/linuxplumbersconf.org\/event\/4\/contributions\/283\/\">Execute-Only memory under a hypervisor<\/a>, he noted a region of memory that the kernel was attempting to read directly (instead of execute). He rearranged things for his x86-only patch series to <a href=\"https:\/\/github.com\/redgecombe\/linux\/commit\/428f889a5c52ca85b763cf484ed666a33259b6ef\">work around<\/a> the issue. Since I&#8217;d just been working in this area, I realized the root cause of this problem was the location of the exception table (which is strictly a lookup table and is never executed) and built a <a href=\"https:\/\/git.kernel.org\/linus\/b8c2f776164c8f74ac31c5e370ca3f029be0aa19\">fix for the issue<\/a> and applied it to <a href=\"https:\/\/lore.kernel.org\/linux-arm-kernel\/20191029211351.13243-1-keescook@chromium.org\/#r\">all architectures<\/a>, since it turns out the exception tables for almost all architectures are just a data table. Hopefully this will help clear the path for more Execute-Only memory work on all architectures. In the process of this, I also updated the <a href=\"https:\/\/git.kernel.org\/linus\/7705dc8557973d8ad8f10840f61d8ec805695e9e\">section fill bytes on x86 to be a trap<\/a> (0xCC, int3), instead of a NOP instruction so functions would need to be targeted more precisely by attacks.<\/p>\n<p><strong>KASLR for 32-bit PowerPC<\/strong><br \/>\nJoining many other architectures, Jason Yan added kernel text base-address offset randomization <a href=\"https:\/\/git.kernel.org\/linus\/2b0e86cc5de6dabadc2d64cefa429fc227c8a756\">(KASLR) to 32-bit PowerPC<\/a>.<\/p>\n<p><strong>seccomp for RISC-V<\/strong><br \/>\nAfter a bit of long road, David Abdurachmanov has added <a href=\"https:\/\/git.kernel.org\/linus\/5340627e3fe08030988bdda46dd86cd5d5fb7517\">seccomp support to the RISC-V architecture<\/a>. The series uncovered some more corner cases in the seccomp self tests code, which is always nice since then we get to make it more robust for the future!<\/p>\n<p><strong>seccomp <code>USER_NOTIF<\/code> continuation<\/strong><br \/>\nWhen the <a href=\"\/blog\/archives\/2019\/03\/12\/security-things-in-linux-v5-0\/\">seccomp <code>SECCOMP_RET_USER_NOTIF<\/code> interface<\/a> was added, it seemed like it would only be used in very limited conditions, so the idea of needing to handle &#8220;normal&#8221; requests didn&#8217;t seem very onerous. However, since then, it has become clear that the overhead of a monitor process needing to perform lots of &#8220;normal&#8221; <code>open()<\/code> calls on behalf of the monitored process started to look more and more slow and fragile. To deal with this, it became clear that there needed to be a way for the <code>USER_NOTIF<\/code> interface to indicate that seccomp should just continue as normal and allow the syscall without any special handling. Christian Brauner <a href=\"https:\/\/git.kernel.org\/linus\/fb3c5386b382d4097476ce9647260fc89b34afdb\">implemented <code>SECCOMP_USER_NOTIF_FLAG_CONTINUE<\/code><\/a> to get this done. It comes with a bit of a disclaimer due to the chance that monitors may use it in places where ToCToU is a risk, and for possible conflicts with <code>SECCOMP_RET_TRACE<\/code>. But overall, this is a net win for container monitoring tools.<\/p>\n<p><strong><code>EFI_RNG_PROTOCOL<\/code> for x86<\/strong><br \/>\nSome EFI systems provide a Random Number Generator interface, which is useful for gaining some entropy in the kernel during very early boot. The arm64 boot stub has been using this for a while now, but Dominik Brodowski has now added support for <a href=\"https:\/\/git.kernel.org\/linus\/0d95981438c3bdb53cc99b0fb656d24d7a80e1f3\">x86 to do the same<\/a>. This entropy is useful for kernel subsystems performing very earlier initialization whre random numbers are needed (like <a href=\"https:\/\/lore.kernel.org\/lkml\/202003051623.AF4F8CB@keescook\/\">randomizing aspects of the SLUB memory allocator<\/a>).<\/p>\n<p><strong><code>FORTIFY_SOURCE<\/code> for MIPS<\/strong><br \/>\nAs has been enabled on many other architectures, Dmitry Korotin got <a href=\"https:\/\/git.kernel.org\/linus\/a2ecb233e3e759730269b31b7d8add823cf196ba\">MIPS building with <code>CONFIG_FORTIFY_SOURCE<\/code><\/a>, so compile-time (and some run-time) buffer overflows during calls to the <code>memcpy()<\/code> and <code>strcpy()<\/code> families of functions will be <a href=\"\/blog\/archives\/2017\/09\/05\/security-things-in-linux-v4-13\/\">detected<\/a>.<\/p>\n<p><strong>limit <code>copy_{to,from}_user()<\/code> size to <code>INT_MAX<\/code><\/strong><br \/>\nAs done for VFS, <code>vsnprintf()<\/code>, and <a href=\"\/blog\/archives\/2020\/02\/18\/security-things-in-linux-v5-4\/\"><code>strscpy()<\/code><\/a>, I went ahead and <a href=\"https:\/\/git.kernel.org\/linus\/6d13de1489b6bf539695f96d945de3860e6d5e17\">limited the size<\/a> of <code>copy_to_user()<\/code> and <code>copy_from_user()<\/code> calls to <code>INT_MAX<\/code> in order to catch any weird overflows in size calculations.<\/p>\n<p><strong>Other things<\/strong><br \/>\n<a href=\"https:\/\/twitter.com\/a13xp0p0v\/status\/1270109939474804740\">Alexander Popov pointed out some more v5.5 features<\/a> that I missed in this blog post. I&#8217;m repeating them here, with some minor edits\/clarifications. Thank you Alexander!<\/p>\n<ul>\n<li><a href=\"https:\/\/git.kernel.org\/linus\/3c5c3cfb9ef4da957e3357a2bd36f76ee34c0862\">KASan support for vmap memory<\/a> expands KASan&#8217;s features to include analysis of memory allocated with <code>vmalloc()<\/code>. More specifically, this means KASan can examine the stack again, since it can be in that region since <code>CONFIG_VMAP_STACK<\/code> was introduced.<\/li>\n<li><a href=\"https:\/\/git.kernel.org\/linus\/dcf78ee660888d8302a0f0888bf746a164d267fa\">MIPS can build with GCC plugins and KCOV<\/a> now, providing those systems with the associated features like stack wiping, coverage analysis, etc.<\/li>\n<li><a href=\"https:\/\/git.kernel.org\/linus\/3c1c24d91ffd536de0a64688a9df7f49e58fadbc\">userfaultfd requires CAP_SYS_PTRACE for UFFD_FEATURE_EVENT_FORK<\/a>. This was done to block unprivileged users from abusing the userfaultfd feature, as it is implemented in a way that provides the ability to <a href=\"https:\/\/lore.kernel.org\/linux-api\/CALCETrWY+5ynDct7eU_nDUqx=okQvjm=Y5wJvA4ahBja=CQXGw@mail.gmail.com\/\">inject file descriptors into unsuspecting processes<\/a>.<\/li>\n<\/ul>\n<p><em>Edit: added Alexander Popov&#8217;s notes<\/em><\/p>\n<p>That&#8217;s it for v5.5! Let me know if there&#8217;s anything else that I should call out here. Next up: Linux <a href=\"\/blog\/archives\/2020\/09\/02\/security-things-in-linux-v5-6\/\">v5.6<\/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.4. I got a bit behind on this blog post series! Let&#8217;s get caught up. Here are a bunch of security things I found interesting in the Linux kernel v5.5 release: restrict perf_event_open() from LSM Given the recurring flaws in the perf subsystem, there has been a strong desire to be able to entirely [&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\/1406"}],"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=1406"}],"version-history":[{"count":24,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/1406\/revisions"}],"predecessor-version":[{"id":1455,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/1406\/revisions\/1455"}],"wp:attachment":[{"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/media?parent=1406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/categories?post=1406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/tags?post=1406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}