vishalmishra434 / rpms / openssh

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