Skip to content

Commit a68e821

Browse files
3v1n0millert
authored andcommitted
plugins/pam: Check the user didn't change during PAM transaction
PAM modules can change the user during their execution, in such case, sudo would still use the user that has been provided giving potentially access to another user with the credentials of another one. So prevent this to happen, by ensuring that the final PAM user is matching the one which started the transaction
1 parent 05b5de5 commit a68e821

File tree

1 file changed

+13
-0
lines changed
  • plugins/sudoers/auth

1 file changed

+13
-0
lines changed

plugins/sudoers/auth/pam.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,19 @@ sudo_pam_verify(const struct sudoers_context *ctx, struct passwd *pw,
330330
debug_return_int(AUTH_FAILURE);
331331
}
332332

333+
if (*pam_status == PAM_SUCCESS) {
334+
const char *pam_user = NULL;
335+
336+
*pam_status = pam_get_item(pamh, PAM_USER, (const void **) &pam_user);
337+
if (*pam_status == PAM_SUCCESS &&
338+
(pam_user == NULL || strcmp(pam_user, pw->pw_name) != 0)) {
339+
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO,
340+
"unable to authenticate '%s' as user '%s'",
341+
pw->pw_name, pam_user);
342+
debug_return_int(AUTH_FAILURE);
343+
}
344+
}
345+
333346
if (getpass_error) {
334347
/* error or ^C from tgetpass() or running non-interactive */
335348
debug_return_int(noninteractive ? AUTH_NONINTERACTIVE : AUTH_INTR);

0 commit comments

Comments
 (0)