fix state confusion between PAM and privsep code

Commits b9a6dd4d6 and df2b28163 introduced a potential desynchronisation
between the PAM code and the sshd-session monitor that could result in
authentication bypass if the unprivileged sshd-auth process had been
compromised.

Reported by Ben Edelman of NIST. Only git HEAD is affected, these
changes have not yet been included in an OpenSSH release.
This commit is contained in:
Damien Miller committed 2026-03-29 16:24:59 +11:00
1 parent 6eb5a68c42
commit bdaf65ae51
3 files changed
+10 -1

No files matched your search

+8
View File
@@ -1015,6 +1015,14 @@ sshpam_free_ctx(void *ctxtp)
*/
}
int
sshpam_priv_kbdint_authdone(void *ctxtp)
{
struct pam_ctxt *ctxt = ctxtp;
return ctxt->pam_done == SshPamAuthenticated;
}
KbdintDevice sshpam_device = {
"pam",
sshpam_init_ctx,
+1
View File
@@ -42,5 +42,6 @@ int sshpam_auth_passwd(Authctxt *, const char *);
int sshpam_get_maxtries_reached(void);
void sshpam_set_maxtries_reached(int);
int is_pam_session_open(void);
int sshpam_priv_kbdint_authdone(void *ctxtp);
#endif /* USE_PAM */
+1 -1
View File
@@ -1204,7 +1204,7 @@ mm_answer_pam_query(struct ssh *ssh, int sock, struct sshbuf *m)
fatal_f("no context");
ret = (sshpam_device.query)(sshpam_ctxt, &name, &info,
&num, &prompts, &echo_on);
if (ret == 0 && num == 0)
if (ret == 0 && num == 0 && sshpam_priv_kbdint_authdone(sshpam_ctxt))
sshpam_authok = sshpam_ctxt;
if (num > 1 || name == NULL || info == NULL)
fatal("sshpam_device.query failed");