wolfsshd: reject Match blocks using unimplemented selectors#1026
wolfsshd: reject Match blocks using unimplemented selectors#1026yosuke-wolfssl wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens wolfsshd configuration parsing by preventing Match blocks that can never be applied (because they use only unimplemented selectors) from being accepted silently, avoiding a fail-open misconfiguration scenario.
Changes:
- Reject
Matchdirectives that resolve neitherUsernorGroup, logging an explicit error and returningWS_FATAL_ERROR. - Free the newly-copied (but unlinked) config node on the
Matchfailure path to avoid leaks. - Add a unit test covering accepted (
User/Group) and rejected (unsupported / no-selector)Matchforms.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/wolfsshd/configuration.c | Adds rejection + cleanup for Match directives that contain no supported selector (User/Group). |
| apps/wolfsshd/test/test_configuration.c | Adds unit coverage to ensure unsupported/no-selector Match directives are rejected. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7c6c3f7 to
5394c6b
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1026
Scan targets checked: none
Failed targets: wolfssh-bugs, wolfssh-src
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1026
Scan targets checked: none
Failed targets: wolfssh-bugs, wolfssh-src
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1026
Scan targets checked: wolfssh-bugs, wolfssh-src
No new issues found in the changed files. ✅
Summary
wolfsshdsilently ignoredMatchblocks keyed on any selector other thanUser/Group.When
HandleMatchparsed aMatchdirective it only calledAddRestrictedCasefor theUserandGroupselectors. A block keyed onAddress,Host,LocalAddress,LocalPort, orRDomainleft bothusrAppliesToandgroupAppliesToNULL, yetParseConfigLinestill returnedWS_SUCCESS. BecausewolfSSHD_GetUserConfonly matches a node when one of those pointers is non-NULL, the block was unreachable and the global config was used instead.This is a fail-open misconfiguration: an administrator who tightens authentication for external networks with, e.g.,
Match Address 10.0.0.0/8gets no error or warning, but the rules never apply.Fix
Reject
Matchblocks that contain no supported selector instead of accepting them silently.In
HandleMatch, after attempting to parseUser/Group, if both selectors are unresolved the directive is rejected withWS_FATAL_ERRORand a clear log message:The guard fires only when neither selector resolved, so all supported forms still work:
Match User <name>(User-only)Match Group <name>(Group-only)Match User <name> Group <name>(both)The orphaned copied config node (never linked into the list on the error path) is freed; this is leak- and double-free-safe since
wolfSSHD_ConfigCopyzero-initializes the node and does not copynext.Testing
Added
test_MatchUnsupportedSelectorinapps/wolfsshd/test/test_configuration.cwith 9 vectors:Match User,Match GroupMatch Address,Match Host,Match LocalAddress,Match LocalPort,Match RDomainMatch all, bareMatchAll scenarios pass. Built and ran the suite under ASan + UBSan with no sanitizer reports.
Files changed
apps/wolfsshd/configuration.c— rejectMatchblocks with no supported selector; free orphaned node on error pathapps/wolfsshd/test/test_configuration.c— addtest_MatchUnsupportedSelector