jonathancammack / rpms / openssh

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