wolfsshd: bound the shell child reap and flush the held backlog - #1276
Open
yosuke-wolfssl wants to merge 1 commit into
Open
yosuke-wolfssl wants to merge 1 commit into
yosuke-wolfssl wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Process descendants may survive cleanup, and the ESRCH race can leave children unreaped.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
This PR bounds wolfsshd shell cleanup after channel closure and preserves pending output.
Changes:
- Adds PTY closure, bounded reaping, and forced termination.
- Flushes held shell output before pipe draining.
- Adds Paramiko regression tests and CI dependencies.
| File | Description |
|---|---|
apps/wolfsshd/wolfsshd.c |
Implements bounded reaping and backlog flushing. |
apps/wolfsshd/test/sshd_channel_close_test.sh |
Tests channel-close cleanup and exit statuses. |
apps/wolfsshd/test/run_all_sshd_tests.sh |
Registers the new test. |
.github/workflows/sshd-test.yml |
Installs Paramiko for SSHD tests. |
.github/workflows/code-coverage.yml |
Installs Paramiko for coverage runs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1276
Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 1 of 1 in-scope changed file(s) opened by the reviewer
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
yosuke-wolfssl
force-pushed
the
fix/wolfsshd-loop
branch
2 times, most recently
from
September 28, 2026 06:05
988c09a to
720f7cd
Compare
- The pty master is closed before the reap. The reap polls waitpid() with WNOHANG for WOLFSSHD_CHILD_REAP_TRIES x WOLFSSHD_CHILD_REAP_WAIT_US, then sends SIGKILL; a failed kill() is logged and ends the wait. - ChildSig is installed before forkpty() instead of after it. - An EIO read from the pty master ends the child's output instead of the loop. - A held backlog is sent with SHELL_FlushOut() before the pipe drain; the drain is skipped when the backlog is not sent. - New sshd_channel_close_test.sh (paramiko) closes the channel while output is held, for an exec command and a pty shell, and checks that the command and the connection both end; it also checks exit status 3 from an exec and an interactive shell. run_all runs it; sshd-test.yml and code-coverage.yml install python3-paramiko.
yosuke-wolfssl
force-pushed
the
fix/wolfsshd-loop
branch
from
September 28, 2026 06:44
720f7cd to
1e30e73
Compare
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.

Problem
Follow-up to #1217. Bugs on the path from a
breakin POSIXSHELL_Subsystem()to its end:waitpid(). When a client closes its channel while wolfsshd holds output, the loop sendsSIGINTand breaks. A command that ignores SIGINT, including any interactive shell on a pty, keeps the connection process, its socket and the child alive until the client drops the whole transport. Reproduced with paramiko (exec_commandorinvoke_shell, stop reading,channel.close()): the command is still running after 10 s.breakcan leave unsent output inshellBuffer, and the post-loop pipe drain thenread()s over it. Reached when the command exits while stdin is still arriving: the pending stdin write fails with EPIPE and the loop breaks with output held.ChildSigwas installed afterforkpty(). A shell that exited in between was reaped silently,ChildRunningnever cleared, and the loop waited until the client disconnected.Fix (
apps/wolfsshd/wolfsshd.c)waitpid(WNOHANG)forWOLFSSHD_CHILD_REAP_TRIESxWOLFSSHD_CHILD_REAP_WAIT_US(0.5 s by default), thenSIGKILLand a blocking wait. A normal exit is reaped on the first poll. A failedkill()is logged and ends the wait.exec nohup job </dev/null >/dev/null 2>&1in an interactive shell); the loop now waits for it, as a 0-byte read already did.ChildSiginstalled beforeforkpty(), so a shell that exits at once still clearsChildRunning.SHELL_FlushOut(). ASHELL_SEND_NEVERbacklog is dropped, and the drain is skipped whenever the backlog is not sent, so the stream never has a gap.Tests
New
apps/wolfsshd/test/sshd_channel_close_test.sh, using paramiko (the OpenSSH client never closes a channel early):INTandHUP, channel closed while output is heldEXIT-trap marker SIGKILL cannot write) and the connection closes within 5 sexit 3from an exec and from an interactive shellIt skips (77) without python3 or paramiko, on a non-loopback host, or when paramiko cannot connect.
sshd-test.ymlandcode-coverage.ymlinstallpython3-paramikofrom apt, because the suite runs as root and cannot see a per-user pip install.Verification
sshd-test.yml's configure lines, suite run withsudoas a sudoer: 31 passed, 3 skipped (the kex debug test, the UPN negative on FPKI builds, ML-DSA);make check13/13.ChildSigchanges touch no buffers). gcc-13-Werroracross 6 configs: clean.Not in this PR
exit-status 0(WEXITSTATUSwithoutWIFEXITED). Fixing that changes what goes on the wire, so it is separate.