Skip to content

Conversation

vishy11
Copy link

@vishy11 vishy11 commented Sep 23, 2025

Implements zeroization support across all heapless data structures to securely clear sensitive data from memory:

  • Added Zeroize trait implementations for Vector, CString, String, IndexMap, IndexSet, and other structures
  • Created tests verifying proper zeroization behavior for each structure
  • Added necessary documentation

This feature is essential for security-sensitive applications needing to prevent data leaks from memory dumps.

Note: Zeroize initially worked on Vector purely via derivation, however was not complete without proper bound checks. Without these checks, the deref implementation of Zeroize was used instead, which led to incomplete zeroization of the Vector's contents.

@zeenix
Copy link
Contributor

zeenix commented Sep 23, 2025

Thanks so much. I think it's definitely a good change. Before we do a proper review, could you please squash the commits and force push (please do not create a new PR).

Copy link
Contributor

@sgued sgued left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good feature to have, thank you.

A couple of changes are needed but this looks good!

src/vec/mod.rs Outdated
#[cfg_attr(
feature = "zeroize",
derive(Zeroize),
zeroize(bound = "S: Zeroize, LenT: Zeroize")
Copy link
Contributor

@sgued sgued Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that in the case the Zeroize feature is enabled, the LenType sealed trait can be a supertrait of Zeroize so that the bounds are simpler.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved!

@vishy11 vishy11 force-pushed the master branch 3 times, most recently from 23b933e to e08f29b Compare September 23, 2025 19:17
@zeenix
Copy link
Contributor

zeenix commented Sep 23, 2025

@vishy11 thanks! I hate to ask but could please rebase (rather than merge) on master, squash the remaining 2 commits and use the PR description as the commit message? Then we'll have a clean history. 🙏

@vishy11 vishy11 force-pushed the master branch 8 times, most recently from 7c07198 to ed337d8 Compare September 23, 2025 20:20
@vishy11
Copy link
Author

vishy11 commented Sep 23, 2025

@vishy11 thanks! I hate to ask but could please rebase (rather than merge) on master, squash the remaining 2 commits and use the PR description as the commit message? Then we'll have a clean history. 🙏

Apologies, was having a lot of the commits mess with each other - they should be good now. Let me know if you need any other changes and I'll do my best to get them done!

zeenix
zeenix previously approved these changes Sep 23, 2025
Copy link
Contributor

@zeenix zeenix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@zeenix
Copy link
Contributor

zeenix commented Sep 23, 2025

Apologies, was having a lot of the commits mess with each other - they should be good now. Let me know if you need any other changes and I'll do my best to get them done!

No worries. It looks all good now. For future reference, I'd suggest first checking the history locally to see everything is in order before submitting the PR and each time before pushing changes to the PR. It's just easier for reviewers this way. 👍

@vishy11 vishy11 requested a review from sgued September 24, 2025 13:49
#[cfg_attr(
feature = "zeroize",
derive(Zeroize),
zeroize(bound = "S: Zeroize, LenT: Zeroize")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zeroize(bound = "S: Zeroize, LenT: Zeroize")
zeroize(bound = "S: Zeroize")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved!

src/c_string.rs Outdated
Comment on lines 24 to 27
#[cfg(feature = "zeroize")]
impl<const N: usize, LenT: LenType> Zeroize for CString<N, LenT>
where
LenT: Zeroize,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[cfg(feature = "zeroize")]
impl<const N: usize, LenT: LenType> Zeroize for CString<N, LenT>
where
LenT: Zeroize,
#[cfg(feature = "zeroize")]
impl<const N: usize, LenT: LenType> Zeroize for CString<N, LenT>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved!

… securely clear sensitive data from memory:

- When the zeroize feature is enabled, the LenType sealed trait now has Zeroize as a supertrait
- This simplifies the bound for deriving Zeroize for VecInner and other types
- Added tests to verify VecView also implements Zeroize correctly

This feature is essential for security-sensitive applications needing to prevent data leaks from memory dumps.

Note: Zeroize initially worked on Vector purely via derivation, however was not complete without proper bound checks. Without these checks, the deref implementation of Zeroize was used instead, which led to incomplete zeroization of the Vector's contents.
Copy link
Contributor

@sgued sgued left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks for the contribution!

@sgued sgued added this pull request to the merge queue Sep 24, 2025
Merged via the queue into rust-embedded:main with commit bbe988d Sep 24, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants