Skip to content

Commit 00fd65b

Browse files
committed
Harden protection continuity and timing evidence
1 parent a6e546a commit 00fd65b

20 files changed

Lines changed: 836 additions & 418 deletions

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
run: scripts/ci_install_rust.sh
3535

3636
- name: Cache Rust build output
37-
uses: Swatinem/rust-cache@63fed3e2fecf6f7b51dc6f043341b79ef82a9ae7 # v2.9.2
37+
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
3838
with:
3939
cache-on-failure: true
4040

@@ -73,7 +73,7 @@ jobs:
7373
run: scripts/ci_install_rust.sh
7474

7575
- name: Cache Rust build output
76-
uses: Swatinem/rust-cache@63fed3e2fecf6f7b51dc6f043341b79ef82a9ae7 # v2.9.2
76+
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
7777
with:
7878
cache-on-failure: true
7979

@@ -116,7 +116,7 @@ jobs:
116116
run: rustup target add ${{ matrix.target }}
117117

118118
- name: Cache Rust build output
119-
uses: Swatinem/rust-cache@63fed3e2fecf6f7b51dc6f043341b79ef82a9ae7 # v2.9.2
119+
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
120120
with:
121121
cache-on-failure: true
122122

@@ -164,7 +164,7 @@ jobs:
164164
run: rustup target add ${{ matrix.target }}
165165

166166
- name: Cache Rust build output
167-
uses: Swatinem/rust-cache@63fed3e2fecf6f7b51dc6f043341b79ef82a9ae7 # v2.9.2
167+
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
168168
with:
169169
cache-on-failure: true
170170

‎.github/workflows/miri.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
rustup +"$MIRI_TOOLCHAIN" component add rust-src
3636
3737
- name: Cache Rust build output
38-
uses: Swatinem/rust-cache@63fed3e2fecf6f7b51dc6f043341b79ef82a9ae7 # v2.9.2
38+
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
3939
with:
4040
cache-on-failure: true
4141

‎.github/workflows/security-evidence.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
rustup target add --toolchain nightly x86_64-unknown-linux-gnu
4040
4141
- name: Cache Rust build output
42-
uses: Swatinem/rust-cache@63fed3e2fecf6f7b51dc6f043341b79ef82a9ae7 # v2.9.2
42+
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
4343
with:
4444
cache-on-failure: true
4545

@@ -68,7 +68,7 @@ jobs:
6868
run: cargo +nightly install cargo-fuzz --version 0.13.2 --locked
6969

7070
- name: Cache Rust build output
71-
uses: Swatinem/rust-cache@63fed3e2fecf6f7b51dc6f043341b79ef82a9ae7 # v2.9.2
71+
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
7272
with:
7373
cache-on-failure: true
7474

‎CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
standalone-tool lockfiles to current compatible dependency releases.
1010
- Update the pinned `Swatinem/rust-cache` GitHub Action to `2.9.2`; confirm
1111
checkout, artifact upload, and Kani actions remain current and SHA-pinned.
12+
- Pin `rust-cache` to the signed commit referenced by the annotated `v2.9.2`
13+
tag rather than the tag object's SHA.
14+
- Preserve established preferred protection controls across mapped growth and
15+
staged replacement. A replacement now fails before committing secret bytes
16+
if a previously accepted control cannot be re-established.
17+
- Retain isolated leakage-test excursions and require two fresh same-seed
18+
confirmations to pass without increasing the Welch threshold. Any repeated
19+
excursion remains release-blocking evidence.
1220
- Stop emitting full performance-baseline reports to CI stdout. Structured
1321
benchmark evidence remains in the requested JSON artifact, while console
1422
output is restricted to a fixed pass/fail status message.

