rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone

Blame SOURCES/openssh-7.2p2-s390-closefrom.patch

aedd00
Zseries only: Leave the hardware filedescriptors open.
aedd00
aedd00
All filedescriptors above 2 are getting closed when a new
aedd00
sshd process to handle a new client connection is
aedd00
spawned. As the process also chroot into an empty filesystem
aedd00
without any device nodes, there is no chance to reopen the
aedd00
files. This patch filters out the reqired fds in the
aedd00
closefrom function so these are skipped in the close loop.
aedd00
aedd00
Author: Harald Freudenberger <freude@de.ibm.com>
aedd00
aedd00
---
aedd00
 openbsd-compat/bsd-closefrom.c |   26 ++++++++++++++++++++++++++
aedd00
 1 file changed, 26 insertions(+)
aedd00
aedd00
--- a/openbsd-compat/bsd-closefrom.c
aedd00
+++ b/openbsd-compat/bsd-closefrom.c
aedd00
@@ -82,7 +82,33 @@ closefrom(int lowfd)
aedd00
 	    fd = strtol(dent->d_name, &endp, 10);
aedd00
 	    if (dent->d_name != endp && *endp == '\0' &&
aedd00
 		fd >= 0 && fd < INT_MAX && fd >= lowfd && fd != dirfd(dirp))
aedd00
+#ifdef __s390__
aedd00
+		{
aedd00
+		    /*
aedd00
+		     * the filedescriptors used to communicate with
aedd00
+		     * the device drivers to provide hardware support
aedd00
+		     * should survive. HF <freude@de.ibm.com>
aedd00
+		     */
aedd00
+		    char fpath[PATH_MAX], lpath[PATH_MAX];
aedd00
+		    len = snprintf(fpath, sizeof(fpath), "%s/%s",
aedd00
+				   fdpath, dent->d_name);
aedd00
+		    if (len > 0 && (size_t)len <= sizeof(fpath)) {
aedd00
+			len = readlink(fpath, lpath, sizeof(lpath));
aedd00
+			if (len > 0) {
aedd00
+			    lpath[len] = 0;
aedd00
+			    if (strstr(lpath, "dev/z90crypt")
aedd00
+				|| strstr(lpath, "dev/zcrypt")
aedd00
+				|| strstr(lpath, "dev/prandom")
aedd00
+				|| strstr(lpath, "dev/shm/icastats"))
aedd00
+				fd = -1;
aedd00
+			}
aedd00
+		    }
aedd00
+		    if (fd >= 0)
aedd00
+			(void) close((int) fd);
aedd00
+		}
aedd00
+#else
aedd00
 		(void) close((int) fd);
aedd00
+#endif
aedd00
 	}
aedd00
 	(void) closedir(dirp);
aedd00
     } else
aedd00