Skip to content

Propagate only WANT_WRITE in DoKexInit - #1278

Open
ejohnstown wants to merge 1 commit into
wolfSSL:masterfrom
ejohnstown:kexinit-stale-error
Open

ejohnstown wants to merge 1 commit into
wolfSSL:masterfrom
ejohnstown:kexinit-stale-error

Conversation

@ejohnstown

@ejohnstown ejohnstown commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

DoKexInit() now reports ssh->error to its caller only when it is
WS_WANT_WRITE. A stale WS_WINDOW_FULL left by SendChannelData() no
longer fails the peer's rekey.

  • tests/regress.c covers stale WS_SUCCESS, WS_WINDOW_FULL and
    WS_CHAN_RXD, and a blocked reply send.

Issue: F-14394

DoKexInit() reports ssh->error once it has handled the KEXINIT, so a
blocked reply reaches the caller. Report it only when it is
WS_WANT_WRITE. Anything else in ssh->error is left by an earlier call,
and a WS_WINDOW_FULL from SendChannelData() failed the peer's rekey.

- tests/regress.c runs DoKexInit() with WS_SUCCESS, WS_WINDOW_FULL and
  WS_CHAN_RXD left in ssh->error, and with the reply send blocked.

Issue: F-14394
@ejohnstown
ejohnstown requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot September 29, 2026 00:24

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #1278

Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 1 of 2 in-scope changed file(s) opened by the reviewer; not opened: tests/regress.c

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 High severity · 4 Medium severity

Open (5)
What changed in this PR

Updates DoKexInit() to only propagate WS_WANT_WRITE back to the caller (avoiding failures due to unrelated stale ssh->error values) and adds regression coverage around stale errors and blocked reply sends.

Changes:

  • Limit DoKexInit() error propagation to WS_WANT_WRITE only.
  • Add a regression helper and test cases to validate stale ssh->error handling and blocked send behavior.
  • Wire the new regression test into main() under an existing compile-time guard.
File Description
tests/​regress.c Adds a regression harness/test to ensure stale ssh->error values don’t break peer rekey, while still reporting blocked reply sends.
src/​internal.c Changes DoKexInit() to propagate only WS_WANT_WRITE instead of any non-zero ssh->error.

💡 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 +6938 to +6943
/* Propagate a want write from SendKexInit(). Only that: other
* codes in ssh->error are left by earlier calls, such as a
* WS_WINDOW_FULL from SendChannelData(), and would fail the
* key exchange. */
if (ssh->error == WS_WANT_WRITE)
ret = WS_WANT_WRITE;
Comment thread src/internal.c
Comment on lines +6938 to +6943
/* Propagate a want write from SendKexInit(). Only that: other
* codes in ssh->error are left by earlier calls, such as a
* WS_WINDOW_FULL from SendChannelData(), and would fail the
* key exchange. */
if (ssh->error == WS_WANT_WRITE)
ret = WS_WANT_WRITE;
Comment thread tests/regress.c
@@ -14859,6 +14859,75 @@ static void TestKexInitReservedNonZeroRejected(void)
wolfSSH_CTX_free(ctx);
}

Comment thread tests/regress.c
AssertIntEQ(wolfSSH_SetAlgoListKey(ssh, FPF_KEY_GOOD), WS_SUCCESS);

payloadSz = BuildKexInitPayload(ssh, FPF_KEX_GOOD, FPF_KEY_GOOD,
0, payload, (word32)sizeof(payload));
Comment thread tests/regress.c
Comment on lines +14920 to +14928
static void TestKexInitIgnoresStaleError(void)
{
AssertIntEQ(RunKexInitWithError(WS_SUCCESS, 0), WS_SUCCESS);
AssertIntEQ(RunKexInitWithError(WS_WINDOW_FULL, 0), WS_SUCCESS);
AssertIntEQ(RunKexInitWithError(WS_CHAN_RXD, 0), WS_SUCCESS);
/* A blocked reply is still reported. */
AssertIntEQ(RunKexInitWithError(WS_SUCCESS, 1), WS_WANT_WRITE);
AssertIntEQ(RunKexInitWithError(WS_WINDOW_FULL, 1), WS_WANT_WRITE);
}
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.

3 participants