Blame SOURCES/pam-1.3.1-pam-modutil-close-write.patch

3bbffd
From b6f73810a2e7afd02a231e2dfa14b05752c83db7 Mon Sep 17 00:00:00 2001
3bbffd
From: "Dmitry V. Levin" <ldv@altlinux.org>
3bbffd
Date: Wed, 26 Feb 2020 19:20:58 +0000
3bbffd
Subject: [PATCH] pam_modutil_sanitize_helper_fds: fix SIGPIPE effect of
3bbffd
 PAM_MODUTIL_PIPE_FD
3bbffd
3bbffd
When pam_modutil_sanitize_helper_fds() is invoked with
3bbffd
PAM_MODUTIL_PIPE_FD to provide a dummy pipe descriptor for stdout
3bbffd
or stderr, it closes the read end of the newly created dummy pipe.
3bbffd
The negative side effect of this approach is that any write to such
3bbffd
descriptor triggers a SIGPIPE.  Avoid this by closing the write end of
3bbffd
the dummy pipe and using its read end as a dummy pipe descriptor for
3bbffd
output.  Any read from such descriptor returns 0, and any write just
3bbffd
fails with EBADF, which should work better with unprepared writers.
3bbffd
3bbffd
* libpam/pam_modutil_sanitize.c (redirect_out_pipe): Remove.
3bbffd
(redirect_out): Call redirect_in_pipe instead of redirect_out_pipe.
3bbffd
3bbffd
Fixes: b0ec5d1e ("Introduce pam_modutil_sanitize_helper_fds")
3bbffd
---
3bbffd
 libpam/pam_modutil_sanitize.c | 30 +-----------------------------
3bbffd
 1 file changed, 1 insertion(+), 29 deletions(-)
3bbffd
3bbffd
diff --git a/libpam/pam_modutil_sanitize.c b/libpam/pam_modutil_sanitize.c
3bbffd
index 605c859d..58b9537c 100644
3bbffd
--- a/libpam/pam_modutil_sanitize.c
3bbffd
+++ b/libpam/pam_modutil_sanitize.c
3bbffd
@@ -46,34 +46,6 @@ redirect_in_pipe(pam_handle_t *pamh, int fd, const char *name)
3bbffd
 	return fd;
3bbffd
 }
3bbffd
 
3bbffd
-/*
3bbffd
- * Creates a pipe, closes its read end, redirects fd to its write end.
3bbffd
- * Returns fd on success, -1 otherwise.
3bbffd
- */
3bbffd
-static int
3bbffd
-redirect_out_pipe(pam_handle_t *pamh, int fd, const char *name)
3bbffd
-{
3bbffd
-	int out[2];
3bbffd
-
3bbffd
-	if (pipe(out) < 0) {
3bbffd
-		pam_syslog(pamh, LOG_ERR, "Could not create pipe: %m");
3bbffd
-		return -1;
3bbffd
-	}
3bbffd
-
3bbffd
-	close(out[0]);
3bbffd
-
3bbffd
-	if (out[1] == fd)
3bbffd
-		return fd;
3bbffd
-
3bbffd
-	if (dup2(out[1], fd) != fd) {
3bbffd
-		pam_syslog(pamh, LOG_ERR, "dup2 of %s failed: %m", name);
3bbffd
-		fd = -1;
3bbffd
-	}
3bbffd
-
3bbffd
-	close(out[1]);
3bbffd
-	return fd;
3bbffd
-}
3bbffd
-
3bbffd
 /*
3bbffd
  * Opens /dev/null for writing, redirects fd there.
3bbffd
  * Returns fd on success, -1 otherwise.
3bbffd
@@ -106,7 +78,7 @@ redirect_out(pam_handle_t *pamh, enum pam_modutil_redirect_fd mode,
3bbffd
 {
3bbffd
 	switch (mode) {
3bbffd
 		case PAM_MODUTIL_PIPE_FD:
3bbffd
-			if (redirect_out_pipe(pamh, fd, name) < 0)
3bbffd
+			if (redirect_in_pipe(pamh, fd, name) < 0)
3bbffd
 				return -1;
3bbffd
 			break;
3bbffd
 		case PAM_MODUTIL_NULL_FD:
3bbffd
-- 
3bbffd
2.25.3
3bbffd