Skip to content
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
46 changes: 29 additions & 17 deletions drivers/soc/apple/refkey.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT
// Copyright 2026 Dj
//! Machine ref-key: Secure-Enclave key sealing, signing, and attestation.
Expand Down Expand Up @@ -98,6 +98,8 @@
profile::KeyStore::Variant5 => (9, 5),
};

// A ref-key created this boot belongs to the current boot policy.
crate::xart_guard::close_policy_window();
if self.profile.key_store == profile::KeyStore::Variant5 {
// On variant 5 the ref-key is bound to the unlocked identity bag.
if let Some(healthy) = self.sks_health_check(c"ref-key create") {
Expand Down Expand Up @@ -280,16 +282,24 @@
return Err(ENODEV);
};
let (handle, _uuid) = self.sks_recover(&stored).ok_or(EIO)?;
if self.profile.key_store == profile::KeyStore::Variant5 {
if let Some(healthy) = self.sks_health_check(c"trusted-key unseal") {
let _ = self.sks_send(self.sks_req_change_lock_state(
handle,
LockState::Unlocked,
stored.secret(),
healthy,
));
// The first unlock under a changed boot policy rewrites one session
// record; see crate::xart_guard.
let unlocked = crate::xart_guard::policy_window(|| {
if self.profile.key_store == profile::KeyStore::Variant5 {
if let Some(healthy) = self.sks_health_check(c"trusted-key unseal") {
let _ = self.sks_send(self.sks_req_change_lock_state(
handle,
LockState::Unlocked,
stored.secret(),
healthy,
));
}
true
} else {
self.sks_prepare_identity_refkey(handle, stored.secret())
}
} else if !self.sks_prepare_identity_refkey(handle, stored.secret()) {
});
if !unlocked {
let _ = self.sks_send(self.sks_req_unload_keybag(handle));
return Err(EIO);
}
Expand Down Expand Up @@ -349,14 +359,16 @@
return Err(ENODEV);
};
let (handle, _uuid) = self.sks_recover(&stored).ok_or(EIO)?;
if let Some(healthy) = self.sks_health_check(c"ref-key attest") {
let _ = self.sks_send(self.sks_req_change_lock_state(
handle,
LockState::Unlocked,
stored.secret(),
healthy,
));
}
crate::xart_guard::policy_window(|| {
if let Some(healthy) = self.sks_health_check(c"ref-key attest") {
let _ = self.sks_send(self.sks_req_change_lock_state(
handle,
LockState::Unlocked,
stored.secret(),
healthy,
));
}
});
let sig = self.sks_refkey_sign(handle, &blob, challenge);
let _ = self.sks_send(self.sks_req_unload_keybag(handle));
Ok((sig.ok_or(EIO)?, pubk))
Expand Down
15 changes: 10 additions & 5 deletions drivers/soc/apple/trusted.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT
// Copyright 2026 Dj

Expand Down Expand Up @@ -106,11 +106,16 @@
let blob = match sep.refkey_seal_trusted(key) {
Ok(blob) => blob,
Err(e) => {
dev_warn!(
sep.dev,
"trusted-keys: seal failed ({:?}); the machine ref-key may not be established yet\n",
e
);
// Callers retry until the ref-key is up: warn once, and keep
// each failure for debugging.
kernel::do_once_lite! {
dev_warn!(
sep.dev,
"trusted-keys: seal failed ({:?}); the machine ref-key may not be established yet\n",
e
);
}
dev_dbg!(sep.dev, "trusted-keys: seal failed ({:?})\n", e);
return e.to_errno();
}
};
Expand Down
Loading
Loading