‎crates/sanitization/src/mapped/guard_pages.rs‎

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ use core::{
1010
use core::cell::Cell;
1111

1212
use super::{
13-
CanaryCorruptedError, ForkPolicy, ForkProtectionRequest, ProtectedSecretFillError,
14-
ProtectionControl, ProtectionError, ProtectionFailure, ProtectionReport, ProtectionRequest,
15-
ProtectionState, Requirement, RollbackReport, RollbackState, SecretIntegrityError,
13+
protection::replacement_request_preserving_established, CanaryCorruptedError, ForkPolicy,
14+
ForkProtectionRequest, ProtectedSecretFillError, ProtectionControl, ProtectionError,
15+
ProtectionFailure, ProtectionReport, ProtectionRequest, ProtectionState, Requirement,
16+
RollbackReport, RollbackState, SecretIntegrityError,
1617
};
1718

1819
#[cfg(all(
@@ -1067,6 +1068,11 @@ impl GuardedSecretVec {
10671068
self.request
10681069
}
10691070

1071+
#[cfg(all(test, target_os = "linux", not(feature = "memory-lock")))]
1072+
pub(crate) fn mark_memory_lock_established_for_replacement_test(&mut self) {
1073+
self.report.memory_lock = ProtectionState::Established;
1074+
}
1075+
10701076
/// Run a closure with read-only access to initialized secret bytes.
10711077
#[inline]
10721078
pub fn try_with_secret<R>(
@@ -1122,17 +1128,18 @@ impl GuardedSecretVec {
11221128
/// If the current guarded mapping is large enough, the old writable
11231129
/// region is cleared before the new bytes are copied in. If the new
11241130
/// value requires a larger mapping, a replacement mapping is allocated
1125-
/// with the same lock state, populated with the new bytes, and then the
1126-
/// old mapping is cleared before it is unmapped.
1131+
/// without permitting an established preferred control to downgrade,
1132+
/// populated with the new bytes, and then the old mapping is cleared
1133+
/// before it is unmapped.
11271134
pub fn try_replace_from_slice(
11281135
&mut self,
11291136
bytes: &[u8],
11301137
) -> Result<(), SecretIntegrityError<GuardPageError>> {
11311138
self.verify_integrity()?;
11321139

11331140
if bytes.len() > self.data_capacity {
1134-
let mut replacement = Self::with_capacity_with_protection(bytes.len(), self.request)
1135-
.map_err(protection_error_as_guard_page)
1141+
let mut replacement = self
1142+
.replacement_with_capacity(bytes.len())
11361143
.map_err(SecretIntegrityError::Operation)?;
11371144
replacement.as_mut_capacity_slice()[..bytes.len()].copy_from_slice(bytes);
11381145
replacement.finish_initialization(bytes.len());
@@ -1150,16 +1157,17 @@ impl GuardedSecretVec {
11501157

11511158
/// Replace all initialized secret bytes with generated bytes.
11521159
///
1153-
/// A replacement mapping is allocated with the same lock state and
1154-
/// populated before the old mapping is cleared and swapped out.
1160+
/// A replacement mapping is allocated without permitting an established
1161+
/// preferred control to downgrade, then populated before the old mapping
1162+
/// is cleared and swapped out.
11551163
pub fn try_replace_from_fn(
11561164
&mut self,
11571165
len: usize,
11581166
mut make_byte: impl FnMut(usize) -> u8,
11591167
) -> Result<(), SecretIntegrityError<GuardPageError>> {
11601168
self.verify_integrity()?;
1161-
let mut replacement = Self::with_capacity_with_protection(len, self.request)
1162-
.map_err(protection_error_as_guard_page)
1169+
let mut replacement = self
1170+
.replacement_with_capacity(len)
11631171
.map_err(SecretIntegrityError::Operation)?;
11641172
replacement.fill_from_fn(len, &mut make_byte);
11651173

@@ -1179,8 +1187,8 @@ impl GuardedSecretVec {
11791187
mut make_byte: impl FnMut(usize) -> Result<u8, E>,
11801188
) -> Result<(), SecretIntegrityError<GuardedSecretVecGenerateError<E>>> {
11811189
self.verify_integrity()?;
1182-
let mut replacement = Self::with_capacity_with_protection(len, self.request)
1183-
.map_err(protection_error_as_guard_page)
1190+
let mut replacement = self
1191+
.replacement_with_capacity(len)
11841192
.map_err(GuardedSecretVecGenerateError::Guard)
11851193
.map_err(SecretIntegrityError::Operation)?;
11861194
replacement
@@ -1264,8 +1272,8 @@ impl GuardedSecretVec {
12641272
.saturating_mul(2)
12651273
.max(required)
12661274
.max(page_granule);
1267-
let mut replacement = Self::with_capacity_with_protection(next_capacity, self.request)
1268-
.map_err(protection_error_as_guard_page)
1275+
let mut replacement = self
1276+
.replacement_with_capacity(next_capacity)
12691277
.map_err(SecretIntegrityError::Operation)?;
12701278
replacement.as_mut_capacity_slice()[..self.len].copy_from_slice(self.as_slice());
12711279
replacement.finish_initialization(self.len);
@@ -1275,6 +1283,16 @@ impl GuardedSecretVec {
12751283
Ok(())
12761284
}
12771285

1286+
fn replacement_with_capacity(&self, capacity: usize) -> Result<Self, GuardPageError> {
1287+
let request = self.request;
1288+
let replacement_request =
1289+
replacement_request_preserving_established(request, &self.report, capacity);
1290+
let mut replacement = Self::with_capacity_with_protection(capacity, replacement_request)
1291+
.map_err(protection_error_as_guard_page)?;
1292+
replacement.request = request;
1293+
Ok(replacement)
1294+
}
1295+
12781296
/// Run a closure with shared access, panicking on canary corruption.
12791297
#[inline]
12801298
pub fn with_secret_or_panic<R>(&self, inspect: impl FnOnce(&[u8]) -> R) -> R {

‎crates/sanitization/src/mapped/memory_lock_native.rs‎

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ unsafe extern "C" {
1515
}
1616

1717
use super::{
18-
CanaryCorruptedError, ForkPolicy, ForkProtectionRequest, ProtectedSecretFillError,
19-
ProtectionControl, ProtectionError, ProtectionFailure, ProtectionReport, ProtectionRequest,
20-
ProtectionState, Requirement, RollbackReport, RollbackState, SecretIntegrityError,
21-
SecretPoolReport, SecretPoolSlotId,
18+
protection::replacement_request_preserving_established, CanaryCorruptedError, ForkPolicy,
19+
ForkProtectionRequest, ProtectedSecretFillError, ProtectionControl, ProtectionError,
20+
ProtectionFailure, ProtectionReport, ProtectionRequest, ProtectionState, Requirement,
21+
RollbackReport, RollbackState, SecretIntegrityError, SecretPoolReport, SecretPoolSlotId,
2222
};
2323

2424
#[cfg(all(
@@ -1074,7 +1074,13 @@ impl<const N: usize> LockedSecretBytes<N> {
10741074
}
10751075

10761076
fn replacement_zeroed(&self) -> Result<Self, MemoryLockError> {
1077-
Self::zeroed_with_protection(self.request).map_err(protection_error_as_memory_lock)
1077+
let request = self.request;
1078+
let replacement_request =
1079+
replacement_request_preserving_established(request, &self.report, N);
1080+
let mut replacement = Self::zeroed_with_protection(replacement_request)
1081+
.map_err(protection_error_as_memory_lock)?;
1082+
replacement.request = request;
1083+
Ok(replacement)
10781084
}
10791085

10801086
/// Fill a caller-provided destination with a copy of the secret bytes.
@@ -2070,6 +2076,11 @@ impl LockedSecretVec {
20702076
self.request
20712077
}
20722078

2079+
#[cfg(all(test, target_os = "linux"))]
2080+
pub(crate) fn mark_guard_pages_established_for_replacement_test(&mut self) {
2081+
self.report.guard_pages = ProtectionState::Established;
2082+
}
2083+
20732084
/// Returns true when the pool mapping is locked against ordinary paging.
20742085
#[must_use]
20752086
#[inline]
@@ -2383,8 +2394,13 @@ impl LockedSecretVec {
23832394
}
23842395

23852396
fn replacement_with_capacity(&self, capacity: usize) -> Result<Self, MemoryLockError> {
2386-
Self::with_capacity_with_protection(capacity, self.request)
2387-
.map_err(protection_error_as_memory_lock)
2397+
let request = self.request;
2398+
let replacement_request =
2399+
replacement_request_preserving_established(request, &self.report, capacity);
2400+
let mut replacement = Self::with_capacity_with_protection(capacity, replacement_request)
2401+
.map_err(protection_error_as_memory_lock)?;
2402+
replacement.request = request;
2403+
Ok(replacement)
23882404
}
23892405

23902406
fn fill_from_fn(&mut self, len: usize, make_byte: &mut impl FnMut(usize) -> u8) {

‎crates/sanitization/src/mapped/memory_lock_wasm.rs‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ use core::{
88
use core::cell::Cell;
99

1010
use super::{
11-
CanaryCorruptedError, ForkPolicy, ProtectionControl, ProtectionError, ProtectionFailure,
12-
ProtectionReport, ProtectionRequest, ProtectionState, Requirement, RollbackReport,
13-
SecretIntegrityError, SecretPoolReport, SecretPoolSlotId,
11+
protection::replacement_request_preserving_established, CanaryCorruptedError, ForkPolicy,
12+
ProtectionControl, ProtectionError, ProtectionFailure, ProtectionReport, ProtectionRequest,
13+
ProtectionState, Requirement, RollbackReport, SecretIntegrityError, SecretPoolReport,
14+
SecretPoolSlotId,
1415
};
1516

1617
#[cfg(feature = "canary-check")]
@@ -757,7 +758,13 @@ impl<const N: usize> LockedSecretBytes<N> {
757758
}
758759

759760
fn replacement_zeroed(&self) -> Result<Self, MemoryLockError> {
760-
Self::zeroed_with_protection(self.request).map_err(protection_error_as_memory_lock)
761+
let request = self.request;
762+
let replacement_request =
763+
replacement_request_preserving_established(request, &self.report, N);
764+
let mut replacement = Self::zeroed_with_protection(replacement_request)
765+
.map_err(protection_error_as_memory_lock)?;
766+
replacement.request = request;
767+
Ok(replacement)
761768
}
762769

763770
/// Fill a caller-provided destination with a copy of the secret bytes.

‎crates/sanitization/src/mapped/protection.rs‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,45 @@ impl ProtectionReport {
721721
}
722722
}
723723

724+
/// Derive the effective policy for replacement storage without permitting an
725+
/// established preferred control to disappear during growth or replacement.
726+
///
727+
/// The returned request is used only while constructing the replacement. The
728+
/// replacement owner retains the caller's original request after construction
729+
/// so future operations can derive continuity from their then-current report.
730+
#[cfg(any(feature = "memory-lock", feature = "guard-pages"))]
731+
pub(crate) const fn replacement_request_preserving_established(
732+
mut request: ProtectionRequest,
733+
report: &ProtectionReport,
734+
next_bytes: usize,
735+
) -> ProtectionRequest {
736+
preserve_control(&mut request.memory_lock, report.memory_lock, next_bytes);
737+
preserve_control(
738+
&mut request.dump_exclusion,
739+
report.dump_exclusion,
740+
next_bytes,
741+
);
742+
preserve_control(&mut request.fork.requirement, report.fork.state, next_bytes);
743+
preserve_control(&mut request.guard_pages, report.guard_pages, next_bytes);
744+
preserve_control(&mut request.canary, report.canary, next_bytes);
745+
preserve_control(&mut request.cache_policy, report.cache_policy, next_bytes);
746+
request
747+
}
748+
749+
#[cfg(any(feature = "memory-lock", feature = "guard-pages"))]
750+
const fn preserve_control(
751+
requirement: &mut Requirement,
752+
state: ProtectionState,
753+
next_bytes: usize,
754+
) {
755+
if matches!(*requirement, Requirement::Preferred)
756+
&& (matches!(state, ProtectionState::Established)
757+
|| (next_bytes != 0 && matches!(state, ProtectionState::NotApplicable)))
758+
{
759+
*requirement = Requirement::Required;
760+
}
761+
}
762+
724763
const fn mapping_satisfies(state: ProtectionState, empty: bool) -> bool {
725764
matches!(state, ProtectionState::Established)
726765
|| (empty && matches!(state, ProtectionState::NotApplicable))
@@ -770,6 +809,71 @@ fn unavailable_control(
770809
}
771810
}
772811

812+
#[cfg(all(test, any(feature = "memory-lock", feature = "guard-pages")))]
813+
mod tests {
814+
use super::*;
815+
816+
#[test]
817+
fn replacement_requires_previously_established_preferred_controls() {
818+
let request = ProtectionRequest {
819+
memory_lock: Requirement::Preferred,
820+
dump_exclusion: Requirement::Preferred,
821+
fork: ForkProtectionRequest::exclude(Requirement::Preferred),
822+
guard_pages: Requirement::Preferred,
823+
canary: Requirement::Preferred,
824+
cache_policy: Requirement::Preferred,
825+
};
826+
let mut report = ProtectionReport::pending(request, 32, 4096);
827+
report.mapping = ProtectionState::Established;
828+
report.memory_lock = ProtectionState::Established;
829+
report.dump_exclusion = ProtectionState::Established;
830+
report.fork.state = ProtectionState::Established;
831+
report.guard_pages = ProtectionState::Established;
832+
report.canary = ProtectionState::Established;
833+
report.cache_policy = ProtectionState::Established;
834+
835+
let replacement = replacement_request_preserving_established(request, &report, 64);
836+
837+
assert_eq!(replacement.memory_lock, Requirement::Required);
838+
assert_eq!(replacement.dump_exclusion, Requirement::Required);
839+
assert_eq!(replacement.fork.requirement, Requirement::Required);
840+
assert_eq!(replacement.guard_pages, Requirement::Required);
841+
assert_eq!(replacement.canary, Requirement::Required);
842+
assert_eq!(replacement.cache_policy, Requirement::Required);
843+
}
844+
845+
#[test]
846+
fn replacement_does_not_upgrade_controls_that_were_already_degraded() {
847+
let request = ProtectionRequest::wasm_compatibility();
848+
let mut report = ProtectionReport::pending(request, 32, 0);
849+
report.mapping = ProtectionState::CompatibilityOnly;
850+
report.memory_lock = ProtectionState::CompatibilityOnly;
851+
report.dump_exclusion = ProtectionState::Unsupported;
852+
report.fork.state = ProtectionState::Unsupported;
853+
854+
assert_eq!(
855+
replacement_request_preserving_established(request, &report, 64),
856+
request
857+
);
858+
}
859+
860+
#[test]
861+
fn nonempty_replacement_requires_controls_accepted_for_empty_storage() {
862+
let request = ProtectionRequest::wasm_compatibility();
863+
let mut report = ProtectionReport::pending(request, 0, 0);
864+
report.mapping = ProtectionState::NotApplicable;
865+
report.memory_lock = ProtectionState::NotApplicable;
866+
report.dump_exclusion = ProtectionState::NotApplicable;
867+
report.fork.state = ProtectionState::NotApplicable;
868+
869+
let replacement = replacement_request_preserving_established(request, &report, 1);
870+
871+
assert_eq!(replacement.memory_lock, Requirement::Required);
872+
assert_eq!(replacement.dump_exclusion, Requirement::Required);
873+
assert_eq!(replacement.fork.requirement, Requirement::Required);
874+
}
875+
}
876+
773877
#[allow(dead_code)]
774878
const fn initial_state(requirement: Requirement) -> ProtectionState {
775879
match requirement {

0 commit comments

Comments
 (0)