fix: SHELL_Subsystem returns without restoring raised privileges#1126
Open
MarkAtwood wants to merge 1 commit into
Open
fix: SHELL_Subsystem returns without restoring raised privileges#1126MarkAtwood wants to merge 1 commit into
MarkAtwood wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a privilege-separation correctness issue in SHELL_Subsystem() (wolfsshd) where several early error returns could leave the per-connection handler running with temporarily raised privileges.
Changes:
- Drop raised privileges via
wolfSSHD_AuthReducePermissions(conn->auth)before returning onpipe()failures (stdout/stderr/stdin). - Drop raised privileges via
wolfSSHD_AuthReducePermissions(conn->auth)before returning onforkpty()failure.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
1423
to
+1427
| wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Issue creating new forkpty"); | ||
| if (wolfSSHD_AuthReducePermissions(conn->auth) != WS_SUCCESS) { | ||
| wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Error dropping permissions"); | ||
| exit(1); | ||
| } |
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.
Bug
SHELL_Subsystem()(apps/wolfsshd/wolfsshd.c) temporarily raises privileges viawolfSSHD_AuthRaisePermissions(conn->auth)to look up user information. Fourerror paths between that raise and the normal privilege drops return
WS_FATAL_ERRORwithout restoring privileges:pipe(stdoutPipe)failurepipe(stderrPipe)failurepipe(stdinPipe)failureforkpty()failureThe caller discards the return value, so the per-connection handler proceeds
through teardown still elevated. This only has effect when
UsePrivilegeSeparationisyes/sandbox(otherwise the raise is a no-op), andreaching it requires fd/process exhaustion, so severity is low — but the raise
should always be paired with a drop.
Fix
Restore privileges with
wolfSSHD_AuthReducePermissions(conn->auth)before eachof the four early returns, matching the existing
exit(1)-on-drop-failurehandling used on the normal child/parent paths.
Verification
Built
--enable-all(incl. wolfsshd) against wolfSSL master; compiles clean.Reported by static analysis (Fenrir finding F-6980).