wolfsshd: complete the Windows user profile fallback - #1243
wolfsshd: complete the Windows user profile fallback#1243yosuke-wolfssl wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The changes directly address the documented Windows failure mode, add proper resource cleanup, and include targeted CI coverage for the previously untested no-profile scenario.
Pull request overview
This PR fixes wolfsshd’s Windows home-directory fallback so that accounts without a pre-existing local profile can successfully log in and get a correct per-user home directory (instead of the service account’s), while also ensuring the temporary profile hive is unloaded at session teardown.
Changes:
- Fix
_GetHomeDirectory()fallback by correctly initializingPROFILEINFO.dwSize, loading the user profile at most once per session, and usingGetUserProfileDirectoryW()(token-based) instead of%USERPROFILE%. - Track the loaded user profile hive in
WOLFSSHD_AUTH.profileand unload it inwolfSSHD_AuthCloseToken(). - Add a new Windows CI “no_profile” job that validates profile creation, correct landing directory, and hive unload after disconnect.
File summaries
| File | Description |
|---|---|
| apps/wolfsshd/wolfsshd.c | Reorders RevertToSelf() ahead of token/profile teardown so profile unloading has required service privileges. |
| apps/wolfsshd/auth.c | Fixes Windows profile-loading fallback and adds per-session profile hive tracking + unloading on token close. |
| .github/workflows/windows-sftp.yml | Adds a matrix job covering a user with no pre-existing Windows profile and asserts creation + cleanup behavior. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
31504d4 to
3301e3b
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1243
Scan targets checked: wolfssh-bugs, wolfssh-src
Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
- _GetHomeDirectoryEx sets PROFILEINFO.dwSize, loads the profile only on its loadProfile argument, and reads the home directory with GetUserProfileDirectoryW instead of expanding %USERPROFILE%. - _GetHomeDirectory and _GetHomeDirectoryPreAuth wrap it with that argument set and clear; CheckPublicKeyWIN takes the pre-auth one. - WOLFSSHD_AUTH holds the loaded hive; wolfSSHD_AuthCloseToken unloads it before closing the token, calling RegCloseKey when the unload fails. - The Windows shell cleanup calls RevertToSelf() before closing the auth token rather than after. - windows-sftp.yml gains a no_profile job: testuser is created with net user alone, and an exec session builds the profile, runs as testuser, and releases the hive. Issue: F-13326
3301e3b to
38ecc08
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1243
Scan targets checked: wolfssh-bugs, wolfssh-src
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Fenrir's latest completed scan found no issues; clearing the prior automated change request.
Problem
_GetHomeDirectory()on wolfsshd's Windows path zero-initializesPROFILEINFObut never setsdwSize, whichLoadUserProfileW()rejects withERROR_INVALID_PARAMETER. That fallback runs wheneverSHGetKnownFolderPath(FOLDERID_Profile)cannot resolve the user — the case for any account with no profile on the host, since the network logon wolfsshd performs does not create one. Every consumer of the home directory then fails and the login is refused:CheckPublicKeyWIN()authorized_keysSFTP_Subsystem()SHELL_Subsystem()Both Windows CI workflows already work around this by hand-writing a
ProfileList\<SID>\ProfileImagePathentry so the fallback is never taken.Two further defects on the same path:
ExpandEnvironmentStringsW(L"%USERPROFILE%"), which expands against the service account's environment. WithdwSizefixed the fallback would start succeeding and handC:\Windows\system32\config\systemprofileback as every user's home, including toSearchForPubKey().@TODOasking whether it should be.Fix (
apps/wolfsshd/auth.c)dwSizeis set beforeLoadUserProfileW(), and the load is guarded onauth->profile == NULLso a second call cannot orphan the first hive handle.GetUserProfileDirectoryW()on the auth token replaces the%USERPROFILE%expansion.WOLFSSHD_AUTH.profileholds the hive for the connection;wolfSSHD_AuthCloseToken()unloads it before closing the token.RevertToSelf()moves ahead of the token close inSHELL_Subsystem()'s cleanup (wolfsshd.c) —UnloadUserProfile()needs the service account'sSE_RESTORE_NAME/SE_BACKUP_NAME, which the impersonated user's token lacks.Closes f-13326, and covers the wrong-home-directory and hive-leak defects on the same path, which were not separately filed.
Tests (
.github/workflows/windows-sftp.yml)New
no_profilematrix job createstestuserwithnet user /addalone — no home directory, no ACL grant, noProfileListentry — then runs the SFTPpwd/lsflow and an exec session viaclient.exe -c. It asserts the session lands intestuser's own profile rather thansystemprofile, thatNTUSER.DATwas created, and that the hive leavesHKEY_USERSafter disconnect. The exec session is what reachesSHELL_Subsystem()'s cleanup: without theRevertToSelf()move the unload fails withERROR_ACCESS_DENIEDand the job fails on the hive still being loaded.Verification
wolfsshd.exeand the full solution build clean, no warnings on the changed files;unit-testandapi-testpass.