Merge pull request #714 from Foundation-Devices/SFT-7497-update-foundation-firmware
What changed, and why it matters
This commit updates the firmware verification library from version 0.2 to 0.3 and adjusts the surrounding Rust code to match. The visible changes are mostly defensive: adding safety documentation, marking C-callable functions as unsafe, and mapping a new error case so invalid firmware headers are reported more precisely. There is no direct evidence in the commit of a fixed security vulnerability, but the update to the underlying library could include undisclosed fixes. The commit itself does not explain why the library was updated.
Review the foundation-firmware 0.3.0 changelog or release notes to determine whether the version bump fixes any security issues. If the crate is not publicly documented, request the vendor to disclose the reason for the update and confirm whether any Passport firmware verification bypass was addressed.
Security signals we found
Dependency version bump of security-critical firmware verification crate (foundation-firmware 0.2 -> 0.3)
New error variant mapping: VerifySignatureError::InvalidHeader now preserves underlying VerifyHeaderError details
C ABI functions marked unsafe with explicit safety preconditions on raw pointer arguments
No explicit vulnerability description or CVE reference in commit message or diff
Evidence from the diff
The diff bumps the foundation-firmware crate from 0.2.0 to 0.3.0 in Cargo.lock and Cargo.toml, regenerates the C header foundation.h with new doc comments, and modifies extmod/foundation-rust/src/firmware.rs. The Rust changes mark verify_update_header and verify_update_signatures as unsafe extern “C” functions, add SAFETY comments around slice::from_raw_parts, add a new mapping for VerifySignatureError::InvalidHeader, and update tests to call the now-unsafe functions inside unsafe blocks. These are API-alignment and safety-documentation changes rather than a standalone bug fix.
Changed components
extmod/foundation-rust/Cargo.lockextmod/foundation-rust/Cargo.tomlextmod/foundation-rust/include/foundation.hextmod/foundation-rust/src/firmware.rsfoundation-firmware Rust crate (external dependency)Inspect captured patch +63 / −14
### extmod/foundation-rust/Cargo.lock
@@ -133,9 +133,9 @@ checksum = "777e495443499419b935d80c5abffb7e7006859242c8a1d40b5831fea4911175"
[[package]]
name = "foundation-firmware"
-version = "0.2.0"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f3275fe6157eee489494fb148a173e0918181aacbd319c86e7d3fc3c221a241f"
+checksum = "3a758c0a99372a055268583d3cad1c4070334a3c955366da0499d5529f8431e1"
dependencies = [
"bitcoin_hashes",
"heapless",
### extmod/foundation-rust/Cargo.toml
@@ -29,7 +29,7 @@ version = "1"
default-features = false
[dependencies.foundation-firmware]
-version = "0.2"
+version = "0.3"
default-features = false
[dependencies.foundation-ur]
### extmod/foundation-rust/include/foundation.h
@@ -509,12 +509,25 @@ extern UR_Encoder UR_ENCODER;
/**
* Verify the header of a firmware update.
+ *
+ * # Safety
+ * `header` must be non-null and point to `header_len` initialized bytes in one
+ * allocation, with length at most `isize::MAX`. This memory must remain readable
+ * and unmodified for the call and must not overlap `result`.
*/
void foundation_firmware_verify_update_header(const uint8_t *header,
size_t header_len,
uint32_t current_timestamp,
FirmwareResult *result);
+/**
+ * Verify a firmware update's header and signatures against its hash.
+ *
+ * # Safety
+ * `header` must be non-null and point to `header_len` initialized bytes in one
+ * allocation, with length at most `isize::MAX`. This memory must remain readable
+ * and unmodified for the call and must not overlap `result`.
+ */
void foundation_firmware_verify_update_signatures(const uint8_t *header,
size_t header_len,
uint32_t current_timestamp,
### extmod/foundation-rust/src/firmware.rs
@@ -100,6 +100,7 @@ impl From<VerifySignatureError> for FirmwareResult {
VerifySignatureError::FailedSignature1 { .. } => FailedSignature1,
VerifySignatureError::FailedSignature2 { .. } => FailedSignature2,
VerifySignatureError::MissingUserPublicKey => MissingUserPublicKey,
+ VerifySignatureError::InvalidHeader(error) => error.into(),
}
}
}
@@ -143,13 +144,19 @@ fn verify_update_header_impl(
}
/// Verify the header of a firmware update.
+///
+/// # Safety
+/// `header` must be non-null and point to `header_len` initialized bytes in one
+/// allocation, with length at most `isize::MAX`. This memory must remain readable
+/// and unmodified for the call and must not overlap `result`.
#[export_name = "foundation_firmware_verify_update_header"]
-pub extern "C" fn verify_update_header(
+pub unsafe extern "C" fn verify_update_header(
header: *const u8,
header_len: usize,
current_timestamp: u32,
result: &mut FirmwareResult,
) {
+ // SAFETY: The C ABI supplies a raw buffer; the caller guarantees slice validity.
let header = unsafe { slice::from_raw_parts(header, header_len) };
match verify_update_header_impl(header, current_timestamp, result) {
@@ -172,15 +179,22 @@ pub extern "C" fn verify_update_header(
}
}
+/// Verify a firmware update's header and signatures against its hash.
+///
+/// # Safety
+/// `header` must be non-null and point to `header_len` initialized bytes in one
+/// allocation, with length at most `isize::MAX`. This memory must remain readable
+/// and unmodified for the call and must not overlap `result`.
#[export_name = "foundation_firmware_verify_update_signatures"]
-pub extern "C" fn verify_update_signatures(
+pub unsafe extern "C" fn verify_update_signatures(
header: *const u8,
header_len: usize,
current_timestamp: u32,
hash: &[u8; 32],
user_public_key: Option<&[u8; 64]>,
result: &mut FirmwareResult,
) {
+ // SAFETY: The C ABI supplies a raw buffer; the caller guarantees slice validity.
let header = unsafe { slice::from_raw_parts(header, header_len) };
let firmware_hash = match sha256d::Hash::from_slice(hash) {
Ok(v) => v,
@@ -266,7 +280,10 @@ mod tests {
fn check_header(header: &[u8]) -> FirmwareResult {
let mut result = FirmwareResult::SignaturesOk;
- verify_update_header(header.as_ptr(), header.len(), 0, &mut result);
+ // SAFETY: Testing the C entry point requires a raw pointer; the slice is live and separate from result.
+ unsafe {
+ verify_update_header(header.as_ptr(), header.len(), 0, &mut result);
+ }
result
}
@@ -276,14 +293,17 @@ mod tests {
key: &[u8; 64],
) -> FirmwareResult {
let mut result = FirmwareResult::SignaturesOk;
- verify_update_signatures(
- header.as_ptr(),
- header.len(),
- 0,
- hash,
- Some(key),
- &mut result,
- );
+ // SAFETY: Testing the C entry point requires a raw pointer; the slice is live and separate from result.
+ unsafe {
+ verify_update_signatures(
+ header.as_ptr(),
+ header.len(),
+ 0,
+ hash,
+ Some(key),
+ &mut result,
+ );
+ }
result
}
@@ -360,6 +380,22 @@ mod tests {
));
}
+ #[test]
+ fn signature_header_errors_preserve_installer_result() {
+ assert!(matches!(
+ FirmwareResult::from(VerifySignatureError::InvalidHeader(
+ VerifyHeaderError::InvalidPublicKey1Index(4)
+ )),
+ FirmwareResult::InvalidPublicKey1Index { index: 4 }
+ ));
+ assert!(matches!(
+ FirmwareResult::from(VerifySignatureError::InvalidHeader(
+ VerifyHeaderError::InvalidPublicKey2Index(u32::MAX)
+ )),
+ FirmwareResult::InvalidPublicKey2Index { index: u32::MAX }
+ ));
+ }
+
#[test]
fn sanity_test() {
assert_eq!(VERSION_LEN, foundation_firmware::VERSION_LEN);Why this scored 31/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.