-
Notifications
You must be signed in to change notification settings - Fork 114
SSHD/Echoserver: Fix memory leaks and public-key lookup #1071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -95,6 +95,8 @@ | |||||||||||||||||||||||||||
| #if defined(WOLFSSHD_UNIT_TEST) && !defined(_WIN32) | ||||||||||||||||||||||||||||
| int (*wsshd_setregid_cb)(WGID_T, WGID_T) = setregid; | ||||||||||||||||||||||||||||
| int (*wsshd_setreuid_cb)(WUID_T, WUID_T) = setreuid; | ||||||||||||||||||||||||||||
| int (*wsshd_setegid_cb)(WGID_T) = setegid; | ||||||||||||||||||||||||||||
| int (*wsshd_seteuid_cb)(WUID_T) = seteuid; | ||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| struct WOLFSSHD_AUTH { | ||||||||||||||||||||||||||||
|
|
@@ -1841,7 +1843,7 @@ static int SetDefaultPublicKeyCheck(WOLFSSHD_AUTH* auth) | |||||||||||||||||||||||||||
| #define WOLFSSH_USER_GET_STRING(x) #x | ||||||||||||||||||||||||||||
| #define WOLFSSH_USER_STRING(x) WOLFSSH_USER_GET_STRING(x) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| static int SetDefualtUserID(WOLFSSHD_AUTH* auth) | ||||||||||||||||||||||||||||
| static int SetDefaultUserID(WOLFSSHD_AUTH* auth) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| #ifdef _WIN32 | ||||||||||||||||||||||||||||
| /* TODO: Implement for Windows. */ | ||||||||||||||||||||||||||||
|
|
@@ -1850,6 +1852,15 @@ static int SetDefualtUserID(WOLFSSHD_AUTH* auth) | |||||||||||||||||||||||||||
| struct passwd* pwInfo; | ||||||||||||||||||||||||||||
| int ret = WS_SUCCESS; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (wolfSSHD_ConfigGetPrivilegeSeparation(auth->conf) == | ||||||||||||||||||||||||||||
| WOLFSSHD_PRIV_OFF) { | ||||||||||||||||||||||||||||
| auth->gid = getgid(); | ||||||||||||||||||||||||||||
| auth->uid = getuid(); | ||||||||||||||||||||||||||||
| auth->sGid = auth->gid; | ||||||||||||||||||||||||||||
| auth->sUid = auth->uid; | ||||||||||||||||||||||||||||
| return WS_SUCCESS; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| pwInfo = getpwnam(WOLFSSH_USER_STRING(WOLFSSH_SSHD_USER)); | ||||||||||||||||||||||||||||
| if (pwInfo == NULL) { | ||||||||||||||||||||||||||||
| /* user name not found on system */ | ||||||||||||||||||||||||||||
|
|
@@ -1910,7 +1921,7 @@ WOLFSSHD_AUTH* wolfSSHD_AuthCreateUser(void* heap, const WOLFSSHD_CONFIG* conf) | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (ret == WS_SUCCESS) { | ||||||||||||||||||||||||||||
| ret = SetDefualtUserID(auth); | ||||||||||||||||||||||||||||
| ret = SetDefaultUserID(auth); | ||||||||||||||||||||||||||||
| if (ret != WS_SUCCESS) { | ||||||||||||||||||||||||||||
| wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Error setting default " | ||||||||||||||||||||||||||||
| "user ID."); | ||||||||||||||||||||||||||||
|
|
@@ -1942,24 +1953,37 @@ int wolfSSHD_AuthFreeUser(WOLFSSHD_AUTH* auth) | |||||||||||||||||||||||||||
| /* return WS_SUCCESS on success */ | ||||||||||||||||||||||||||||
| int wolfSSHD_AuthRaisePermissions(WOLFSSHD_AUTH* auth) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| int ret = 0; | ||||||||||||||||||||||||||||
| int ret = WS_SUCCESS; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| wolfSSH_Log(WS_LOG_INFO, "[SSHD] Attempting to raise permissions level"); | ||||||||||||||||||||||||||||
| #ifndef WIN32 | ||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 [Low] New bare scope block violates local C convention The PR adds a standalone scope block under Suggestion:
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed the styling. |
||||||||||||||||||||||||||||
| if (auth) { | ||||||||||||||||||||||||||||
| byte flag = 0; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (auth == NULL) { | ||||||||||||||||||||||||||||
| return WS_BAD_ARGUMENT; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| flag = wolfSSHD_ConfigGetPrivilegeSeparation(auth->conf); | ||||||||||||||||||||||||||||
| if (flag == WOLFSSHD_PRIV_SEPARAT || flag == WOLFSSHD_PRIV_SANDBOX) { | ||||||||||||||||||||||||||||
| wolfSSH_Log(WS_LOG_INFO, | ||||||||||||||||||||||||||||
| "[SSHD] Attempting to raise permissions level"); | ||||||||||||||||||||||||||||
| #ifdef WOLFSSHD_UNIT_TEST | ||||||||||||||||||||||||||||
| if (wsshd_setegid_cb(auth->sGid) != 0) { | ||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||
| if (setegid(auth->sGid) != 0) { | ||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||
| wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Error raising gid"); | ||||||||||||||||||||||||||||
| ret = WS_FATAL_ERROR; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (seteuid(auth->sUid) != 0) { | ||||||||||||||||||||||||||||
| #ifdef WOLFSSHD_UNIT_TEST | ||||||||||||||||||||||||||||
| if (ret == WS_SUCCESS && wsshd_seteuid_cb(auth->sUid) != 0) { | ||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||
| if (ret == WS_SUCCESS && seteuid(auth->sUid) != 0) { | ||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||
| wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Error raising uid"); | ||||||||||||||||||||||||||||
| ret = WS_FATAL_ERROR; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||
| ret = WS_BAD_ARGUMENT; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return ret; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 [Medium] Privilege-separation permission behavior lacks regression tests
💡 SUGGEST
testThe PR changes daemon privilege behavior by returning success from
SetDefaultUserIDwhenUsePrivilegeSeparation nois configured, and by makingwolfSSHD_AuthRaisePermissionsa no-op unless the config isWOLFSSHD_PRIV_SEPARATorWOLFSSHD_PRIV_SANDBOX. Grep found config parsing tests and reduce-permission tests, but no tests that exercisewolfSSHD_AuthRaisePermissionsor auth creation under the new privilege modes. This is a user-visible daemon startup/auth behavior change, so it should have regression coverage.Suggestion:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added unit coverage for the UsePrivilegeSeparation no case to ensure it returns success without requiring the configured sshd user. I also added tests verifying that wolfSSHD_AuthRaisePermissions only triggers the uid/gid restore path for the yes and sandbox modes as expected.