Skip to content

echoserver: check scp exec, drop root for shell - #1378

Merged
philljj merged 3 commits into
wolfSSL:masterfrom
ejohnstown:echoserver-session
Nov 18, 2026
Merged

philljj merged 3 commits into
wolfSSL:masterfrom
ejohnstown:echoserver-session

Conversation

@ejohnstown

@ejohnstown ejohnstown commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

The echoserver takes an exec request as an SCP transfer only when
wolfSSH_ChannelCommandIsScp() does. A root-started server runs the
shell as the logged-in user; SCP and SFTP still run as the server.

  • api: a "scpbackup" exec is served as a session
  • the shell child hands the user its pty, sets groups, gid and uid,
    and exits if any step fails
  • the shell child closes every descriptor above stderr before exec
  • scp: the send callback comments allow one 0 return in a row at any
    point while file data remains, not only on the metadata call

Issue: F-14206, F-8857, F-13331

Copilot AI balanced review requested due to automatic review settings November 3, 2026 16:47

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.

🟡 Changes recommended

The regression test bypasses shell startup with -f, leaving shell credentials, PTY ownership and access, and prevention of execv() after setup failures unverified.

1 open issue
What changed in this PR

This PR aligns the echoserver’s SCP handling with wolfSSH’s command classifier and makes root-started shells run as the authenticated user.

Changes:

  • Use wolfSSH_ChannelCommandIsScp() to distinguish SCP transfers from other exec requests.
  • Set terminal ownership and user credentials before starting the shell, exiting on setup failure.
  • Add a regression test confirming that scpbackup is served as an echo session.
File Description
tests/​api.c Adds and registers the scpbackup exec regression test.
examples/​echoserver/​echoserver.c Corrects SCP classification and drops shell-child privileges.

Review effort: Balanced

Comment thread examples/echoserver/echoserver.c Resolved
@ejohnstown

Copy link
Copy Markdown
Contributor Author

@claude review

@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 #1378

Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 2 of 2 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

@claude claude 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.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment thread examples/echoserver/echoserver.c Resolved
wsExecStartCb() now takes an exec request as a transfer only when
wolfSSH_ChannelCommandIsScp() does, the same test wolfSSH_accept()
diverts on. A command such as "scpbackup" is served as a session.

- tests: test_wolfSSH_SCP_ExecNotScp echoes data over a "scpbackup"
  exec channel

Issue: F-14206
When the echoserver runs as root, the forkpty child hands the pty
slave to the authenticated user, mode 0620, so the shell can reopen
its terminal, then takes that user's groups, gid and uid and closes
every descriptor above stderr before it execs the shell. It exits
without a shell if any step fails or root can be regained.

- configure: check for closefrom(), with a close() loop as fallback
- a server that is not root starts the shell as before

Issue: F-8857
A send callback may return 0 once in a row at any point while file
data remains, not only on the metadata call; a return that sends data
resets the stall detector. The WS_CallbackScpSend doc and the comment
at the stall check in DoScpSource now say so.

Issue: F-13331
@philljj

philljj commented Nov 18, 2026

Copy link
Copy Markdown

@wolfSSL-Fenrir-bot review max

@philljj philljj self-assigned this Nov 18, 2026

@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 #1378

Scan targets checked: wolfssh-src, wolfssh-bugs
Not reviewed (no scan target covers them): configure.ac
Coverage: 4 of 4 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: Max

@philljj
philljj merged commit b0d0f00 into wolfSSL:master Nov 18, 2026
222 checks passed
@ejohnstown
ejohnstown deleted the echoserver-session branch November 19, 2026 15:56
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.

5 participants