Advance replay window only after CCM tag verifies#5
Open
balloob wants to merge 1 commit into
Open
Conversation
verifyNonceReplay() both checked and advanced the replay window on the cleartext nonce, before the AES-CCM tag was verified. In an active session an attacker could send a forged frame with a high counter: it passed the replay check (not yet seen), the window advanced to that high counter, then the CCM tag failed and the frame was rejected -- but the window was now desynced, so subsequent legitimate frames with lower counters were rejected as replays. This is a denial-of-service on the session. Split the advance out of verifyNonceReplay() into advanceNonceReplay() and call it from decryptCommand() only after the CCM tag has verified. The replay-reject check stays before decrypt (a cheap, correct early-out for genuine replays); a forged frame with a bad tag no longer mutates last_seen_counter/replay_window. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012g2e8mr132vcizx92WsgiR
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.
The problem
verifyNonceReplay()checked the replay window and advancedlast_seen_counter/replay_windowon the cleartext nonce, before the AES-CCM tag was verified. The replay check runs on the plaintext nonce prior to decrypt.In an active session an attacker can exploit this to DoS the session:
last_seen_counterjumps to that high counter.A forged frame with a bad tag must never mutate the replay window.
The fix
Split the window advance out of
verifyNonceReplay()into a newadvanceNonceReplay(), and call it fromdecryptCommand()only after the AES-CCM tag has verified successfully.The replay reject check stays where it is (before decrypt) — it's a cheap, correct early-out for genuine replays. The reorder is now:
advanceNonceReplay()records the counter and bumps the window exactly once.Verification
No ARM SDK toolchain in this environment, so the reordered logic was extracted verbatim into a host-gcc harness (compiles clean under
-Wall -Wextra):Companion change
The Silabs firmware has the same issue — its replay window was just added in OpenDisplay/Firmware_Silabs#5 — and is being fixed there in lockstep.
🤖 Generated with Claude Code
https://claude.ai/code/session_012g2e8mr132vcizx92WsgiR
Companion PR: OpenDisplay/Firmware_Silabs#5 (same advance-after-auth reorder, Silabs — folded into its replay-protection PR). Both: reject-before-decrypt, advance-window-only-after-CCM-tag.