Skip to content

Commit b820c3a

Browse files
committed
update TODO and some fmt looking changes
1 parent ba7f0f4 commit b820c3a

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

zeroize_stack/TODO.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ Copilot provided that code, but Gemini says that after the future is awaited, th
3030

3131
## Safe
3232

33-
* Panic when the OS is `hermit` or it is running on `wasm32` or `wasm64`, as their stacks don't behave the same as all of the others.
34-
3533
* Handle unwinds better: currently we return a `Result<R, Box<dyn Any + Send>>`. The error case is a little bit tricky to handle, as dropping the error could cause a panic. The program should either panic, or return the panic payload's message.
3634

35+
* Either:
36+
* Panic when the OS is `hermit` or it is running on `wasm32` or `wasm64`, as their stacks don't behave the same as all of the others.
37+
* Run the closure without `psm::on_stack` and generate a compiler warning stating that the target's stack layout is not supported with basic stack switching.
38+
* Implement different types of `AlignedHeapStack` to cover `wasm32` and `hermit` as performed in the `stacker` crate.
39+
3740
## Would require a PR to `stacker` to zero the allocated stack on drop
3841

3942
* Use stacker crate to handle stack size management: if I read some of the `stacker` docs correctly, that crate should be able to extend the size of the stack when it is about to overflow. If that is correct, we could use their techniques to allocate a new stack and zeroize the old one whenever our allocated stack is about to overflow, eliminating the primary remaining `# Safety` comment. Note: we may not be able to zeroize the old stack immediately as the stack switching process likely attempts to return to the old stack once execution completes; we might have to wait until execution completes before zeroizing all heap-stacks.

zeroize_stack/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ pub struct AlignedHeapStack {
8484
}
8585

8686
impl AlignedHeapStack {
87-
/// Creates a new `AlignedHeapStack`. `psm` recommends using at least `4 KB`
87+
/// Creates a new `AlignedHeapStack`. `psm` recommends using at least `4 KB`
8888
/// of stack space.
89-
///
89+
///
9090
/// # Panics
91-
///
91+
///
9292
/// This function panics when `size_kb * 1024` overflows `isize`.
9393
pub fn new(size_kb: usize) -> Self {
9494
assert!(
@@ -99,7 +99,7 @@ impl AlignedHeapStack {
9999
locked: false,
100100
stack: create_aligned_vec(size_kb, align_of::<u128>()),
101101
};
102-
// these may be redundant but I just want to be sure that the alignment doesn't
102+
// these may be redundant but I just want to be sure that the alignment doesn't
103103
// change somehow
104104
debug_assert_eq!(result.stack.as_ptr() as usize % align_of::<u128>(), 0);
105105
debug_assert_eq!(result.stack.len() % align_of::<u128>(), 0);
@@ -133,10 +133,10 @@ psm::psm_stack_manipulation! {
133133
///
134134
/// # Arguments
135135
///
136-
/// * `aligned_heap_stack` - the heap-based aligned region of memory to
137-
/// be used as the stack. `psm` recommends at least `4 KB` of stack
136+
/// * `aligned_heap_stack` - the heap-based aligned region of memory to
137+
/// be used as the stack. `psm` recommends at least `4 KB` of stack
138138
/// space, but the total size cannot overflow an `isize`. Also,
139-
/// some architectures might consume more memory in the stack, such as
139+
/// some architectures might consume more memory in the stack, such as
140140
/// SPARC.
141141
/// * `crypto_fn` - the code to run while on the separate stack.
142142
///

zeroize_stack/tests/zeroize_stack.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ mod stack_sanitization_tests {
4040
fn non_returning_function_test() {
4141
let mut heap_stack = AlignedHeapStack::new(4);
4242
let mut v = 0;
43-
unsafe { exec_on_sanitized_stack(&mut heap_stack, AssertUnwindSafe(|| non_returning_function(&mut v)))}.unwrap();
43+
unsafe {
44+
exec_on_sanitized_stack(
45+
&mut heap_stack,
46+
AssertUnwindSafe(|| non_returning_function(&mut v)),
47+
)
48+
}
49+
.unwrap();
4450
assert_eq!(v, 5);
4551
}
4652
}

0 commit comments

Comments
 (0)