Sick Gaming
Redefining Security Technology in Zephyr and Fuchsia - Printable Version

+- Sick Gaming (https://www.sickgaming.net)
+-- Forum: Computers (https://www.sickgaming.net/forum-86.html)
+--- Forum: Linux, FreeBSD, and Unix types (https://www.sickgaming.net/forum-88.html)
+--- Thread: Redefining Security Technology in Zephyr and Fuchsia (/thread-86578.html)



Redefining Security Technology in Zephyr and Fuchsia - xSicKxBot - 09-25-2018

Redefining Security Technology in Zephyr and Fuchsia

<div style="margin: 5px 5% 10px 5%;"><img src="http://www.sickgaming.net/blog/wp-content/uploads/2018/09/redefining-security-technology-in-zephyr-and-fuchsia.jpg" width="1786" height="580" title="" alt="" /></div><div><div><img src="http://www.sickgaming.net/blog/wp-content/uploads/2018/09/redefining-security-technology-in-zephyr-and-fuchsia.jpg" class="ff-og-image-inserted" /></div>
<p><span><span>If you’re the type of person who uses the word “vuln” as a shorthand for code vulnerabilities, you should check out the presentation from the recent <a href="https://events.linuxfoundation.org/events/linux-security-summit-north-america-2018/">Linux Security Summit</a> called “</span><span>Security in Zephyr and Fuchsia.” In the talk, two researchers from the National Security Agency discuss their contributions to the nascent security stacks of two open source OS projects: Zephyr and Fuchsia. </span></span></p>
<p><span><span>If you’re worried about the fact that Edward Snowden’s old employer is helping to write next generation OSes that could run our lives in 10 years, consider the upsides. First, since these are open source projects, any nefarious backdoors would be clearly visible. Second, the NSA knows a thing or two about security. Stephen Smalley and James Carter, who discussed security in Zephyr and Fuchsia, respectively, are </span><span>computer security researchers at the NSA’s Information Assurance Research group</span><span>, which developed and maintains the security-enhanced SELinux and SE Android distributions. Smalley leads </span><span>the NSA’s Security Enhancements (SE) for the Internet of Things project and is a kernel and userspace maintainer for SELinux.</span></span></p>
<p><span><span>The Linux Foundation hosted </span><a href="http://linuxgizmos.com/open-source-zephyr-rtos-snuggles-up-to-risc-v-with-new-members/"><span>Zephyr Project</span></a><span>, which is creating the IoT-oriented Zephyr RTOS, is the more mature of the two projects. Google’s </span><a href="http://linuxgizmos.com/googles-fuchsia-os-will-support-linux-apps/"><span>Fuchsia OS</span></a><span> has a longer way to go — especially if you believe that </span><a href="http://linuxgizmos.com/as-eu-tightens-screws-on-android-google-focuses-on-a-fuchsia-future/"><span>Fuchsia</span></a><span> will replace Android and Chrome OS over the next decade.</span></span></p>
<p><span><span>The developers of Zephyr and Fuchsia have a rare opportunity to develop novel, up-to-date security stacks from scratch. One of the main reasons Google chose to build Fuchsia from a new microkernel was that it could avoid the hodgepodge of legacy code layered on top of Linux, thereby improving security. Attempts to </span><a href="http://linuxgizmos.com/exploring-security-challenges-in-linux-based-iot-devices/"><span>boost security in Linux</span></a><span> are always going to be like patching holes in a boat. Zephyr and Fuchsia aim to be the OS equivalents of hovercraft.</span></span></p>
<p><span><span>Zephyr and Fuchsia are very different OSes, and they implement security in different ways. Zephyr is designed for constrained devices running on microcontrollers, such as Cortex-M4 chips, whereas Fuchsia will target phones and desktops running on applications processors, such as Cortex-A53 and Intel Core.</span></span></p>
<p><span><span>“Zephyr and Fuchsia were both open sourced in 2016, but they have been developed for very different use cases,” said Smalley. “Their architectures are very different, and each is also very different from Linux.”</span></span></p>
<h3><span><span>Zephyr security</span></span></h3>
<p><span><span>Like Linux and Fuchsia, Zephyr has RO/NX memory protection, stack depth overflow prevention, and stack buffer overflow detection. However, there’s still no kernel or user space ASLR (</span><span>address space layout randomization), which “</span><span>will likely move to a build time randomization and a small boot time relocation,” said Smalley. </span></span></p>
<p><span><span>Among other architectural differences with Linux, “There’s no process isolation in Zephyr, only a userspace thread model,” explained Smalley. “The process abstraction model has yet to be implemented, and the kernel/user boundary is still being fleshed out.”</span></span></p>
<p><span><span>In Zephyr, “you’re generally working with a single application, and security is highly dependent on particular SoCs and kernel configurations,” said Smalley. By comparison, “In Linux, there are a number of core OS security features that are neutral and independent.”</span></span></p>
<p><span><span>The original Zephyr release had a single executable with a single address space with all threads in supervisor mode and no memory protection or virtual memory, said Smalley. “As Zephyr added OS protections, it sought to minimize changes to kernel APIs in order to be backward compatible,” he added. “A key Zephyr design philosophy is to do as much as possible at build time, and then as much as possible at last view time, thereby minimizing runtime overheads and ensuring bounded latency for real-time.”</span></span></p>
<p><span><span>Zephyr security is complicated by the fact that some of the MCUs it targets include memory protection units (MPUs) while others do not. Beginning in releases 1.8 and 1.9, Zephyr began to provide memory protections, with allowances for both types of MCUs.</span></span></p>
<p><span><span>The NSA team developed a set of kernel memory protection tests modeled on lkdtm tests from the </span><a href="https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project"><span>Kernel Self Protection Project</span></a><span> (KSPP) for Linux. “The tests were helpful in catching bugs in Zephyr MPU drivers, and they are now used for regression testing,” said Smalley.</span></span></p>
<p><span><span>Zephyr added userspace support in versions 1.10 and 1.11 that provided basic support for user mode threads with isolated memory. Smalley’s team developed a set of userspace tests “that sought to validate the security properties for user mode threads were being enforced.”  Zephyr’s userspace memory model is still limited to a single executable and address space, and there’s no virtual memory. “It can support user mode threads but not full processes,” explained Smalley.</span></span></p>
<p><em><span>Sign up to receive updates on Open Source Summit and ELC+OpenIoT Europe: </span></em></p>
<p><span><span>Zephyr security features include an object permissions model in which user threads must first be granted permissions to an object to enable access. “A kernel mode thread can grant access to a user mode thread, and an inheritance mechanism allows those permissions to be propagated down,” explained Smalley. “It’s an all or nothing model — all user threads can access all app global variables.”</span></span></p>
<p><span><span>This all-or-nothing approach “poses a high burden on the application developer, who has to manually organize the application global variable memory layout to meet MPU restrictions,” said Smalley. To help compensate, the NSA team developed a feature due in release 1.13 that “supports a slightly more developer friendly way of grouping application globals based on desired protections. It’s a small step forward, not a panacea.”</span></span></p>
<p><span><span>Future Zephyr security work includes adding MPU virtualization, which “would allow us to support a larger number of regions instead of just eight that can be swapped in and out of the MPU on demand,” said Smalley. “We also hope to provide full support for multiple applications and program loading.” </span></span></p>
<p><span><span>In Zephyr, kernel code is fully trusted. “We would like to see Linux-like mitigations for kernel vulns using KSPP kernel self-protection features while minimizing runtime overheads,” said Smalley. Other wish-list items include leveraging </span><a href="http://linuxgizmos.com/new-cortex-m-chips-add-armv8-and-trustzone/"><span>armv8-m</span></a><span> for Cortex-M MCUs, thereby enabling </span><span>TrustZone security. There’s also a long-term plan </span><span>to “develop a MAC suited to RTOSes that’s more oriented to build-time app partitioning.”</span></span></p>
<h3><span><span>Fuchsia security</span></span></h3>
<p><span><span>Fuchsia differs from Linux and Zephyr in that it’s a </span><span>microkernel OS with security based on </span><span>object capability</span><span>. </span><span>Like Linux it offers process isolation. In addition, “The plumbing for kernel or user space ASLR is there,” said the NSA’s James Carter.</span></span></p>
<p><span><span>Compared to the “large and monolithic” Linux, Fuchsia has a small, decomposed TCB (trusted computing base),” said Carter. “It also uses object capabilities instead of DAC and MAC.” </span></span></p>
<p><span><span>Fuchsia is based on the Zircon Microkernel, which is derived from the little kernel (lk), “an RTOS used in the Android bootloader,” explained Carter. Fuchsia extends lk to support 64-bit, user mode, processes, IPC, and other advanced features. “The lk is the only thing that runs in supervisor mode. Drivers, filesystem, and network all run in user mode.”</span></span></p>
<p><span><span>Fuchsia security mechanisms include regular handles and resource handles using Zircon object capabilities. “Regular handles are usually the only way that userspace can access kernel objects,” said Carter. “Fuchsia differs from most OSes in that it uses a push model in which a client creates the handle and pushes it to a server. Handles are per-process and unforgeable, and they identify both the object and a set of access rights to the object. Access rights include duplicating them with equal or lesser rights or passing them across IPC or using them to obtain handles to child objects with equal or lesser writes.”</span></span></p>
<p><span><span>Fuchsia handles “are good because they separate rights for propagation vs. use and separate rights for different operations,” said Carter. “You can also reduce rights through handle duplication.”</span></span></p>
<p><span><span>Handles still pose some problems, however. For example, “with object_get_child(), if you have a handle to a job, you can acquire a handle to anything in that job or any child jobs,” said Carter. “Also, a leak of root job handle is fatal to security. We’d like to see more work on making everything able to be least privilege, and more control over handle propagation and revocation. Not all operations currently check access rights and some rights are unimplemented.”</span></span></p>
<p><span><span>Resource handles, which are the type of handle used for platform resources like memory mapped I/O, I/O ports, and IRQs, let developers specify the type of resource and optional range. On the plus side, they offer “fine-grained, hierarchical resource restrictions,” said Carter. “However, right now the root resource check isn’t very granular, and as with regular handles, leaks can be fatal. We need to work on propagation, revocation, and refining to least privilege.”</span></span></p>
<p><span><span>Zircon security primitives include job policy and vDSO enforcement. “In Fuchsia everything is part of a job,” said Carter. “Processes don’t have child processes – jobs have child jobs. Jobs can be nested, containing jobs and other processes, and job policy is applied to all processes within the job. Policies are inherited from the parent and can only be made more restrictive.”</span></span></p>
<p><span><span>On the pro side, you can create fine-grained object creation policies, as well as hierarchical job policies that are mixed,” explained Carter. “However, the </span><a href="https://en.wikipedia.org/wiki/W%5EX"><span>W^X</span></a><span> policy is not yet implemented, and when it is it will cause problems with strict hierarchical policies because if a child needs to map something W^X, then all ancestors would need to beta map it W^X as well.”</span></span></p>
<p><span><span>In Fuchsia, the </span><a href="https://www.linuxjournal.com/content/creating-vdso-colonels-other-chicken"><span>vDSO</span></a><span> (</span><span>virtual dynamic shared object) primitive “</span><span>is only meant to invoke system calls,” said Carter. “It’s fully read-only and is mapping constrained by the kernel.”</span></span></p>
<p><span><span>Fuchsia’s vDSO makes the OS more secure by “limiting the kernel attack surface, enforcing the use of the public API, and supporting per process system call restrictions,” said Carter. “It’s also good that vDSO is not trusted by the kernel so its system call arguments are fully validated.” On the other hand, the current version offers the potential for tampering with or bypassing vDSO, added Carter. </span></span></p>
<p><span><span>Carter went on to explain Fuchsia namespaces and sandboxes. Advantages of the namespaces implementation include “the lack of a global namespace and the fact that object reachability is determined by initial namespace,” said Carter. “But we’d like to see more granularity.” For sandboxes, which are used for isolating applications, “We’d like to see an expansion to system services. There’s also no independent validation of the sandbox configuration.”</span></span></p>
<p><span><span>As with Zephyr, the NSA team recommends that Fuchsia eventually add a MAC framework, which would help to “control propagation, support revocation, and apply least privilege,” said Carter. “A MAC could support finer grained check and generalize job policy, as well as validate namespaces and sandboxes. It could also provide a unified framework for defining, enforcing, and validating security goals.”</span></span></p>
<p><span><span>Options for integrating a MAC with Fuchsia start with building it entirely in user space with no microkernel support, said Carter. Alternatively, you could “extend the existing mechanism” by building it “mostly in user space with limited microkernel support.” A third choice would be to “create security policy logic in user space with full microkernel enforcement for its objects, as we did with DTMach in SELinux.”</span></span></p>
<p><span><span>In conclusion, Carter emphasized that Fuchsia’s security stack is </span><span>a work in progress. “We’re just trying to evaluate the thing.” You can watch the entire video below.</span></span></p>
<p>[embedded content]</p>
</div>