Skip to contentSkip to conversation

autofs-5.0.4 - use CLOEXEC flag for setmntent

PATCH In review Ian Kent 1 participant 3 messages Feb 11, 2009

Subsystems (2)
lore
Share & tools
lore

Ian Kent

author maintainer
#0 lore raw

PATCH 1/13 autofs-5.0.4 - use CLOEXEC flag for setmntent

Update use of CLOEXEC functionality to cover setmntent(3) calls as well.
---

 CHANGELOG           |    1 +
 include/automount.h |   20 ++++++++++++++++++++
 lib/mounts.c        |    8 ++++----
 3 files changed, 25 insertions(+), 4 deletions(-)
CHANGELOG +1 -0
index af77b55..eb4a189 100644
@@ -8,6 +8,7 @@
 - make hash table scale to thousands of entries (Paul Wankadia,
   Valerie Aurora Henson).
 - clear the quoted flag after each character from program map input.
+- use CLOEXEC flag for setmntent also.
 
 4/11/2008 autofs-5.0.4
 -----------------------
include/automount.h +20 -0
index 005d209..46cb6c6 100644
@@ -581,5 +581,25 @@ static inline FILE *open_fopen_r(const char *path)
 	return f;
 }
 
+static inline FILE *open_setmntent_r(const char *table)
+{
+	FILE *tab;
+
+#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
+	if (cloexec_works != -1) {
+		tab = setmntent(table, "re");
+		if (tab != NULL) {
+			check_cloexec(fileno(tab));
+			return tab;
+		}
+	}
+#endif
+	tab = fopen(table, "r");
+	if (tab == NULL)
+		return NULL;
+	check_cloexec(fileno(tab));
+	return tab;
+}
+
 #endif
 
lib/mounts.c +4 -4
index ce4691b..b98e1a4 100644
@@ -218,7 +218,7 @@ struct mnt_list *get_mnt_list(const char *table, const char *path, int include)
 	if (!path || !pathlen || pathlen > PATH_MAX)
 		return NULL;
 
