Skip to content

Commit 397ccce

Browse files
committed
test local attestation
Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>
1 parent 2dcd17e commit 397ccce

9 files changed

Lines changed: 81 additions & 170 deletions

File tree

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@ jobs:
4343
run: ACE_DIR=$(pwd)/build/ MAKEFLAGS="--silent -j4" make hypervisor
4444
- name: build firmware
4545
run: ACE_DIR=$(pwd)/build/ MAKEFLAGS="--silent -j4" make firmware
46-
- name: build confidential_vms
46+
- name: build confidential vms
4747
run: ACE_DIR=$(pwd)/build/ MAKEFLAGS="--silent -j4" make confidential_vms
48+
- name: run tests on confidential vms
49+
run: ACE_DIR=$(pwd)/build/ ace test

confidential-vms/linux_vm/hypervisor_rootfs/run_linux_vm_qemu.sh

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
# SPDX-FileContributor: Wojciech Ozga <woz@zurich.ibm.com>, IBM Research - Zurich
44
# SPDX-License-Identifier: Apache-2.0
55

6-
QEMU_CMD=qemu-system-riscv64
7-
KERNEL=/root/linux_vm/Image
8-
DRIVE=/root/linux_vm/rootfs.ext2
9-
INITRAMFS=/root/linux_vm/rootfs.cpio
10-
TAP=/root/linux_vm/cove_tap_qemu
11-
126
HOST_PORT="$((3000 + RANDOM % 3000))"
137
INTERACTIVE="-nographic"
148
SMP=2
159
MEMORY=1G
10+
ID=""
1611

1712
for i in "$@"; do
1813
case $i in
@@ -34,6 +29,10 @@ for i in "$@"; do
3429
MEMORY="${i#*=}"
3530
shift
3631
;;
32+
-i=*|--id=*)
33+
ID="${i#*=}"
34+
shift
35+
;;
3736
--daemonize*)
3837
INTERACTIVE="-daemonize"
3938
shift
@@ -47,8 +46,19 @@ for i in "$@"; do
4746
esac
4847
done
4948

49+
if [ ! -f "/root/linux_vm${ID}" ]; then
50+
cp -rf /root/linux_vm /root/linux_vm${ID}
51+
fi
52+
53+
QEMU_CMD=qemu-system-riscv64
54+
KERNEL=/root/linux_vm${ID}/Image
55+
DRIVE=/root/linux_vm${ID}/rootfs.ext2
56+
INITRAMFS=/root/linux_vm${ID}/rootfs.cpio
57+
TAP=/root/linux_vm${ID}/cove_tap_qemu
58+
5059
echo "SSH port: ${HOST_PORT}"
5160
echo "Number of cores assigned to the guest: ${SMP}"
61+
echo "${INTERACTIVE}"
5262

5363
${QEMU_CMD} ${DEBUG_OPTIONS} \
5464
${INTERACTIVE} \
@@ -61,5 +71,4 @@ ${QEMU_CMD} ${DEBUG_OPTIONS} \
6171
-device virtio-blk-pci,drive=hd0,iommu_platform=on,disable-legacy=on,disable-modern=off \
6272
-drive if=none,format=raw,file=${DRIVE},id=hd0 \
6373
-device virtio-net-pci,netdev=net0,iommu_platform=on,disable-legacy=on,disable-modern=off \
64-
-netdev user,id=net0,net=192.168.100.1/24,dhcpstart=192.168.100.128,hostfwd=tcp::${HOST_PORT}-:22 \
65-
-nographic
74+
-netdev user,id=net0,net=192.168.100.1/24,dhcpstart=192.168.100.128,hostfwd=tcp::${HOST_PORT}-:22

confidential-vms/linux_vm/hypervisor_rootfs/run_linux_vm_qemu2.sh

Lines changed: 0 additions & 69 deletions
This file was deleted.

hypervisor/configurations/qemu_riscv64_virt_defconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ BR2_GLOBAL_PATCH_DIR=""
5656

5757
# Packages
5858
BR2_PACKAGE_DROPBEAR=y
59+
BR2_PACKAGE_OPENSSH_CLIENT=y
60+
BR2_PACKAGE_SSHPASS=y
5961

6062
# Qemu
6163
BR2_PACKAGE_QEMU=y

hypervisor/rootfs/common.sh

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,21 @@
22
# SPDX-FileCopyrightText: 2023 IBM Corporation
33
# SPDX-FileContributor: Wojciech Ozga <woz@zurich.ibm.com>, IBM Research - Zurich
44
# SPDX-License-Identifier: Apache-2.0
5-
6-
function run_confidential_vm() {
7-
fallocate -l 128M hdd.dsk
8-
9-
KERNEL_IMAGE=$1
10-
NUMBER_OF_CORES=$2
11-
MEMORY_SIZE=$3
12-
DRIVE="hdd.dsk"
13-
14-
qemu-system-riscv64 -machine virt -cpu rv64 -smp $NUMBER_OF_CORES -m $MEMORY_SIZE \
15-
--enable-kvm \
16-
-global virtio-mmio.force-legacy=false \
17-
-append "console=ttyS0 ro root=/dev/vda swiotlb=mmnn,force nosplash debug promote_to_tvm" \
18-
-device virtio-blk-pci,drive=hd0,iommu_platform=on,disable-legacy=on,disable-modern=off \
19-
-drive if=none,format=raw,file=${DRIVE},id=hd0 \
20-
-nographic -bios none \
21-
-kernel $KERNEL_IMAGE &
22-
}
5+
export TVM_TEST_PASSWD="passwd"
6+
export SSH_CMD="sshpass -p ${TVM_TEST_PASSWD} ssh -y -q"
237

