Skip to content

Commit efc7039

Browse files
committed
Lock APOB state machine on unapproved messages
1 parent 695c7d5 commit efc7039

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

drv/cosmo-hf/src/apob.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,19 @@ impl ApobState {
620620
Ok(data.len())
621621
}
622622

623+
pub(crate) fn lock(&mut self) {
624+
match *self {
625+
ApobState::Ready { .. } | ApobState::Waiting { .. } => {
626+
*self = ApobState::Locked {
627+
commit_result: Err(ApobCommitError::InvalidState),
628+
};
629+
}
630+
ApobState::Locked { .. } => {
631+
// Nothing to do here
632+
}
633+
}
634+
}
635+
623636
pub(crate) fn commit(
624637
&mut self,
625638
drv: &mut FlashDriver,

drv/cosmo-hf/src/hf.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,14 @@ impl idl::InOrderHostFlashImpl for ServerImpl {
537537
.map_err(RequestError::from)
538538
}
539539

540+
fn apob_lock(
541+
&mut self,
542+
_: &RecvMessage,
543+
) -> Result<(), RequestError<core::convert::Infallible>> {
544+
self.apob_state.lock();
545+
Ok(())
546+
}
547+
540548
fn apob_read(
541549
&mut self,
542550
_: &RecvMessage,
@@ -989,6 +997,14 @@ impl idl::InOrderHostFlashImpl for FailServer {
989997
Err(drv_hf_api::ApobCommitError::InvalidState.into())
990998
}
991999

1000+
fn apob_lock(
1001+
&mut self,
1002+
_: &RecvMessage,
1003+
) -> Result<(), RequestError<core::convert::Infallible>> {
1004+
// Locking is tautological if we're running the error server
1005+
Ok(())
1006+
}
1007+
9921008
fn apob_read(
9931009
&mut self,
9941010
_: &RecvMessage,

drv/gimlet-hf-server/src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,13 @@ impl idl::InOrderHostFlashImpl for ServerImpl {
940940
Err(drv_hf_api::ApobCommitError::NotImplemented.into())
941941
}
942942

943+
fn apob_lock(
944+
&mut self,
945+
_: &RecvMessage,
946+
) -> Result<(), RequestError<core::convert::Infallible>> {
947+
Err(drv_hf_api::ApobCommitError::NotImplemented.into())
948+
}
949+
943950
fn apob_read(
944951
&mut self,
945952
_: &RecvMessage,
@@ -1166,6 +1173,13 @@ impl idl::InOrderHostFlashImpl for FailServer {
11661173
Err(drv_hf_api::ApobCommitError::NotImplemented.into())
11671174
}
11681175

1176+
fn apob_lock(
1177+
&mut self,
1178+
_: &RecvMessage,
1179+
) -> Result<(), RequestError<core::convert::Infallible>> {
1180+
Err(drv_hf_api::ApobCommitError::NotImplemented.into())
1181+
}
1182+
11691183
fn apob_read(
11701184
&mut self,
11711185
_: &RecvMessage,

drv/mock-gimlet-hf-server/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ impl idl::InOrderHostFlashImpl for ServerImpl {
264264
Err(drv_hf_api::ApobCommitError::NotImplemented.into())
265265
}
266266

267+
fn apob_lock(
268+
&mut self,
269+
_: &RecvMessage,
270+
) -> Result<(), RequestError<core::convert::Infallible>> {
271+
Err(drv_hf_api::ApobCommitError::NotImplemented.into())
272+
}
273+
267274
fn apob_read(
268275
&mut self,
269276
_: &RecvMessage,

idl/hf.idol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ Interface(
286286
),
287287
idempotent: true,
288288
),
289+
"apob_lock": (
290+
description: "locks the APOB state machine",
291+
reply: Simple("()"),
292+
idempotent: true,
293+
),
289294
"apob_read": (
290295
description: "reads from the current APOB slot",
291296
args: {

task/host-sp-comms/src/main.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,27 @@ impl ServerImpl {
822822
self.tx_buf.reset();
823823
}
824824

825+
// If we receive an out-of-sequence message, then lock the APOB state
826+
// machine. This makes it harder for malicious hosts to exfiltrate
827+
// data via the host flash APOB slots.
828+
match request {
829+
HostToSp::KeyLookup { .. }
830+
| HostToSp::GetBootStorageUnit
831+
| HostToSp::GetIdentity
832+
| HostToSp::GetStatus
833+
| HostToSp::AckSpStart
834+
| HostToSp::ApobBegin { .. }
835+
| HostToSp::ApobData { .. }
836+
| HostToSp::ApobRead { .. }
837+
| HostToSp::ApobCommit => {
838+
// These are explicitly allowed
839+
}
840+
_ => {
841+
// Anything not allowed is prohibited!
842+
self.hf.apob_lock();
843+
}
844+
}
845+
825846
// We defer any actions until after we've serialized our response to
826847
// avoid borrow checker issues with calling methods on `self`.
827848
let mut action = None;

0 commit comments

Comments
 (0)