Skip to content

Commit 2bcc306

Browse files
committed
add initial draft of the RustyHermit showcase
1 parent 578948c commit 2bcc306

File tree

4 files changed

+144
-4
lines changed

4 files changed

+144
-4
lines changed

content/showcase/bandwidth.png

63.6 KB
Loading

content/showcase/common_vm.png

41.4 KB
Loading

content/showcase/libos.png

44.7 KB
Loading

content/showcase/rusty-hermit.md

Lines changed: 144 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,151 @@
11
+++
22
title = "The <code>RustyHermit</code> Unikernel"
3-
date = 0000-01-01
3+
date = 2021-01-17
44

55
[extra]
6-
authors = []
6+
authors = ["stlankes"]
77
+++
88

9-
The `RustyHermit` project ...
9+
[RustyHermit](https://github.com/hermitcore/rusty-hermit) is a unikernel, which is completely written Rust. [Unikernel](http://unikernel.org/) are application images that directly contain the kernel as a library, so it does not require an installed operating system (OS). They are typical used in virtualized environments, which build the backbone of typical cloud / edge infrastructures.
1010

11-
<!-- TODO: update publish date -->
11+
Common virtualized environment based on classical virtual machines. In this case, complete machines are emulated or virtualized and on host and guest site are running common operating systems. This technique is established (VMware, Hyper-V, etc.) and widely used. However, it introduces additional overhead especially regarding memory consumption and performance.
12+
13+
![Structure of a common virtualitation environment](../common_vm.png)
14+
15+
An alternative approach to common virtual machines is OS-level
16+
virtualization, where the kernel allows the existence of multiple
17+
isolated user space instances. These isolated instances are also known
18+
as container. A typical representative is LXC or Docker and promise less
19+
overhead in comparison to common virtual machines. However, the
20+
isolation between the processes is weaker and may provide less security.
21+
22+
Often only one application (e.g. a web server) is running in the container or the virtual machine. In this case, is a unikernel an attractive solution. The kernel is provided as static library and linked to the application. As the images directly contain the OS kernel, unikernels can directly be bootet inside a virtual machine and do not require the typical software stack containing a linux kernel and its userland within the VM.
23+
24+
Unikernels do not provide system calls in the classical sense, as everything is running with the privilege level of a kernel and what is typically done via system calls is provided via a common function call. At first glance, this sounds more insecure than previous approaches. However, these kernels are expected to run within a virtual machine, which isolated the application from the real system. In addition, common compiler analysis is used to check the complete software stack and even unneeded components can be removed, which can reduce the attack surface of the application.
25+
26+
![Structure of a library operating system](../libos.png)
27+
28+
Well known unikernels are kernels such as [MirageOS](https://mirage.io/)
29+
and [Unikraft](http://www.unikraft.org/). MirageOS is written in OCaml,
30+
while Unikraft still use C as programming language. In contrast to these
31+
kernels, RustyHermit is completely written in Rust to benefit from
32+
Rust's performance and security behavior. In principle, every existing
33+
Rust application can be built on top of RustyHermit. However, unikernels
34+
are a single tasking operating system. Consequently, the support of the
35+
system call `fork` and inter-process communication are missing. In
36+
addition, a classical C library is missing, which is typical used as
37+
interface to the operating system. Every crate, which bypass the
38+
standard runtime and tries to communicate directly to operating system
39+
does not work without modifications. However, many applications do not
40+
depend on these features and work on RustyHermit.
41+
42+
Unikernels can be highly optimized. For instance, we optimized the
43+
network stack of RustyHermit. RustyHermit uses
44+
[smoltcp](https://github.com/smoltcp-rs/smoltcp) as network stack, which
45+
is completely written in Rust. As interface between guest and host
46+
operating system, we use
47+
[Virtio](https://www.linux-kvm.org/page/Virtio), which is in a
48+
para-virtualized driver for KVM and widely used in virtualized Linux
49+
environments. The following figure compares Linux with RustyHermit,
50+
where both are running as guests inside a virtual machine running on top
51+
of a Linux-based host system. Especially for small messages RustHermit
52+
is faster in than Linux.
53+
54+
![Bandwidth of the RustyHermit's exerimental network interface](../bandwidth.png)
55+
56+
RustyHermit is also a research project to evaluate new operating
57+
systems designs, which improves the scalability and the security of operating systems in cloud environments. For instance, RustyHermit provides classical
58+
techniques to improve the security behavior like stack guards and
59+
separating the application stack from the libos stack. However, a
60+
library operating system uses typical a common function call to enter
61+
the kernel. A classical separation from user- and kernel space by
62+
entering a higher privilege level is missing. We presented in a
63+
[paper](https://www.ssrg.ece.vt.edu/papers/vee20-mpk.pdf) a modified
64+
version of RustyHermit, which provides an intra-unikernel isolation with
65+
Intel Memory Protection Keys (MPK). MPK is a relatively new hard-ware
66+
primitive that provides per-thread permission control over groups of
67+
pages in a single address space with [negligible switching overhead](https://www.usenix.org/conference/atc19/presentation/park-soyeon),
68+
making it a compelling candidate for use in unikernels.
69+
70+
MPK is requiring modification of page tables at a small performance cost. Four previously-unused bits of each page table entry (the 62nd to the 59th on x86-64) are exploited by MPK. Since MPK exploits four bits of the page table entry, it supports up to 15 protection keys.
71+
MPK controls per-thread permission on groups of pages. Each core has a PKRU register (32 bits) containing a permission value. The value of the PKRU register defines the permission of the thread currently running on that core for each group of pages containing a protection key in their page table entries. Unlike page-table-level permission, MPK provides thread-local memory permission.
72+
73+
We provide user / kernel separation so we simply see the entire application as an untrusted component, independently of application-specific characteristics such as the language it is written in or the level of skill of the application’s programmer. In addition, we divide the kernel code into trusted and untrusted components. Trusted kernel components represent pieces of code written with a memory-safe language, i.e., offering strong security guarantees. Untrusted kernel components correspond to code written either in memory-unsafe languages or in unsafe Rust code blocks.
74+
75+
By entering the library operating system through the application binary interface, the protection keys will be automatically changed and allows access to the kernel stack and the kernel heap. Unauthorized access from within the application will trigger a pagefault, which will be handled by the library operating system.
76+
77+
To give you an example on how to build an RustyHermit application, lets create a new cargo project:
78+
79+
```sh
80+
cargo new hello_world
81+
cd hello_world
82+
```
83+
84+
RustyHermit currently requires the nightly versions of the Rust toolchain.
85+
To simplify the workflow, we recommend to create the configuration
86+
_rust-toolchain_ as follows to define the required components and to
87+
tested version of nightly compiler.
88+
89+
To simplify the workflow, we recommend that you create the _rust-toolchain_ configuration file as follows:
90+
91+
```
92+
[toolchain]
93+
channel = "nightly-2020-12-23"
94+
components = [ "rustfmt", "rust-src", "llvm-tools-preview"]
95+
targets = [ "x86_64-unknown-hermit" ]
96+
```
97+
98+
The configuration file specifies the required components and the version of the nightly compiler to use.
99+
100+
The RustyHermit's target `x86_64-unknown-hermit` is part of Rust
101+
supported platforms, but doesn't belong to the *tier 1* platforms,
102+
which means that official binary releases aren't available and the
103+
standard runtime must be build from scratch.
104+
To simplify this build process, we recommend to create the configuration
105+
file `.cargo/config` as follows:
106+
107+
```
108+
[unstable]
109+
build-std = ["std", "core", "alloc", "panic_abort"]
110+
111+
[build]
112+
target = "x86_64-unknown-hermit"
113+
``
114+
115+
To bind the library operating system to the application, we have to add the crate [hermit-sys](https://crates.io/crates/hermit-sys) to the dependencies in the file `Cargo.toml`.
116+
117+
```toml
118+
# Cargo.toml
119+
120+
[target.'cfg(target_os = "hermit")'.dependencies]
121+
hermit-sys = "0.1.*"
122+
features = ["smoltcp"]
123+
```
124+
125+
The feature `smoltcp` is required, if your application tries
126+
to establish a TCP connection. In this case, the library operating systems
127+
includes the TCP/stack [smoltcp](https://github.com/smoltcp-rs/smoltcp).
128+
In addition _hermit-sys_ depends on the tool [cargo-download](https://crates.io/crates/cargo-download) to download required components and must be installed with the command `cargo install cargo-download`.
129+
Finally, the application can be build with the common command `cargo build`.
130+
131+
The result is a 64-bit excutable in the [executable link format](https://refspecs.linuxfoundation.org/elf/elf.pdf) (ELF).
132+
To start the application within a common virtual machine, a loader is required, which initialize the processor and start the applications.
133+
We provide at [GitHub](https://github.com/hermitcore/rusty-loader) a simple loader.
134+
A makefile to build the loader is part of the project.
135+
After that, Qemu can be used to start RustyHermit in a VM as follows:
136+
137+
```sh
138+
qemu-system-x86_64 -display none -smp 1 -m 64M -serial stdio -kernel path_to_loader/rusty-loader -initrd path_to_app/app -cpu qemu64,apic,fsgsbase,rdtscp,xsave,fxsr
139+
```
140+
141+
To improve the performance, KVM can be used to use the virtualization extension of modern processors.
142+
143+
```sh
144+
qemu-system-x86_64 -display none -smp 1 -m 64M -serial stdio -kernel path_to_loader/rusty-loader -initrd path_to_hello_world/hello_world -enable-kvm -cpu host
145+
```
146+
147+
For the near future, we have to stabilized the interface to the hardware.
148+
For instance, the support of [Virtio-fs](https://virtio-fs.gitlab.io/)
149+
is in an early stage. In addition, the integration into Rust standard
150+
library isn't finalized and the current version runs only on x86. In the
151+
future, we want to support also aarch64 as processor architecture.

0 commit comments

Comments
 (0)