248
function kill_confidential_vm() {
259
PID="$(pidof qemu-system-riscv64)"
2610
kill -9 $PID
2711
wait $PID 2>/dev/null
2812
}
2913

14+
function wait_for_ssh () {
15+
for i in $(seq 1 30); do
16+
if [ "$( $SSH_CMD -p$3 $1@$2 'whoami' )" == "root" ]; then
17+
break
18+
fi
19+
echo "Waiting for the TVM's SSH ..."
20+
sleep 1
21+
done
22+
}

hypervisor/rootfs/selftest.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55

66
# This script runs all tests in harness
77

8-
declare -a TESTS=("test_esm")
8+
declare -a TESTS=("test_attestation")
99

1010
for i in "${TESTS[@]}"; do
11-
./$i.sh 2>&1 > $i.log
11+
./$i.sh 2>&1 > $i.log
1212
RESULT=$?
1313
if [ $RESULT -eq 0 ]; then
1414
echo "$i: success"
1515
else
1616
echo "$i: failed"
17-
cat $i.log
17+
echo ""
18+
echo "======= Logs: ======="
19+
cat $i.log
1820
fi
19-
done
21+
done
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
# SPDX-FileCopyrightText: 2025 IBM Corporation
3+
# SPDX-FileContributor: Wojciech Ozga <woz@zurich.ibm.com>, IBM Research - Zurich
4+
# SPDX-License-Identifier: Apache-2.0
5+
. common.sh
6+
7+
/root/run_linux_vm_qemu.sh --daemonize 2>&1 > tmp_run_vm.log &
8+
sleep 5
9+
10+
TVM_USER="root"
11+
TVM_HOST="localhost"
12+
TVM_PORT="$(grep 'SSH port' tmp_run_vm.log | awk -F': ' '{ print $2 }' )"
13+
echo "TVM's SSH is listening on port: $TVM_PORT"
14+
15+
wait_for_ssh $TVM_USER $TVM_HOST $TVM_PORT
16+
17+
$SSH_CMD -p${TVM_PORT} ${TVM_USER}@${TVM_HOST} 'insmod /root/ace_module/ace.ko'
18+
$SSH_CMD -p${TVM_PORT} ${TVM_USER}@${TVM_HOST} 'dmesg | grep Secret' > tmp_dmesg.log
19+
20+
ATTESTATION_RESULT="$(grep 'Secret=0xc0ffee' tmp_dmesg.log | wc -l)"
21+
22+
kill_confidential_vm
23+
24+
if [[ "x$ATTESTATION_RESULT" == "x1" ]]; then
25+
echo "Attestation test succeeded"
26+
exit 0
27+
else
28+
echo "Attestation test failed"
29+
exit 1
30+
fi

tools/ace_test.sh

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,16 @@ echo "Hypervisor's SSH is listening on port: $HYPERVISOR_TEST_PORT"
2121
# wait until the VM is up and running
2222
wait_for_ssh ${HYPERVISOR_TEST_LOGIN} ${HYPERVISOR_TEST_HOSTNAME} ${HYPERVISOR_TEST_PORT}
2323

