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