autofs/autofs-5.1.8-make-submount-cleanup-the-same-as-top-level-mounts.patch
2023-06-13 10:51:59 +08:00

132 lines
4.1 KiB
Diff

autofs-5.1.8 - make submount cleanup the same as top level mounts
From: Ian Kent <raven@themaw.net>
We often see segfaults when cleaning up resources at submount shutdown
after changes are made to resolve problems. It's always really hard to
work out what's causing these to happen.
But changing submounts to use the same final cleanup method as top level
mounts eliminates the faulting, at least in the case of the most recent
changes, hopefully this change in proceedure will continue to work.
Admitedly there's some setting of fields to NULL after freeing but that
didn't fix the problem until the procedure change was also made.
In any case the result is a consistency improvement.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/automount.c | 17 +++--------------
daemon/master.c | 19 +++++++++++++++++--
modules/mount_autofs.c | 6 +++---
4 files changed, 24 insertions(+), 19 deletions(-)
--- autofs-5.1.4.orig/CHANGELOG
+++ autofs-5.1.4/CHANGELOG
@@ -142,6 +142,7 @@
- dont take parent source lock at mount shutdown.
- eliminate buffer usage from handle_mounts_cleanup().
- fix possible use after free in handle_mounts_exit().
+- make submount cleanup the same as top level mounts.
xx/xx/2018 autofs-5.1.5
- fix flag file permission.
--- autofs-5.1.4.orig/daemon/automount.c
+++ autofs-5.1.4/daemon/automount.c
@@ -1765,21 +1765,10 @@ static void handle_mounts_cleanup(void *
master_source_unlock(ap->entry);
/*
- * Submounts are detached threads and don't belong to the
- * master map entry list so we need to free their resources
- * here.
+ * Send a signal to the signal handler so it can join with any
+ * completed handle_mounts() threads and perform final cleanup.
*/
- if (submount) {
- master_free_mapent_sources(ap->entry, 1);
- master_free_mapent(ap->entry);
- }
-
- /*
- * If we are not a submount send a signal to the signal handler
- * so it can join with any completed handle_mounts() threads and
- * perform final cleanup.
- */
- if (!submount && !pending)
+ if (!pending)
pthread_kill(signal_handler_thid, SIGTERM);
master_mutex_unlock();
--- autofs-5.1.4.orig/daemon/master.c
+++ autofs-5.1.4/daemon/master.c
@@ -384,11 +384,14 @@ static void __master_free_map_source(str
instance = source->instance;
while (instance) {
- if (instance->lookup)
+ if (instance->lookup) {
close_lookup(instance->lookup);
+ instance->lookup = NULL;
+ }
instance = instance->next;
}
close_lookup(source->lookup);
+ source->lookup = NULL;
}
if (source->argv)
free_argv(source->argc, source->argv);
@@ -401,6 +404,7 @@ static void __master_free_map_source(str
__master_free_map_source(instance, 0);
instance = next;
}
+ source->instance = NULL;
}
status = pthread_rwlock_destroy(&source->module_lock);
@@ -863,9 +867,20 @@ void master_add_mapent(struct master *ma
void master_remove_mapent(struct master_mapent *entry)
{
struct master *master = entry->master;
+ struct autofs_point *ap = entry->ap;
+
+ if (ap->submount) {
+ struct mnt_list *mnt;
- if (entry->ap->submount)
+ mnt = mnts_find_submount(ap->path);
+ if (mnt) {
+ warn(ap->logopt,
+ "map entry %s in use at shutdown", ap->path);
+ mnts_put_mount(mnt);
+ }
+ list_add(&entry->join, &master->completed);
return;
+ }
if (!list_empty(&entry->list)) {
list_del_init(&entry->list);
--- autofs-5.1.4.orig/modules/mount_autofs.c
+++ autofs-5.1.4/modules/mount_autofs.c
@@ -28,8 +28,8 @@
#define MODPREFIX "mount(autofs): "
-/* Attribute to create detached thread */
-extern pthread_attr_t th_attr_detached;
+/* Attributes to create handle_mounts() thread */
+extern pthread_attr_t th_attr;
extern struct startup_cond suc;
int mount_version = AUTOFS_MOUNT_VERSION; /* Required by protocol */
@@ -327,7 +327,7 @@ int mount_mount(struct autofs_point *ap,
suc.done = 0;
suc.status = 0;
- if (pthread_create(&thid, &th_attr_detached, handle_mounts, &suc)) {
+ if (pthread_create(&thid, &th_attr, handle_mounts, &suc)) {
crit(ap->logopt,
MODPREFIX
"failed to create mount handler thread for %s",