[openssh-commits] [openssh] branch master updated: revise how PAM is invoked in the monitor process
git+noreply at mindrot.org
git+noreply at mindrot.org
Wed Nov 25 19:52:41 AEDT 2026
This is an automated email from the git hooks/post-receive script.
djm pushed a commit to branch master
in repository openssh.
The following commit(s) were added to refs/heads/master by this push:
new 061bf4abe revise how PAM is invoked in the monitor process
061bf4abe is described below
commit 061bf4abe98b2f05e0dcb1eda4760eebfa0b1abf
Author: Damien Miller <djm at mindrot.org>
AuthorDate: Wed Nov 25 00:49:51 2026 -0800
revise how PAM is invoked in the monitor process
Remove the separate mm_start_pam() monitor call and start PAM
unconditionally at the start of authentication.
Synchronously expect the mm_do_pam_account() monitor call whenever
an authentication call completes successfully.
Explicitly force pam_acct_mgmt() to use the store_conv conversation
function.
Based on patch from Marco Trevisan; feedback/ok dtucker
---
auth-pam.c | 5 +++
auth2.c | 4 ---
monitor.c | 109 +++++++++++++++++++++++++++++----------------------------
monitor.h | 1 -
monitor_wrap.c | 15 --------
monitor_wrap.h | 1 -
6 files changed, 60 insertions(+), 75 deletions(-)
diff --git a/auth-pam.c b/auth-pam.c
index 29607e041..d2f6d59bc 100644
--- a/auth-pam.c
+++ b/auth-pam.c
@@ -1071,6 +1071,11 @@ do_pam_account(void)
expose_authinfo(__func__);
+ sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
+ (const void *)&store_conv);
+ if (sshpam_err != PAM_SUCCESS)
+ fatal_f("failed to set PAM_CONV: %s",
+ pam_strerror(sshpam_handle, sshpam_err));
sshpam_err = pam_acct_mgmt(sshpam_handle, 0);
debug3("PAM: %s pam_acct_mgmt = %d (%s)", __func__, sshpam_err,
pam_strerror(sshpam_handle, sshpam_err));
diff --git a/auth2.c b/auth2.c
index db9e6695f..e1d8af7c6 100644
--- a/auth2.c
+++ b/auth2.c
@@ -315,10 +315,6 @@ input_userauth_request(int type, uint32_t seq, struct ssh *ssh)
mm_audit_event(ssh, SSH_INVALID_USER);
#endif
}
-#ifdef USE_PAM
- if (options.use_pam)
- mm_start_pam(ssh);
-#endif
ssh_packet_set_log_preamble(ssh, "%suser %s",
authctxt->valid ? "authenticating " : "invalid ", user);
setproctitle("%s [net]", authctxt->valid ? user : "unknown");
diff --git a/monitor.c b/monitor.c
index ebcd9c8c8..17159272b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -122,8 +122,6 @@ int mm_answer_term(struct ssh *, int, struct sshbuf *);
int mm_answer_state(struct ssh *, int, struct sshbuf *);
#ifdef USE_PAM
-int mm_answer_pam_start(struct ssh *, int, struct sshbuf *);
-int mm_answer_pam_account(struct ssh *, int, struct sshbuf *);
int mm_answer_pam_init_ctx(struct ssh *, int, struct sshbuf *);
int mm_answer_pam_query(struct ssh *, int, struct sshbuf *);
int mm_answer_pam_respond(struct ssh *, int, struct sshbuf *);
@@ -191,8 +189,6 @@ struct mon_table mon_dispatch_proto20[] = {
{MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner},
{MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
#ifdef USE_PAM
- {MONITOR_REQ_PAM_START, MON_ONCE, mm_answer_pam_start},
- {MONITOR_REQ_PAM_ACCOUNT, 0, mm_answer_pam_account},
{MONITOR_REQ_PAM_INIT_CTX, MON_ONCE, mm_answer_pam_init_ctx},
{MONITOR_REQ_PAM_QUERY, 0, mm_answer_pam_query},
{MONITOR_REQ_PAM_RESPOND, MON_ONCE, mm_answer_pam_respond},
@@ -262,11 +258,38 @@ monitor_permit_authentications(int permit)
}
}
+#ifdef USE_PAM
+static int
+monitor_pam_account(struct ssh *ssh, struct monitor *pmonitor)
+{
+ struct sshbuf *m;
+ u_int ret;
+ int r;
+
+ if (!options.use_pam)
+ fatal_f("PAM not enabled");
+ if ((m = sshbuf_new()) == NULL)
+ fatal_f("sshbuf_new failed");
+ mm_request_receive_expect(pmonitor->m_sendfd,
+ MONITOR_REQ_PAM_ACCOUNT, m);
+ if ((ret = do_pam_account()) > INT_MAX)
+ fatal_f("do_pam_account bad return %u", ret);
+ if ((r = sshbuf_put_u32(m, ret)) != 0 ||
+ (r = sshbuf_put_stringb(m, loginmsg)) != 0)
+ fatal_fr(r, "buffer error");
+ sshbuf_reset(loginmsg);
+
+ mm_request_send(pmonitor->m_sendfd, MONITOR_ANS_PAM_ACCOUNT, m);
+ sshbuf_free(m);
+ return (int)ret;
+}
+#endif
+
void
monitor_child_preauth(struct ssh *ssh, struct monitor *pmonitor)
{
struct mon_table *ent;
- int status, authenticated = 0, partial = 0;
+ int status, pam_account_failed = 0, authenticated = 0, partial = 0;
debug3("preauth child monitor started");
@@ -315,6 +338,10 @@ monitor_child_preauth(struct ssh *ssh, struct monitor *pmonitor)
}
if (authenticated) {
+ if (pam_account_failed) {
+ fatal_f("authentication success after "
+ "PAM account failure");
+ }
if (!(ent->flags & MON_AUTHDECIDE))
fatal_f("unexpected authentication from %d",
ent->type);
@@ -322,18 +349,23 @@ monitor_child_preauth(struct ssh *ssh, struct monitor *pmonitor)
!auth_root_allowed(ssh, auth_method))
authenticated = 0;
#ifdef USE_PAM
- /* PAM needs to perform account checks after auth */
- if (options.use_pam && authenticated) {
- struct sshbuf *m;
-
- if ((m = sshbuf_new()) == NULL)
- fatal("%s: sshbuf_new failed",
- __func__);
- mm_request_receive_expect(pmonitor->m_sendfd,
- MONITOR_REQ_PAM_ACCOUNT, m);
- authenticated = mm_answer_pam_account(
- ssh, pmonitor->m_sendfd, m);
- sshbuf_free(m);
+ /*
+ * If PAM is enabled and authentication was successful,
+ * then the unpriv process is next expected to make a
+ * MONITOR_REQ_PAM_ACCOUNT request. This can cancel
+ * the successful authentication and return a reason
+ * to the client.
+ */
+ if (options.use_pam && authenticated &&
+ !monitor_pam_account(ssh, pmonitor)) {
+ pam_account_failed = 1;
+ authenticated = 0;
+ /*
+ * If the account check failed then the unpriv
+ * process is expected to fatal() immediately
+ * It will be prevented from circumventing
+ * this by the pam_account_failed check above.
+ */
}
#endif
}
@@ -874,6 +906,11 @@ mm_answer_pwnamallow(struct ssh *ssh, int sock, struct sshbuf *m)
goto out;
}
+#ifdef USE_PAM
+ if (options.use_pam)
+ start_pam(ssh);
+#endif
+
allowed = 1;
authctxt->pw = pwent;
authctxt->valid = 1;
@@ -936,7 +973,7 @@ mm_answer_pwnamallow(struct ssh *ssh, int sock, struct sshbuf *m)
#ifdef USE_PAM
if (options.use_pam)
- monitor_permit(mon_dispatch, MONITOR_REQ_PAM_START, 1);
+ monitor_permit(mon_dispatch, MONITOR_REQ_PAM_INIT_CTX, 1);
#endif
return (0);
@@ -1139,42 +1176,6 @@ mm_answer_bsdauthrespond(struct ssh *ssh, int sock, struct sshbuf *m)
#endif
#ifdef USE_PAM
-int
-mm_answer_pam_start(struct ssh *ssh, int sock, struct sshbuf *m)
-{
- if (!options.use_pam)
- fatal_f("UsePAM not set, but ended up in %s anyway", __func__);
-
- start_pam(ssh);
-
- monitor_permit(mon_dispatch, MONITOR_REQ_PAM_ACCOUNT, 1);
- if (options.kbd_interactive_authentication)
- monitor_permit(mon_dispatch, MONITOR_REQ_PAM_INIT_CTX, 1);
-
- return (0);
-}
-
-int
-mm_answer_pam_account(struct ssh *ssh, int sock, struct sshbuf *m)
-{
- u_int ret;
- int r;
-
- if (!options.use_pam)
- fatal_f("PAM not enabled");
-
- ret = do_pam_account();
-
- if ((r = sshbuf_put_u32(m, ret)) != 0 ||
- (r = sshbuf_put_stringb(m, loginmsg)) != 0)
- fatal_fr(r, "buffer error");
- sshbuf_reset(loginmsg);
-
- mm_request_send(sock, MONITOR_ANS_PAM_ACCOUNT, m);
-
- return (ret);
-}
-
static void *sshpam_ctxt, *sshpam_authok;
extern KbdintDevice sshpam_device;
diff --git a/monitor.h b/monitor.h
index fe0b00b2e..d5a1c5d24 100644
--- a/monitor.h
+++ b/monitor.h
@@ -57,7 +57,6 @@ enum monitor_reqtype {
MONITOR_REQ_TERM = 50,
MONITOR_REQ_STATE = 51, MONITOR_ANS_STATE = 52,
- MONITOR_REQ_PAM_START = 100,
MONITOR_REQ_PAM_ACCOUNT = 102, MONITOR_ANS_PAM_ACCOUNT = 103,
MONITOR_REQ_PAM_INIT_CTX = 104, MONITOR_ANS_PAM_INIT_CTX = 105,
MONITOR_REQ_PAM_QUERY = 106, MONITOR_ANS_PAM_QUERY = 107,
diff --git a/monitor_wrap.c b/monitor_wrap.c
index 457a6196f..3df3121ed 100644
--- a/monitor_wrap.c
+++ b/monitor_wrap.c
@@ -704,21 +704,6 @@ mm_session_pty_cleanup2(Session *s)
}
#ifdef USE_PAM
-void
-mm_start_pam(struct ssh *ssh)
-{
- struct sshbuf *m;
-
- debug3_f("entering");
- if (!options.use_pam)
- fatal_f("UsePAM=no, but ended up in %s anyway", __func__);
- if ((m = sshbuf_new()) == NULL)
- fatal_f("sshbuf_new failed");
- mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_START, m);
-
- sshbuf_free(m);
-}
-
u_int
mm_do_pam_account(void)
{
diff --git a/monitor_wrap.h b/monitor_wrap.h
index f43759b21..ae2b05ab8 100644
--- a/monitor_wrap.h
+++ b/monitor_wrap.h
@@ -74,7 +74,6 @@ OM_uint32 mm_ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
#endif
#ifdef USE_PAM
-void mm_start_pam(struct ssh *ssh);
u_int mm_do_pam_account(void);
void *mm_sshpam_init_ctx(struct Authctxt *);
int mm_sshpam_query(void *, char **, char **, u_int *, char ***, u_int **);
--
To stop receiving notification emails like this one, please contact
djm at mindrot.org.
More information about the openssh-commits
mailing list