Skip to content

[otbn] Patch an error in the OTBN boot services program #27679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: earlgrey_1.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions sw/device/silicon_creator/lib/drivers/otbn.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,20 @@ rom_error_t sc_otbn_load_app(const sc_otbn_app_t app) {
}
return kErrorOk;
}

void sc_otbn_patch(void) {
enum {
// Offset in the code of the bad instruction:
kBugOffset = 0x958,
// The bad instruction is:
// bn.rshi w16, w20, w31 >> 192
kBadInstr = 0xc1fa387b,
// The good instruction is:
// bn.rshi w16, w31, w20 >> 192
kGoodInstr = 0xc14fb87b,
};
uint32_t inst = abs_mmio_read32(kBase + OTBN_IMEM_REG_OFFSET + kBugOffset);
if (inst == kBadInstr) {
abs_mmio_write32(kBase + OTBN_IMEM_REG_OFFSET + kBugOffset, kGoodInstr);
}
}
12 changes: 12 additions & 0 deletions sw/device/silicon_creator/lib/drivers/otbn.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,18 @@ rom_error_t sc_otbn_imem_sec_wipe(void);
OT_WARN_UNUSED_RESULT
rom_error_t sc_otbn_dmem_sec_wipe(void);

/**
* Patch a bad instruction in OTBN imem.
*
* There is a bug in the OTBN boot services program loaded by ROM. There is a
* single instruction with mistakenly transposed operands which can affect the
* random share values. This bug DOES NOT affect the correctness of the OTBN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* random share values. This bug DOES NOT affect the correctness of the OTBN
* random share values. This bug DOES NOT affect the correctness of the OTBN

* calculations.
*
* This function patches the bad instruction with the correctly instruction.
*/
void sc_otbn_patch(void);

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions sw/device/silicon_creator/rom_ext/imm_section/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ cc_library(
"//sw/device/silicon_creator/lib/base:static_dice",
"//sw/device/silicon_creator/lib/cert:dice_chain",
"//sw/device/silicon_creator/lib/drivers:flash_ctrl",
"//sw/device/silicon_creator/lib/drivers:otbn",
"//sw/device/silicon_creator/lib/drivers:rnd",
"//sw/device/silicon_creator/lib/ownership:ownership_key",
"//sw/device/silicon_creator/rom_ext:rom_ext_manifest",
Expand Down
8 changes: 8 additions & 0 deletions sw/device/silicon_creator/rom_ext/imm_section/imm_section.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "sw/device/silicon_creator/lib/base/sec_mmio.h"
#include "sw/device/silicon_creator/lib/cert/dice_chain.h"
#include "sw/device/silicon_creator/lib/drivers/flash_ctrl.h"
#include "sw/device/silicon_creator/lib/drivers/otbn.h"
#include "sw/device/silicon_creator/lib/drivers/rnd.h"
#include "sw/device/silicon_creator/lib/epmp_state.h"
#include "sw/device/silicon_creator/lib/error.h"
Expand All @@ -21,6 +22,13 @@

OT_WARN_UNUSED_RESULT
static rom_error_t imm_section_start(void) {
// Patch a bug in the OTBN ECDSA-P256 program.
//
// There is a single instruction with mistakenly transposed operands which
// can affect the random share values. This bug DOES NOT affect the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// can affect the random share values. This bug DOES NOT affect the
// can affect the random share values. This bug DOES NOT affect the

// correctness of the OTBN calculations.
sc_otbn_patch();

// Check the ePMP state.
HARDENED_RETURN_IF_ERROR(epmp_state_check());
// Check sec_mmio expectations.
Expand Down
Loading