Skip to content

Commit 24a3888

Browse files
sasdfpamaury
authored andcommitted
[rom_ext,rescue] Fix allowlist for reboot mode
The reboot mode is always allowed in `rescue_validate_mode`. H owever, the rescue protocol will still crash with `kErrorRescueBadMode` when the reboot command is not allowed. This commit fixes this issue by moving those special commands before the `owner_rescue_command_allowed` checks. Change-Id: I2c632c516825df514f50454a406e52a3be67f1ef Signed-off-by: Yi-Hsuan Deng <[email protected]> (cherry picked from commit 3609dac)
1 parent e0d3422 commit 24a3888

File tree

2 files changed

+15
-7
lines changed
  • sw/device/silicon_creator

2 files changed

+15
-7
lines changed

sw/device/silicon_creator/lib/rescue/rescue.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,20 @@ rom_error_t rescue_validate_mode(uint32_t mode, rescue_state_t *state) {
214214
}
215215

216216
rom_error_t rescue_send_handler(rescue_state_t *state) {
217-
if (state->mode == kRescueModeNoOp) {
218-
// The No-Op mode is always allowed and does nothing.
219-
return kErrorOk;
217+
// The following commands are always allowed and are not subject to
218+
// the "command allowed" check.
219+
switch (state->mode) {
220+
case kRescueModeReboot:
221+
// If a reboot was requested, return an error and go through the normal
222+
// shutdown process.
223+
return kErrorRescueReboot;
224+
case kRescueModeNoOp:
225+
// The No-Op mode is always allowed and does nothing.
226+
return kErrorOk;
227+
default:
228+
/* do nothing */;
220229
}
230+
221231
hardened_bool_t allow =
222232
owner_rescue_command_allowed(state->config, state->mode);
223233
if (allow != kHardenedBoolTrue) {
@@ -255,10 +265,6 @@ rom_error_t rescue_send_handler(rescue_state_t *state) {
255265
case kRescueModeFirmwareSlotB:
256266
// Nothing to do for receive modes.
257267
return kErrorOk;
258-
case kRescueModeReboot:
259-
// If a reboot was requested, return an error and go through the normal
260-
// shutdown process.
261-
return kErrorRescueReboot;
262268
default:
263269
// This state should be impossible.
264270
return kErrorRescueBadMode;

sw/device/silicon_creator/rom_ext/e2e/rescue/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ opentitan_test(
389389
--exec="rescue get-device-id --reboot=false"
390390
# Try the `RESQ` mode and make sure we get an error message.
391391
--exec="console --non-interactive --send='RESQ\r' --exit-success='{exit_success}' --exit-failure='{exit_failure}'"
392+
# Try the `REBO` mode and make sure we reboot without crash.
393+
--exec="console --non-interactive --send='REBO\r' --exit-success='ROM:' --exit-failure='BFV:.*\r\n'"
392394
no-op
393395
""",
394396
),

0 commit comments

Comments
 (0)