Repository navigation
fix: clear sign_hmac key residue from the stack - #22
Merged
Merged
Conversation
Merged
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.
sign_hmacran HMAC-SHA256 through thesha2hasher, which does not zero its chaining state and is moved by value. A stack probe on aarch64 macOS found key-derived values on the stack after one call onmain: at least half of the inner and of the outer chaining state in the shipped LTO build, three copies of each in a debug build, and a ChaCha20 state holding the vault master key in a release build without LTO.hmac_sha256drivessha2::block_api::compress256directly. The padded key, the chaining state, the last padded block and the inner digest each live in their ownZeroizingbuffer and are only passed by reference.sign_hmaccalls the key-touching part (hmac_with_secret,#[inline(never)]) and thenscrub_stack, which overwrites 32 KiB of stack below the caller.hmaccrate (new dev-dependency) as an oracle for key and message lengths around the block boundaries, and the SHA-256 padding againstSha256::digestfor every length from 0 to 193.After the fix the probe found nothing in the shipped LTO build, a release build without LTO, a debug build, and the software SHA-256 backend. The other paths that decrypt under the master key (
decrypt_secretbehindreserve_invoke,retrieve_secretbehindconsume,encrypt_and_store) are not scrubbed yet. Registers are not cleared. Linux x86_64 is not measured.Cost:
sign_hmacwith a 256-byte payload, median of 7 x 200,000 calls, shipped profile: 2.31 µs onmain, 1.98 to 2.00 µs here. The direct compression calls and the single padded-key buffer save more than the scrub costs.Local: fmt, clippy
-D warnings, cargo 110 passed (macOS), pytest 131 passed and 1 skipped with the real broker.