Skip to content

GH-952: Release IdentFilter write queue after forwarding message - #953

Merged
tomaswolf merged 1 commit into
apache:dev_3.0from
abhiramaab:fix-ident-filter-kexinit-ordering
Nov 10, 2026
Merged

tomaswolf merged 1 commit into
apache:dev_3.0from
abhiramaab:fix-ident-filter-kexinit-ordering

Conversation

@abhiramaab

Copy link
Copy Markdown

Summary

Fixes #952.

IdentFilter.WriteHandler.send() prematurely released its write queue guard using lastWrite.compareAndSet(result, null) inside the queue.addListener callback, before invoking owner().send(cmd, message).

Under concurrent message dispatch, a subsequent call to send() (e.g., SSH_MSG_KEX_FIRST during key exchange negotiation) could observe lastWrite == null, bypass the queue, and reach the output sink before SSH_MSG_KEXINIT, violating message ordering.

Changes

  1. Moved lastWrite.compareAndSet(result, null) to execute after owner().send(...) in IdentFilter.java, ensuring the write queue remains guarded until the current message is handed off.
  2. Added the regression test concurrentSendDuringKexInitDoesNotOvertake in IdentFilterTest.java to verify that messages queued during identification and KEXINIT processing cannot overtake each other.

Verification

  • ./mvnw test -pl sshd-core -Dtest=IdentFilterTest passes.
  • Verified code style and formatting using checkstyle:check, formatter:validate, and impsort:check.

All checks passed with 0 violations.

Copilot AI balanced review requested due to automatic review settings November 9, 2026 07:05

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@tomaswolf

Copy link
Copy Markdown
Member

Thank you for this contribution! The code looks good, but the commit message should explain a bit more.

In real operation, this can happen in an SSH client that has queued its own KEX_INIT already and then receives the peer's KEX_INIT and initializes its Kex object, which sends that first KEX message, all while its own KEX_INIT is still queued.

@abhiramaab
abhiramaab force-pushed the fix-ident-filter-kexinit-ordering branch from e5fd90f to 65a067a Compare November 10, 2026 01:19
@abhiramaab

Copy link
Copy Markdown
Author

Thanks @tomaswolf! I've updated the commit message to describe the real-world client KEX_INIT scenario and force-pushed the branch.

IdentFilter.WriteHandler.send() prematurely released its write queue guard
via lastWrite.compareAndSet(result, null) inside the queue.addListener
callback before calling owner().send(cmd, message).

In real operation, this can happen in an SSH client that has queued its own
KEX_INIT already and then receives the peer's KEX_INIT and initializes its
Kex object, which sends that first KEX message, all while its own KEX_INIT
is still queued. If lastWrite is prematurely reset, that subsequent KEX
message bypasses the queue and reaches the output sink before KEX_INIT,
violating SSH protocol packet ordering.

Move lastWrite.compareAndSet(result, null) after owner().send(...) to ensure
the write queue remains guarded until the message is handed off.
Add regression test in IdentFilterTest.
@tomaswolf
tomaswolf force-pushed the fix-ident-filter-kexinit-ordering branch from 65a067a to 645bfca Compare November 10, 2026 16:52
@tomaswolf
tomaswolf merged commit 645bfca into apache:dev_3.0 Nov 10, 2026
7 checks passed
@tomaswolf

Copy link
Copy Markdown
Member

I've updated the commit message

Thanks, perfect!

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