• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..30-Mar-2022-

c_src/H03-May-2022-138135

include/H30-Mar-2022-952729

src/H30-Mar-2022-379313

test/H30-Mar-2022-6942

.cargo-checksum.jsonH A D03-May-202227 11

.clang-formatH A D30-Mar-20223.3 KiB122120

.clang-tidyH A D30-Mar-202292 33

.travis.ymlH A D30-Mar-2022292 1311

Cargo.tomlH A D30-Mar-20221.5 KiB2220

LICENSEH A D30-Mar-20221 KiB2217

README.mdH A D30-Mar-20225.9 KiB142104

README.md

1[![Build Status](https://travis-ci.com/PLSysSec/rlbox_lucet_sandbox.svg?branch=master)](https://travis-ci.com/PLSysSec/rlbox_lucet_sandbox)
2
3# RLBOX Lucet Sandbox Integration
4Integration with RLBox sandboxing API to leverage the sandboxing in WASM modules compiled with lucet compiler.
5
6For details about the RLBox sandboxing APIs, see [here](https://github.com/PLSysSec/rlbox_api_cpp17).
7
8This code has been tested on 64-bit versions of Ubuntu and Mac OSX.
9The lucet compiler does not currently support Windows.
10
11## Reporting security bugs
12
13If you find a security bug, please do not create a public issue. Instead, file a security bug on bugzilla using the [following template link](https://bugzilla.mozilla.org/enter_bug.cgi?cc=tom%40mozilla.com&cc=nfroyd%40mozilla.com&cc=deian%40cs.ucsd.edu&cc=shravanrn%40gmail.com&component=Security%3A%20Process%20Sandboxing&defined_groups=1&groups=core-security&product=Core&bug_type=defect).
14
15## Building/Running the tests
16
17You can build and run the tests using cmake with the following commands.
18
19```bash
20cmake -S . -B ./build
21cmake --build ./build --target all
22cmake --build ./build --target test
23```
24
25On Arch Linux you'll need to install [ncurses5-compat-libs](https://aur.archlinux.org/packages/ncurses5-compat-libs/).
26
27## Using this library
28
29First, build the rlbox_lucet_sandbox repo with
30
31```bash
32cmake -S . -B ./build
33cmake --build ./build --target all
34```
35
36This lucet/wasm integration with RLBox depends on 3 external tools/libraries that are pulled in **automatically** to run the tests included in this repo.
37
381. [A clang compiler with support for WASM/WASI backend, and the WASI sysroot](https://github.com/CraneStation/wasi-sdk). This allows you to compile C/C++ code to WASM modules usable outside of web browsers (in desktop applications).
392. [The **modified** lucet compiler](https://github.com/shravanrn/lucet/) that compiles the produced WASM/WASI module to a native binary.
403.  [The RLBox APIs]((https://github.com/PLSysSec/rlbox_api_cpp17)) - A set of APIs that allow easy use of sandboxed libraries.
41
42In the below steps, you can either use the automatically pulled in versions as described below, or download the tools yourself.
43
44In order to sandbox a library of your choice.
45
46- Build the sources of your library along with the file `c_src/lucet_sandbox_wrapper.c` and passing the flag `--export-all` to the linker using the clang compiler described above. This will produce a wasm module. The required clang compiler is available in the path `build/_deps/wasiclang-src/opt/wasi-sdk/bin/clang`.
47For instance, to edit an existing `make` based build system, you can run the commmand.
48
49```bash
50build/_deps/wasiclang-src/bin/clang --sysroot build/_deps/wasiclang-src/share/wasi-sysroot/ c_src/lucet_sandbox_wrapper.c -c -o c_src/lucet_sandbox_wrapper.o
51
52CC=build/_deps/wasiclang-src/bin/clang                            \
53CXX=build/_deps/wasiclang-src/bin/clang++                         \
54CFLAGS="--sysroot build/_deps/wasiclang-src/share/wasi-sysroot/"  \
55LD=build/_deps/wasiclang-src/bin/wasm-ld                          \
56LDLIBS=lucet_sandbox_wrapper.o                                                 \
57LDFLAGS=-Wl,--export-all                                                       \
58make
59```
60
61- Assuming the above command produced the wasm module `libFoo`, compile this to an ELF shared library using the modified lucetc compiler as shown below.
62
63```bash
64build/cargo/release/lucetc                                        \
65    --bindings build/_deps/mod_lucet-src/lucet-wasi/bindings.json \
66    --guard-size "4GiB"                                           \
67    --min-reserved-size "4GiB"                                    \
68    --max-reserved-size "4GiB"                                    \
69    libFoo                                                        \
70    -o libWasmFoo.so
71```
72- Finally you can write sandboxed code, just as you would with any other RLBox sandbox, such as in the short example below. For more detailed examples, please refer to the tutorial in the [RLBox Repo]((https://github.com/PLSysSec/rlbox_api_cpp17)).
73
74
75```c++
76#define RLBOX_SINGLE_THREADED_INVOCATIONS
77
78#include "rlbox_lucet_sandbox.hpp"
79#include "rlbox.hpp"
80
81int main()
82{
83    rlbox_sandbox<rlbox_lucet_sandbox> sandbox;
84    sandbox.create_sandbox("libWasmFoo.so");
85    // Invoke function bar with parameter 1
86    sandbox.invoke_sandbox_function(bar, 1);
87    sandbox.destroy_sandbox();
88    return 0;
89}
90```
91
92- To compile the above example, you must include the rlbox header files in `build/_deps/rlbox-src/code/include`, the integration header files in `include/` and the lucet_sandbox library in `build/cargo/{debug or release}/librlbox_lucet_sandbox.a` (make sure to use the whole archive and the rdynamic linker options). For instance, you can compile the above with
93
94```bash
95g++ -std=c++17 example.cpp -o example -I build/_deps/rlbox-src/code/include -I include -Wl,--whole-archive build/cargo/debug/librlbox_lucet_sandbox.a -Wl,--no-whole-archive -rdynamic -lpthread -ldl -lrt
96```
97
98## Contributing Code
99
1001. To contribute code, it is recommended you install clang-tidy which the build
101uses if available. Install using:
102
103   On Ubuntu:
104```bash
105sudo apt install clang-tidy
106```
107   On Arch Linux:
108```bash
109sudo pacman -S clang-tidy
110```
111
1122. It is recommended you use the dev mode for building during development. This
113treat warnings as errors, enables clang-tidy checks, runs address sanitizer etc.
114Also, you probably want to use the debug build. To do this, adjust your build
115settings as shown below
116
117```bash
118cmake -DCMAKE_BUILD_TYPE=Debug -DDEV=ON -S . -B ./build
119```
120
1213. After making changes to the source, add any new required tests and run all
122tests as described earlier.
123
1244. To make sure all code/docs are formatted with, we use clang-format.
125Install using:
126
127   On Ubuntu:
128```bash
129sudo apt install clang-format
130```
131   On Arch Linux:
132```bash
133sudo pacman -S clang-format
134```
135
1365. Format code with the format-source target:
137```bash
138cmake --build ./build --target format-source
139```
140
1416. Submit the pull request.
142