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
- The pty master is closed before the reap, so the shell gets SIGHUP and can exit on its own. - The post-loop reap polls waitpid() with WNOHANG for WOLFSSHD_CHILD_REAP_TRIES x WOLFSSHD_CHILD_REAP_WAIT_US, then sends SIGKILL and waits. A failed kill() is logged with its errno and ends the wait. - Output held in the shell backlog when the loop breaks is sent with SHELL_FlushOut() before the pipe drain reads into shellBuffer. A SHELL_SEND_NEVER backlog is dropped unsent, and the drain is skipped when the backlog is dropped or its send fails. - sshd_channel_close_test.sh closes a session channel with paramiko while wolfsshd holds output, for an exec command that traps SIGINT and SIGHUP and for an interactive shell on a pty, and checks each command is gone within 5s and that the shell left through its HUP/EXIT trap rather than SIGKILL. It also checks that an exit status of 3 reaches the client with and without a pty. It exits 77 when python3 or paramiko is missing, the host is not a loopback address, or paramiko cannot connect. - run_all_sshd_tests.sh runs it after sshd_stdin_stall_test.sh. - sshd-test.yml and code-coverage.yml install python3-paramiko before the wolfSSHd tests.
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
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. Two 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.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.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. The channel close drops its backlog; the flush covers theselect()and child-stdin write breaks.Tests
New
apps/wolfsshd/test/sshd_channel_close_test.sh, using paramiko (the OpenSSH client never closes a channel early):INTandHUPHUP/EXITtrap rather than SIGKILLexit 3, with and without a ptyIt 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.-Werroracross 6 configs: clean.Not in this PR
exit-status 0(WEXITSTATUSwithoutWIFEXITED). Fixing that changes what goes on the wire, so it is separate.