Skip to content

proto_handshake: clear the cookie before freeing it - #441

Open
woahwhattheheck wants to merge 1 commit into
Tarsnap:masterfrom
woahwhattheheck:proto-handshake-clear-cookie
Open

proto_handshake: clear the cookie before freeing it#441
woahwhattheheck wants to merge 1 commit into
Tarsnap:masterfrom
woahwhattheheck:proto-handshake-clear-cookie

Conversation

@woahwhattheheck

@woahwhattheheck woahwhattheheck commented Sep 6, 2026

Copy link
Copy Markdown

Disclosure, per this repository's AGENTS.md: I am an LLM (Claude), submitting on behalf of the account owner. I am available to discuss this change and to revise it in response to review feedback.

Fixes #440.

struct handshake_cookie holds x — the diffie-hellman private value, whose
being forgotten is what makes the PFS handshake forward-secret — and the two
diffie-hellman parameter MAC keys derived from the shared secret. All four
sites which free the cookie did so without wiping it:

  • handshakefail()
  • proto_handshake() at err1
  • handshakedone(), which runs once per successful connection, at exactly the
    point where x has served its purpose
  • proto_handshake_cancel()

Four insecure_memzero() calls and the include; no other change.

Why all four rather than only where x is populated

err1 is reached before the diffie-hellman value is ever generated, so
strictly it has nothing to protect. I wiped it anyway so that "the cookie is
always cleared before it is freed" is a property that holds without the reader
having to trace which paths populate what — the same reasoning as
scryptenc.c, which wipes dk at err1 on paths where it may never have
been filled in. Happy to drop that one if you would rather keep it exact.

The nonces and yh_* values in the cookie go over the wire in the clear, so
they are not the point here; they are simply covered by wiping the whole
structure, which is cheaper and less fragile than picking members.

struct handshake_cookie holds x, the diffie-hellman private value, and the
two diffie-hellman parameter MAC keys derived from the shared secret.  All
four sites which free the cookie did so without wiping it: handshakefail(),
proto_handshake() at err1, handshakedone(), and proto_handshake_cancel().

handshakedone() runs once per successful connection, at exactly the point
where x has served its purpose and should stop existing; forgetting it is
what makes the PFS handshake forward-secret.

Wipe on all four rather than only where x is known to be populated, so that
"the cookie is cleared before it is freed" holds without tracing which paths
populate what, as scryptenc.c does with dk at err1.  The nonces and yh_*
values go over the wire in the clear and are simply covered by wiping the
whole structure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[bug bounty] The handshake cookie, holding the diffie-hellman private value, is freed without being wiped

2 participants