Blame SOURCES/autofs-5.1.0-dont-allocate-dev_ctl_ops-too-early.patch

304803
autofs-5.1.0 - dont allocate dev_ctl_ops too early
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
If the standard io file descriptors have been closed by the cloning
304803
process the file handle for autofs device control can correspond to
304803
a descriptor number of one of the standard io descriptors which will
304803
be closed when the process is daemonized.
304803
304803
Avoid this by closing the device control descriptor opened when
304803
performing sanity checks at startup so that it can be opened
304803
on a higher numbered file descriptor after the process has switched
304803
to daemon mode.
304803
---
304803
 CHANGELOG    |    1 +
304803
 lib/mounts.c |   14 +++++++++++++-
304803
 2 files changed, 14 insertions(+), 1 deletion(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -127,6 +127,7 @@
304803
 - allow empty value for some map options.
304803
 - allow empty value in macro selectors.
304803
 - add serialization to sasl init.
304803
+- dont allocate dev_ctl_ops too early.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/lib/mounts.c
304803
+++ autofs-5.0.7/lib/mounts.c
304803
@@ -90,7 +90,7 @@ unsigned int linux_version_code(void)
304803
 
304803
 unsigned int query_kproto_ver(void)
304803
 {
304803
-	struct ioctl_ops *ops = get_ioctl_ops();
304803
+	struct ioctl_ops *ops;
304803
 	char dir[] = "/tmp/autoXXXXXX", *t_dir;
304803
 	char options[MAX_OPTIONS_LEN + 1];
304803
 	pid_t pgrp = getpgrp();
304803
@@ -131,10 +131,19 @@ unsigned int query_kproto_ver(void)
304803
 		return 0;
304803
 	}
304803
 
304803
+	ops = get_ioctl_ops();
304803
+	if (!ops) {
304803
+		umount(t_dir);
304803
+		close(pipefd[0]);
304803
+		rmdir(t_dir);
304803
+		return 0;
304803
+	}
304803
+
304803
 	ops->open(LOGOPT_NONE, &ioctlfd, st.st_dev, t_dir);
304803
 	if (ioctlfd == -1) {
304803
 		umount(t_dir);
304803
 		close(pipefd[0]);
304803
+		close_ioctl_ctl();
304803
 		rmdir(t_dir);
304803
 		return 0;
304803
 	}
304803
@@ -146,6 +155,7 @@ unsigned int query_kproto_ver(void)
304803
 		ops->close(LOGOPT_NONE, ioctlfd);
304803
 		umount(t_dir);
304803
 		close(pipefd[0]);
304803
+		close_ioctl_ctl();
304803
 		rmdir(t_dir);
304803
 		return 0;
304803
 	}
304803
@@ -155,6 +165,7 @@ unsigned int query_kproto_ver(void)
304803
 		ops->close(LOGOPT_NONE, ioctlfd);
304803
 		umount(t_dir);
304803
 		close(pipefd[0]);
304803
+		close_ioctl_ctl();
304803
 		rmdir(t_dir);
304803
 		return 0;
304803
 	}
304803
@@ -162,6 +173,7 @@ unsigned int query_kproto_ver(void)
304803
 	ops->close(LOGOPT_NONE, ioctlfd);
304803
 	umount(t_dir);
304803
 	close(pipefd[0]);
304803
+	close_ioctl_ctl();
304803
 	rmdir(t_dir);
304803
 
304803
 	return 1;