Skip to content

Discard a rejected CBC packet before failing - #1281

Open
ejohnstown wants to merge 1 commit into
wolfSSL:masterfrom
ejohnstown:sf29
Open

ejohnstown wants to merge 1 commit into
wolfSSL:masterfrom
ejohnstown:sf29

Conversation

@ejohnstown

Copy link
Copy Markdown
Contributor

Under AES-CBC, a packet rejected on its length or its MAC no longer fails at once. DoReceive() reads it out to MAX_PACKET_SZ bytes and runs the MAC over the rest first, as OpenSSH does, so neither the failure point nor the MAC work reveals the length.

  • RejectPacket() and DiscardPacket() handle every length and MAC rejection; a PROCESS_DISCARD state resumes after a want-read, and a transport failure mid-discard still reports the rejection (F-12606, F-8807, F-11668).
  • CTR, AEAD and unencrypted packets still fail immediately; the discard compiles out under WOLFSSH_NO_AES_CBC.
  • tests/unit.c covers each rejection with short reads, a peer close, and a nonzero start offset.

Under AES-CBC, DoReceive() no longer fails as soon as the decrypted
length or the MAC is rejected. It reads the packet out to MAX_PACKET_SZ
bytes and runs the MAC over the rest first, as OpenSSH does, so neither
the failure point nor the MAC work reveals the length.

- the length checks and the MAC check all go through RejectPacket()
- a PROCESS_DISCARD state resumes the discard after a want-read; a
  transport failure mid-discard reports the rejection
- CTR, AEAD and unencrypted packets still fail immediately
- the discard compiles out under WOLFSSH_NO_AES_CBC
- tests/unit.c covers each rejection with short reads, a peer close,
  and a nonzero start offset

Issue: F-12606, F-8807, F-11668
Copilot AI balanced review requested due to automatic review settings September 29, 2026 23:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The discard path masks local allocation failures as packet-rejection errors.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds constant-work rejection handling for malformed AES-CBC packets to reduce timing leakage.

Changes:

  • Introduces resumable rejected-packet discard state.
  • Preserves immediate rejection for non-CBC modes.
  • Adds CBC discard and CTR regression tests.
File Description
wolfssh/​internal.h Adds discard state and metadata.
src/​internal.c Implements CBC packet discard handling.
tests/​unit.c Tests discard behavior and immediate CTR failure.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/internal.c
Comment on lines +14614 to +14619
if (ret < 0) {
/* Past a want-read the discard is over; report the rejection. */
if (ssh->error != WS_WANT_READ)
ssh->error = ssh->discardError;
return ret;
}
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.

2 participants