Skip to content

Commit a96ef17

Browse files
committed
pam: do not return PAM_IGNORE on system errors
Instead, use more meaningful status codes: - PAM_SYSTEM_ERR if getpwuid_r(), gethostname(), or pam_modutil_{drop,regain}_priv() fails; - PAM_BUF_ERR if memory allocation routines fails; and - PAM_ABORT for any uncaught errors. This commit is part of a fix for YSA-2025-01 / CVE-2025-23013.
1 parent ba1fb88 commit a96ef17

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

pam-u2f.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
176176
cfg_t *cfg = &cfg_st;
177177
char buffer[BUFSIZE];
178178
int pgu_ret, gpn_ret;
179-
int retval = PAM_IGNORE;
179+
int retval = PAM_ABORT;
180180
device_t *devices = NULL;
181181
unsigned n_devices = 0;
182182
int openasuser = 0;
@@ -192,10 +192,10 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
192192
if (!cfg->origin) {
193193
if (!cfg->sshformat) {
194194
strcpy(buffer, DEFAULT_ORIGIN_PREFIX);
195-
196195
if (gethostname(buffer + strlen(DEFAULT_ORIGIN_PREFIX),
197196
BUFSIZE - strlen(DEFAULT_ORIGIN_PREFIX)) == -1) {
198197
debug_dbg(cfg, "Unable to get host name");
198+
retval = PAM_SYSTEM_ERR;
199199
goto done;
200200
}
201201
} else {
@@ -205,6 +205,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
205205
cfg->origin = strdup(buffer);
206206
if (!cfg->origin) {
207207
debug_dbg(cfg, "Unable to allocate memory");
208+
retval = PAM_BUF_ERR;
208209
goto done;
209210
} else {
210211
should_free_origin = 1;
@@ -217,6 +218,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
217218
cfg->appid = strdup(cfg->origin);
218219
if (!cfg->appid) {
219220
debug_dbg(cfg, "Unable to allocate memory");
221+
retval = PAM_BUF_ERR;
220222
goto done;
221223
} else {
222224
should_free_appid = 1;
@@ -236,7 +238,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
236238
devices = calloc(cfg->max_devs, sizeof(device_t));
237239
if (!devices) {
238240
debug_dbg(cfg, "Unable to allocate memory");
239-
retval = PAM_IGNORE;
241+
retval = PAM_BUF_ERR;
240242
goto done;
241243
}
242244

@@ -254,7 +256,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
254256
pw->pw_dir[0] != '/') {
255257
debug_dbg(cfg, "Unable to retrieve credentials for user %s, (%s)", user,
256258
strerror(errno));
257-
retval = PAM_USER_UNKNOWN;
259+
retval = PAM_SYSTEM_ERR;
258260
goto done;
259261
}
260262

@@ -265,7 +267,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
265267
if (cfg->expand && cfg->auth_file) {
266268
if ((cfg->auth_file = expand_variables(cfg->auth_file, user)) == NULL) {
267269
debug_dbg(cfg, "Failed to perform variable expansion");
268-
retval = PAM_AUTHINFO_UNAVAIL;
270+
retval = PAM_BUF_ERR;
269271
goto done;
270272
}
271273
should_free_auth_file = 1;
@@ -275,7 +277,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
275277
char *tmp = resolve_authfile_path(cfg, pw, &openasuser);
276278
if (tmp == NULL) {
277279
debug_dbg(cfg, "Could not resolve authfile path");
278-
retval = PAM_IGNORE;
280+
retval = PAM_BUF_ERR;
279281
goto done;
280282
}
281283
if (should_free_auth_file) {
@@ -294,7 +296,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
294296
debug_dbg(cfg, "Dropping privileges");
295297
if (pam_modutil_drop_priv(pamh, &privs, pw)) {
296298
debug_dbg(cfg, "Unable to switch user to uid %i", pw->pw_uid);
297-
retval = PAM_IGNORE;
299+
retval = PAM_SYSTEM_ERR;
298300
goto done;
299301
}
300302
debug_dbg(cfg, "Switched to uid %i", pw->pw_uid);
@@ -304,7 +306,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
304306
if (openasuser) {
305307
if (pam_modutil_regain_priv(pamh, &privs)) {
306308
debug_dbg(cfg, "could not restore privileges");
307-
retval = PAM_IGNORE;
309+
retval = PAM_SYSTEM_ERR;
308310
goto done;
309311
}
310312
debug_dbg(cfg, "Restored privileges");

0 commit comments

Comments
 (0)