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