24-
# test confidential memory protections
25-
QEMU_MEMORY_SIZE_MB=2048
26-
27-
# Verify that the hypervisor has no access to the confidential memory
28-
MEMORY_ACCESS_EXEC="insmod ace-kernel-module/ace.ko"
29-
MEMORY_BASE_ADDRESS="$(hex2dec 80000000 10 16)"
30-
let MEMORY_SIZE=${QEMU_MEMORY_SIZE_MB}*1024*1024
31-
let NONSECURE_MEMORY_BASE_ADDRESS=${MEMORY_BASE_ADDRESS}+2048*1024 # after OpenSBI reserved memory
32-
let SECURE_MEMORY_BASE_ADDRESS=${MEMORY_BASE_ADDRESS}+${MEMORY_SIZE}/2
33-
let SECURE_MEMORY_END_ADDRESS=${SECURE_MEMORY_BASE_ADDRESS}+${MEMORY_SIZE}/2-1
34-
35-
declare -A EXPECTED_MEMORY_ACCESS=([$NONSECURE_MEMORY_BASE_ADDRESS]=0 [$MEMORY_BASE_ADDRESS]=1 [$SECURE_MEMORY_BASE_ADDRESS]=1 [$SECURE_MEMORY_END_ADDRESS]=1)
36-
37-
for i in "${!EXPECTED_MEMORY_ACCESS[@]}"; do
38-
ADDRESS=$(hex2dec $i 16 10)
39-
EXPECTED_RESULT=${EXPECTED_MEMORY_ACCESS[$i]}
40-
RESULT=$(${SSH_CMD} -p${HYPERVISOR_TEST_PORT} ${HYPERVISOR_TEST_LOGIN}@${HYPERVISOR_TEST_HOSTNAME} ./test_secure_memory.sh 0x$ADDRESS 2>&1)
41-
ACCESS_FAILED="$(echo $RESULT | grep 'Segmentation fault' | wc -l)"
42-
if [ $ACCESS_FAILED -ne $EXPECTED_RESULT ]; then
43-
echo "incorrect access rights to $ADDRESS: FAIL"
44-
else
45-
echo "correct access rights to $ADDRESS: succeess"
46-
fi
47-
kill_qemu ${HYPERVISOR_TEST_PORT}
48-
${ACE_DIR}/tools/ace_run_hypervisor.sh --daemonize > .run_tests.log
49-
HYPERVISOR_TEST_PORT="$(grep 'SSH port' .run_tests.log | awk -F': ' '{ print $2 }' )"
50-
wait_for_ssh ${HYPERVISOR_TEST_LOGIN} ${HYPERVISOR_TEST_HOSTNAME} ${HYPERVISOR_TEST_PORT}
51-
done
52-
5324
# execute tests remotely over ssh
54-
${SSH_CMD} -p${HYPERVISOR_TEST_PORT} ${HYPERVISOR_TEST_LOGIN}@${HYPERVISOR_TEST_HOSTNAME} './selftest.sh'
25+
${SSH_CMD} -p${HYPERVISOR_TEST_PORT} ${HYPERVISOR_TEST_LOGIN}@${HYPERVISOR_TEST_HOSTNAME} './selftest.sh' > ace_test_results
5526

5627
# kill the VM
5728
kill_qemu ${HYPERVISOR_TEST_PORT}
29+
30+
FAILED="$( grep ': failed' ace_test_results | wc -l)"
31+
cat ace_test_results
32+
33+
if [[ $FAILED -gt 0 ]]; then
34+
exit 1
35+
fi
36+
exit 0

tools/common.sh

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ export HYPERVISOR_TEST_HOSTNAME="localhost"
1111
export SSH_PASSWD_PARAMS="-o PasswordAuthentication=yes -o PreferredAuthentications=keyboard-interactive,password -o PubkeyAuthentication=no -o StrictHostKeyChecking=no"
1212
export SSH_CMD="sshpass -p ${HYPERVISOR_TEST_PASSWD} ssh ${SSH_PASSWD_PARAMS}"
1313

14-
1514
# Usage: wait_for_ssh "root", "localhost", "22"
16-
function wait_for_ssh () {
17-
while [ "$( $SSH_CMD -p$3 $1@$2 'whoami' )" != "root" ]; do
18-
echo "waiting for the guest's ssh ..."
15+
function wait_for_ssh () {
16+
while [ "$( $SSH_CMD -p$3 $1@$2 'whoami' )" != "root" ]; do
17+
echo "waiting for the hypervisor's ssh ..."
1918
sleep 1
2019
done
2120
}
@@ -29,39 +28,3 @@ function kill_qemu () {
2928
wait $PID 2>/dev/null
3029
fi
3130
}
32-
33-
function kill_users_qemu () {
34-
USER="$(whoami)"
35-
PID="$(ps aux | grep qemu | grep ${USER} | awk -F' ' '{ print $2 }')"
36-
if [ "$PID" != "" ]; then
37-
kill -9 $PID
38-
wait $PID 2>/dev/null
39-
fi
40-
}
41-
42-
function hex2dec() {
43-
## validate sufficient input
44-
test -n "$1" || {
45-
printf "\n error: insufficient input. usage: %s num [obase (2)] [ibase (10)]\n\n" "${0//*\//}"
46-
exit 1
47-
}
48-
49-
## test for help
50-
test "$1" = "-h" || test "$1" = "--help" && {
51-
printf "\n usage: %s num [obase (2)] [ibase (10)] -- to convert number\n\n" "${0//*\//}"
52-
exit 0
53-
}
54-
55-
## validate numeric value given for conversion (bash only test)
56-
ival="${1^^}"
57-
[[ $ival =~ [^0-9A-F] ]] && {
58-
printf "\n error: invalid input. Input must be within upper/lower case hex character set [0-9A-Fa-f]\n\n"
59-
exit 1
60-
}
61-
62-
ob=${2:-2}
63-
ib=${3:-10}
64-
65-
# set obase first before ibase -- or weird things happen.
66-
printf "obase=%d; ibase=%d; %s\n" $ob $ib $ival | bc
67-
}

0 commit comments

Comments
 (0)