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