Skip to content

Commit 3118f7a

Browse files
committed
Fixed regression in sim test, added sim test for denied rollback
1 parent d4f062a commit 3118f7a

4 files changed

Lines changed: 75 additions & 0 deletions

File tree

.github/workflows/test-hooks-simulator.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ jobs:
8888
WOLFBOOT_HOOK_BOOT=1 \
8989
WOLFBOOT_HOOK_PANIC=1
9090
91+
- name: Run dualbank rollback denial simulation
92+
if: matrix.mechanism == 'dualbank'
93+
run: |
94+
tools/scripts/sim-dualbank-rollback-denied.sh
95+
9196
- name: Clear hook log
9297
run: |
9398
rm -f /tmp/wolfboot_hooks.log

.github/workflows/test-sunnyday-simulator.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ jobs:
5454
cp config/examples/sim-dualbank.config .config
5555
make test-sim-internal-flash-with-update
5656
57+
- name: Run dualbank rollback denial simulation
58+
run: |
59+
tools/scripts/sim-dualbank-rollback-denied.sh
60+
5761
- name: Run dualbank swap simulation
5862
run: |
5963
tools/scripts/sim-dualbank-swap-update.sh

src/update_flash_hwswap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "hooks.h"
2929
#include "spi_flash.h"
3030
#include "wolfboot/wolfboot.h"
31+
#include "printf.h"
3132
#ifdef SECURE_PKCS11
3233
int WP11_Library_Init(void);
3334
#endif
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
if [ ! -f ".config" ]; then
5+
echo "Missing .config. Run make config first." >&2
6+
exit 1
7+
fi
8+
9+
if ! grep -Eq '^(DUALBANK_SWAP(\?|)=1)' .config; then
10+
echo "DUALBANK_SWAP=1 is required for this simulation." >&2
11+
exit 1
12+
fi
13+
14+
if [ ! -x "./wolfboot.elf" ]; then
15+
echo "wolfboot.elf not found. Build the simulator first." >&2
16+
exit 1
17+
fi
18+
19+
if [ ! -f "./internal_flash.dd" ]; then
20+
echo "internal_flash.dd not found. Build test-sim-internal-flash-with-update first." >&2
21+
exit 1
22+
fi
23+
24+
backup_image="$(mktemp ./internal_flash.rollback.XXXXXX)"
25+
cp ./internal_flash.dd "$backup_image"
26+
trap 'cp "$backup_image" ./internal_flash.dd; rm -f "$backup_image" sim_registers.dd' EXIT
27+
28+
rm -f sim_registers.dd
29+
30+
update_addr_hex="$(grep '^WOLFBOOT_PARTITION_UPDATE_ADDRESS=' .config | cut -d= -f2)"
31+
if [ -z "${update_addr_hex}" ]; then
32+
echo "WOLFBOOT_PARTITION_UPDATE_ADDRESS is not set in .config." >&2
33+
exit 1
34+
fi
35+
36+
update_addr=$((update_addr_hex))
37+
38+
# Corrupt UPDATE payload bytes so version metadata remains intact but
39+
# image verification fails and boot logic attempts fallback.
40+
printf '\x00\x00\x00\x00\x00\x00\x00\x00' | \
41+
dd of=./internal_flash.dd bs=1 seek="$((update_addr + 0x120))" conv=notrunc status=none
42+
43+
set +e
44+
rollback_output="$(timeout 3s ./wolfboot.elf get_version 2>&1)"
45+
rollback_rc=$?
46+
set -e
47+
48+
if [ "$rollback_rc" -eq 0 ]; then
49+
echo "Expected rollback denial, but boot continued normally." >&2
50+
exit 1
51+
fi
52+
53+
if [ "$rollback_rc" -ne 124 ] && [ "$rollback_rc" -ne 80 ]; then
54+
echo "Unexpected exit code while checking rollback denial: $rollback_rc" >&2
55+
echo "$rollback_output" >&2
56+
exit 1
57+
fi
58+
59+
if ! printf '%s\n' "$rollback_output" | grep -q "Rollback to lower version not allowed"; then
60+
echo "Rollback denial message not found in output." >&2
61+
echo "$rollback_output" >&2
62+
exit 1
63+
fi
64+
65+
echo "Dualbank rollback-to-older-version denial verified."

0 commit comments

Comments
 (0)