-	tab = setmntent(table, "r");
+	tab = open_setmntent_r(table);
 	if (!tab) {
 		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
 		logerr("setmntent: %s", estr);
@@ -415,7 +415,7 @@ static int table_is_mounted(const char *table, const char *path, unsigned int ty
 	if (!path || !pathlen || pathlen >= PATH_MAX)
 		return 0;
 
-	tab = setmntent(table, "r");
+	tab = open_setmntent_r(table);
 	if (!tab) {
 		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
 		logerr("setmntent: %s", estr);
@@ -489,7 +489,7 @@ int has_fstab_option(const char *opt)
 	if (!opt)
 		return 0;
 
-	tab = setmntent(_PATH_MNTTAB, "r");
+	tab = open_setmntent_r(_PATH_MNTTAB);
 	if (!tab) {
 		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
 		logerr("setmntent: %s", estr);
@@ -668,7 +668,7 @@ struct mnt_list *tree_make_mnt_tree(const char *table, const char *path)
 	size_t plen;
 	int eq;
 
-	tab = setmntent(table, "r");
+	tab = open_setmntent_r(table);
 	if (!tab) {
 		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
 		logerr("setmntent: %s", estr);
author maintainer
#1 lore raw

PATCH 2/13 autofs-5.0.4 - fix hosts map use after free

From: Paul Wankadia <[email protected]>

This patch fixed use a map entry after it has been freed in the hosts map lookup module.
---

 CHANGELOG              |    1 +
 modules/lookup_hosts.c |    8 +++++---
 2 files changed, 6 insertions(+), 3 deletions(-)
CHANGELOG +1 -0
index eb4a189..3199e4d 100644
@@ -9,6 +9,7 @@
   Valerie Aurora Henson).
 - clear the quoted flag after each character from program map input.
 - use CLOEXEC flag for setmntent also.
+- fix hosts map use after free (Paul Wankadia).
 
 4/11/2008 autofs-5.0.4
 -----------------------
modules/lookup_hosts.c +5 -3
index 93b975a..d3ae0e2 100644
@@ -138,17 +138,19 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
 	/* Check if we recorded a mount fail for this key anywhere */
 	me = lookup_source_mapent(ap, name, LKP_DISTINCT);
 	if (me) {
+		struct mapent_cache *fmc = me->mc;
+
 		if (me->status >= time(NULL)) {
-			cache_unlock(me->mc);
+			cache_unlock(fmc);
 			return NSS_STATUS_NOTFOUND;
 		}
 
 		if (!me->mapent) {
-			cache_delete(me->mc, name);
+			cache_delete(fmc, name);
 			me = NULL;
 		}
 
-		cache_unlock(me->mc);
+		cache_unlock(fmc);
 	}
 
 	cache_readlock(mc);
author maintainer
#2 lore raw
In reply to Ian Kent
Quoted 2 lines · Ian Kent

Update use of CLOEXEC functionality to cover setmntent(3) calls as well.

Pleas ignore this false start.
Oops.

Quoted 94 lines

---

 CHANGELOG           |    1 +
 include/automount.h |   20 ++++++++++++++++++++
 lib/mounts.c        |    8 ++++----
 3 files changed, 25 insertions(+), 4 deletions(-)
CHANGELOG +1 -0
index af77b55..eb4a189 100644
@@ -8,6 +8,7 @@
 - make hash table scale to thousands of entries (Paul Wankadia,
   Valerie Aurora Henson).
 - clear the quoted flag after each character from program map input.
+- use CLOEXEC flag for setmntent also.
 
 4/11/2008 autofs-5.0.4
 -----------------------
include/automount.h +20 -0
index 005d209..46cb6c6 100644
@@ -581,5 +581,25 @@ static inline FILE *open_fopen_r(const char *path)
 	return f;
 }
 
+static inline FILE *open_setmntent_r(const char *table)
+{
+	FILE *tab;
+
+#if defined(O_CLOEXEC) && defined(SOCK_CLOEXEC)
+	if (cloexec_works != -1) {
+		tab = setmntent(table, "re");
+		if (tab != NULL) {
+			check_cloexec(fileno(tab));
+			return tab;
+		}
+	}
+#endif
+	tab = fopen(table, "r");
+	if (tab == NULL)
+		return NULL;
+	check_cloexec(fileno(tab));
+	return tab;
+}
+
 #endif
 
lib/mounts.c +4 -4
index ce4691b..b98e1a4 100644
@@ -218,7 +218,7 @@ struct mnt_list *get_mnt_list(const char *table, const char *path, int include)
 	if (!path || !pathlen || pathlen > PATH_MAX)
 		return NULL;
 
-	tab = setmntent(table, "r");
+	tab = open_setmntent_r(table);
 	if (!tab) {
 		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
 		logerr("setmntent: %s", estr);
@@ -415,7 +415,7 @@ static int table_is_mounted(const char *table, const char *path, unsigned int ty
 	if (!path || !pathlen || pathlen >= PATH_MAX)
 		return 0;
 
-	tab = setmntent(table, "r");
+	tab = open_setmntent_r(table);
 	if (!tab) {
 		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
 		logerr("setmntent: %s", estr);
@@ -489,7 +489,7 @@ int has_fstab_option(const char *opt)
 	if (!opt)
 		return 0;
 
-	tab = setmntent(_PATH_MNTTAB, "r");
+	tab = open_setmntent_r(_PATH_MNTTAB);
 	if (!tab) {
 		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
 		logerr("setmntent: %s", estr);
@@ -668,7 +668,7 @@ struct mnt_list *tree_make_mnt_tree(const char *table, const char *path)
 	size_t plen;
 	int eq;
 
-	tab = setmntent(table, "r");
+	tab = open_setmntent_r(table);
 	if (!tab) {
 		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
 		logerr("setmntent: %s", estr);

_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs