Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-8275] Implement a zeroizing allocator #788

Merged
merged 21 commits into from
May 23, 2024
Merged

[PM-8275] Implement a zeroizing allocator #788

merged 21 commits into from
May 23, 2024

Conversation

Hinton
Copy link
Member

@Hinton Hinton commented May 16, 2024

Type of change

- [ ] Bug fix
- [x] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

Add a custom allocator which zerorizes memory on drop. This should ensure everything heap allocated gets sanitized before deallocated, and avoid sensitive memory being exposed more reliably than using Sensitive.

Before you submit

  • Please add unit tests where it makes sense to do so

Copy link
Contributor

github-actions bot commented May 16, 2024

Logo
Checkmarx One – Scan Summary & Detailsa660adb5-526b-4b7c-be1e-1c88050ac223

No New Or Fixed Issues Found

Copy link

codecov bot commented May 16, 2024

Codecov Report

Attention: Patch coverage is 0% with 97 lines in your changes are missing coverage. Please review.

Please upload report for BASE (main@5d8536b). Learn more about missing BASE report.

Current head 4ab4af7 differs from pull request most recent head 3605dbb

Please upload reports for the commit 3605dbb to get more accurate results.

Files Patch % Lines
crates/bitwarden-crypto/src/allocator.rs 0.00% 97 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #788   +/-   ##
=======================================
  Coverage        ?   57.96%           
=======================================
  Files           ?      179           
  Lines           ?    11652           
  Branches        ?        0           
=======================================
  Hits            ?     6754           
  Misses          ?     4898           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hinton Hinton changed the title Explore using a custom allocator Implement a zeroizing allocator May 20, 2024
@Hinton Hinton marked this pull request as ready for review May 20, 2024 13:04
@Hinton Hinton changed the title Implement a zeroizing allocator [PM-8275] Implement a zeroizing allocator May 20, 2024
Copy link
Member

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

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

Allocator look good to me and seems to be working correctly, but I'm not sure about having to define #[global_allocator] in every crate. It might make us accidentally forget to enable it in some future new crate. We should also probably enable it for bitwarden-uniffi.

What if instead we defined the global allocator in the bitwarden crate under some secure-allocator feature flag which is enabled by default? That way all our crates will get the new allocator for free, and anyone using our Rust crate who might prefer a different allocator can just disable the default flags.

@Hinton Hinton requested a review from dani-garcia May 21, 2024 16:11
crates/bitwarden-c/Cargo.toml Outdated Show resolved Hide resolved
crates/bitwarden-crypto/Cargo.toml Outdated Show resolved Hide resolved
crates/bitwarden/Cargo.toml Outdated Show resolved Hide resolved
@Hinton Hinton requested a review from dani-garcia May 21, 2024 17:39
dani-garcia
dani-garcia previously approved these changes May 21, 2024
Copy link
Member

Choose a reason for hiding this comment

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

Please add features documentation to this front page as described in https://doc.rust-lang.org/cargo/reference/features.html#feature-documentation-and-discovery.

Especially since you're worried about unintentionally disabling memory hardening and thus not following the additive feature standard

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I've added some documentation.

dani-garcia
dani-garcia previously approved these changes May 23, 2024
# Conflicts:
#	crates/memory-testing/src/main.rs
@Hinton Hinton merged commit 0ca7dc4 into main May 23, 2024
86 checks passed
@Hinton Hinton deleted the ps/allocator branch May 23, 2024 16:07
Hinton added a commit that referenced this pull request Jun 3, 2024
Wraps up the custom allocator effort introduced in #788 by removing the
now no longer needed `Sensitive` type.
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.

None yet

3 participants