Proving that everything works as expected
Now that we've got the CheriBuild tools installed and working as well as the QEMU virtual machine it's time to try testing some code.
The below paper provides some good examples and allows us to prove that compiling code with the tools provides the expected results.
Below is a link to a great set of instructions and examples that help get test code up and running on CHERI. Some of the most common exploits are documented and examples of how CHERI is working to prevent these are shown. This is a great way to check your environment and to see what sort of problems CHERI is designed to solve and how it could possibly link with other DSbD technologies.
Note: You can use this command to mount a directory from your local machine into the QEMU virtual machine. This is handy for quickly being able to run code that you have cross-compiled.
mount_smbfs -I 10.0.2.4 -N //10.0.2.4/source_root /mnt Some sample build commands for CHERI and RiscV native
In our case all of the example code ran as expected, we used 2 QEMU virtual machines, one was running riscv64-purecap and the other running riscv64-hybrid. Just for reference I have included a couple of the example commands used to show how the building of CHERI binaries differs from a native binary.
CHERI
./cheri/output/sdk/bin/clang -g -O2 \
--sysroot=./cheri/output/rootfs-riscv64-purecap \
-target riscv64-unknown-freebsd -static -fuse-ld=lld \
-mno-relax -march=rv64gcxcheri -mabi=l64pc128d \
-Wall -Wcheri -G0 \
./cheri/evaluation_code/basic_pointer_printing/cheri/print-capability.c \
-o ./cheri/evaluation_code/basic_pointer_printing/cheri/cheri_print_capability Native RiscV
./cheri/output/sdk/bin/clang -g -O2 \
--sysroot=./cheri/output/rootfs-riscv64-hybrid \
-target riscv64-unknown-freebsd -static -fuse-ld=lld \
-mno-relax -march=rv64gc -mabi=lp64d \
-Wall -Wcheri -G0 \
./cheri/evaluation_code/basic_pointer_printing/native/print-pointer.c \
-o ./cheri/evaluation_code/basic_pointer_printing/native/native_print_capability