Skip to content

Treat combined Match User/Group blocks as a conjunction in wolfsshd#1027

Open
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_5692
Open

Treat combined Match User/Group blocks as a conjunction in wolfsshd#1027
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_5692

Conversation

@yosuke-wolfssl

Copy link
Copy Markdown
Contributor

Summary

wolfSSHD_GetUserConf evaluated a combined Match User X Group Y config block with OR semantics instead of AND. OpenSSH treats a Match line as a conjunction, but the lookup loop broke out on a username match or a group match independently. Since a combined Match User X Group Y line sets both usrAppliesTo and groupAppliesTo on the same config node, the block was returned for:

  • any user named alice regardless of group, and
  • any user whose primary group is admins regardless of name.

When such a block relaxes a global ForceCommand (e.g. from internal-sftp to a full shell) or changes ChrootDir, an authenticated user satisfying only one of the two selectors inherited the permissive policy and could escape SFTP-only confinement.

Fix

Each config node is now evaluated as a conjunction of its set selectors: a node applies only when every non-NULL selector on it matches; a NULL selector acts as a wildcard.

Node has Match condition
user only user matches
group only group matches
user + group user matches AND group matches
neither wildcard (global/head default)

This preserves the legitimate, common single-selector blocks (Match User alice, Match Group admins) while closing the combined-block bypass. When no node matches, it still falls back to the global head config. The NULL-group path (WIN32, or failed group resolution in wolfSSHD_AuthGetUserConf) now fails closed against a combined node rather than treating NULL as a wildcard.

Changes

  • apps/wolfsshd/configuration.c — rewrote the matching loop in wolfSSHD_GetUserConf to use per-node conjunction semantics.
  • apps/wolfsshd/test/test_configuration.c — added test_GetUserConfMatchGroupAnd covering combined and single-selector blocks with users satisfying zero, one, and both selectors, plus the NULL-group fail-closed case.

Testing

  • New test test_GetUserConfMatchGroupAnd and existing test_GetUserConfMatchOverride pass.
  • Negative control: with the fix reverted, the new test fails (ret=-1001), confirming it actually catches the OR bug.
  • Sanitizers: built and ran the config test under -fsanitize=address,undefined -fno-omit-frame-pointer — clean, no ASan/UBSan reports.

@yosuke-wolfssl yosuke-wolfssl self-assigned this Jun 15, 2026
Copilot AI review requested due to automatic review settings June 15, 2026 04:26

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.

Pull request overview

This PR fixes wolfSSHD_GetUserConf so that a combined Match User X Group Y block is evaluated with AND (conjunction) semantics rather than the previous OR behavior, aligning wolfSSHD config resolution with OpenSSH and preventing unintended application of more-permissive policies.

Changes:

  • Reworked the wolfSSHD_GetUserConf matching loop to require all non-NULL selectors present on a node (currently User and Group) to match before selecting that node.
  • Added a new unit test covering combined Match User + Group, single-selector behavior, and the NULL-group fail-closed case.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
apps/wolfsshd/configuration.c Updates user/group match resolution to conjunction semantics and prevents combined-selector bypass.
apps/wolfsshd/test/test_configuration.c Adds regression coverage for combined vs single-selector Match blocks and NULL-group behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Scan targets checked: none
Failed targets: wolfssh-bugs, wolfssh-src

⚠️ Review incomplete — one or more scan targets failed before findings could be produced. See the Fenrir PR review detail page for logs.

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

Scan targets checked: none
Failed targets: wolfssh-bugs, wolfssh-src

⚠️ Review incomplete — one or more scan targets failed before findings could be produced. See the Fenrir PR review detail page for logs.

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

Scan targets checked: wolfssh-bugs, wolfssh-src

No new issues found in the changed files. ✅

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.

4 participants