kentpeacock / rpms / openssh

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