Repository navigation
Add an opt-in zeroize feature that wipes codec buffers - #201
Open
MattJackson wants to merge 2 commits into
Open
MattJackson wants to merge 2 commits into
MattJackson wants to merge 2 commits into
Conversation
With the new `zeroize` feature the packet codec overwrites protocol bytes with zeros once it is done with them: * bytes consumed from the input buffer are wiped before the buffer advances past them (plain chunks and compressed envelopes); * `compress` wipes its input before clearing it; * buffers that need to grow move into a new allocation and the old one is wiped first, instead of `BytesMut::reserve` releasing or reusing it as is; * partial output left in spare capacity by a failed inflate or deflate is wiped; * the compressed codec wipes its staging buffer when encoding fails, and both of its buffers on drop. Without the feature the code is unchanged in behaviour. CI runs the codec tests with the feature enabled.
Replace the broad claim that the codec's buffers are wiped with an exact list of what is overwritten and what is not: the flate2 compressor/decompressor state (zlib window) and caller-owned dst buffers are not wiped. Mention the test-only global allocator. Documentation only; no behaviour change.
Author
|
I tightened the docs; the wiping logic is unchanged. This adds a precise list of what is and is not wiped to the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add an opt-in
zeroizefeature for best-effort wiping of the packet codec's buffers.With
zeroizeenabled the codec overwrites with zeros: bytes consumed from thesrcbuffer ofPacketCodec::decode(before the buffer advances), the compressed codec's staging buffers on clear / regrow (old allocation wiped after copying) / drop, the compress input after compression, and partial output left in spare capacity by a failed inflate/deflate. Without the feature behaviour is unchanged. CI runs the codec tests with the feature on.Limitations (also documented on
PacketCodec, README and crate docs):flate2Compress/Decompress state, including the zlib window (up to 32 KiB of recent plaintext), is not wiped; flate2 offers no hook for it;decode'sdst(including earlier allocations it releases when it grows,BytesMutorVec<u8>), and the encoded bytes inencode'sdst(if the codec itself grows thatdst, the old allocation is wiped);encode, and anything outside the codec (sockets, kernel, caller copies), is out of scope.The tests install a
#[global_allocator]that applies to all lib tests when built with--features "test zeroize"; it only delegates toSystemand is noted inzeroize_tests.rs.