git: 06abe08de45d - main - pam_exec: fix the stderr close test and avoid a double close
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 20 Oct 2026 22:07:01 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=06abe08de45d251410949eac1bbb025367275260
commit 06abe08de45d251410949eac1bbb025367275260
Author: Osvaldo Janeri Filho <ojanerif@amd.com>
AuthorDate: 2026-10-20 22:04:17 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-10-20 22:05:31 +0000
pam_exec: fix the stderr close test and avoid a double close
The cleanup tested cherr[0] when closing cherr[1]. The parent also closed
chin[0]/chout[1]/cherr[1] after pdfork() without clearing them, so the out:
cleanup path closed them again. Clear each fd after closing and test the right
one.
Reviewed by: des, markj
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D60924
---
lib/libpam/modules/pam_exec/pam_exec.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/lib/libpam/modules/pam_exec/pam_exec.c b/lib/libpam/modules/pam_exec/pam_exec.c
index 800a791f04a1..4151163b7670 100644
--- a/lib/libpam/modules/pam_exec/pam_exec.c
+++ b/lib/libpam/modules/pam_exec/pam_exec.c
@@ -335,12 +335,18 @@ _pam_exec(pam_handle_t *pamh,
OUT(PAM_SYSTEM_ERR);
}
/* use poll() to watch the process and stdin / stdout / stderr */
- if (chin[0] >= 0)
+ if (chin[0] >= 0) {
close(chin[0]);
- if (chout[1] >= 0)
+ chin[0] = -1;
+ }
+ if (chout[1] >= 0) {
close(chout[1]);
- if (cherr[1] >= 0)
+ chout[1] = -1;
+ }
+ if (cherr[1] >= 0) {
close(cherr[1]);
+ cherr[1] = -1;
+ }
memset(pfd, 0, sizeof pfd);
pfd[0].fd = pd;
pfd[0].events = POLLHUP;
@@ -451,7 +457,7 @@ out:
close(chout[1]);
if (cherr[0] >= 0)
close(cherr[0]);
- if (cherr[0] >= 0)
+ if (cherr[1] >= 0)
close(cherr[1]);
if (envlist != NULL)
openpam_free_envlist(envlist);