From 60c7c495a0d385d70940fdf1aa815281853d86ea Mon Sep 17 00:00:00 2001 From: Ian Kent Date: Fri, 22 Dec 2023 10:24:01 +0800 Subject: [PATCH] Fix a SEGV that occurs during a restart when remounting already mounted mounts. Jira: https://issues.redhat.com/browse/RHEL-19731 In commit 635b90ecc (autofs-5.1.8 - fix mount tree startup reconnect) when getting the parent the check for a multi-mount should include a check for the root of the multi-mount as well since the root does not set the parent. There's also a possible deadlock when re-connecting to existing direct mounts. If we're starting up or trying to re-connect to an existing direct mount we could be iterating through the map entries with the readlock held so we can't just take the writelock for direct mounts. But when trying to re-connect to an existing mount at startup there won't be any other process updating the map entry cache. Signed-off-by: Ian Kent --- autofs-5.1.9-fix-deadlock-in-remount.patch | 68 +++++++++++++++++++ ...ent-multi-mount-check-in-try_remount.patch | 43 ++++++++++++ autofs.spec | 15 +++- 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 autofs-5.1.9-fix-deadlock-in-remount.patch create mode 100644 autofs-5.1.9-fix-get-parent-multi-mount-check-in-try_remount.patch diff --git a/autofs-5.1.9-fix-deadlock-in-remount.patch b/autofs-5.1.9-fix-deadlock-in-remount.patch new file mode 100644 index 0000000..415fc01 --- /dev/null +++ b/autofs-5.1.9-fix-deadlock-in-remount.patch @@ -0,0 +1,68 @@ +autofs-5.1.9 - fix deadlock in remount + +From: Ian Kent + +If we're starting up or trying to re-connect to an existing direct +mount we could be iterating through the map entries with the readlock +held so we can't just take the writelock for direct mounts. But when +trying to re-connect to an existing mount at startup there won't be +any other process updating the map entry cache. + +Signed-off-by: Ian Kent +--- + CHANGELOG | 1 + + modules/parse_sun.c | 26 ++++++++++++++++++++++++-- + 2 files changed, 25 insertions(+), 2 deletions(-) + +--- autofs-5.1.7.orig/CHANGELOG ++++ autofs-5.1.7/CHANGELOG +@@ -160,6 +160,7 @@ + - allow -null map in indirect maps. + - fix multi-mount check. + - fix get parent multi-mount check in try_remount(). ++- fix deadlock in remount. + + 25/01/2021 autofs-5.1.7 + - make bind mounts propagation slave by default. +--- autofs-5.1.7.orig/modules/parse_sun.c ++++ autofs-5.1.7/modules/parse_sun.c +@@ -889,7 +889,18 @@ update_offset_entry(struct autofs_point + strcpy(m_mapent, loc); + } + +- cache_writelock(mc); ++ /* ++ * If we're starting up or trying to re-connect to an existing ++ * direct mount we could be iterating through the map entries ++ * with the readlock held so we can't just take the writelock ++ * for direct mounts. But at when trying to re-connect to an ++ * existing mount at startup there won't be any other process ++ * updating the map entry cache. ++ */ ++ if (ap->state == ST_INIT && ap->flags & MOUNT_FLAG_REMOUNT) ++ cache_readlock(mc); ++ else ++ cache_writelock(mc); + ret = cache_update_offset(mc, name, m_key, m_mapent, age); + + me = cache_lookup_distinct(mc, m_key); +@@ -1581,7 +1592,18 @@ dont_expand: + free(myoptions); + } while (*p == '/' || (*p == '"' && *(p + 1) == '/')); + +- cache_writelock(mc); ++ /* ++ * If we're starting up or trying to re-connect to an existing ++ * direct mount we could be iterating through the map entries ++ * with the readlock held so we can't just take the writelock ++ * for direct mounts. But at when trying to re-connect to an ++ * existing mount at startup there won't be any other process ++ * updating the map entry cache. ++ */ ++ if (ap->state == ST_INIT && ap->flags & MOUNT_FLAG_REMOUNT) ++ cache_readlock(mc); ++ else ++ cache_writelock(mc); + me = cache_lookup_distinct(mc, name); + if (!me) { + cache_unlock(mc); diff --git a/autofs-5.1.9-fix-get-parent-multi-mount-check-in-try_remount.patch b/autofs-5.1.9-fix-get-parent-multi-mount-check-in-try_remount.patch new file mode 100644 index 0000000..74fa55e --- /dev/null +++ b/autofs-5.1.9-fix-get-parent-multi-mount-check-in-try_remount.patch @@ -0,0 +1,43 @@ +autofs-5.1.9 - fix get parent multi-mount check in try_remount() + +From: Ian Kent + +In commit 635b90ecc (autofs-5.1.8 - fix mount tree startup reconnect) +when getting the parent the check for a multi-mount should include a +check for the root of the multi-mount as well since the root does not +set the parent. + +We could set the root parent to itself but that may have side effects +because the convention has always been the parent is NULL for the +multi-mount root. + +Reported-by: Roberto Bergantinos Corpas +Suggested-by: Roberto Bergantinos Corpas + +Signed-off-by: Ian Kent +--- + CHANGELOG | 1 + + lib/mounts.c | 2 +- + 2 files changed, 2 insertions(+), 1 deletion(-) + +--- autofs-5.1.7.orig/CHANGELOG ++++ autofs-5.1.7/CHANGELOG +@@ -159,6 +159,7 @@ + - fix expire retry looping. + - allow -null map in indirect maps. + - fix multi-mount check. ++- fix get parent multi-mount check in try_remount(). + + 25/01/2021 autofs-5.1.7 + - make bind mounts propagation slave by default. +--- autofs-5.1.7.orig/lib/mounts.c ++++ autofs-5.1.7/lib/mounts.c +@@ -2878,7 +2878,7 @@ int try_remount(struct autofs_point *ap, + } + + me->flags &= ~MOUNT_FLAG_DIR_CREATED; +- mapent = IS_MM(me) ? MM_PARENT(me) : me; ++ mapent = IS_MM(me) && !IS_MM_ROOT(me) ? MM_PARENT(me) : me; + /* Direct or offset mount, key is full path */ + if (mapent->key[0] == '/') { + if (!is_mounted(mapent->key, MNTS_REAL)) diff --git a/autofs.spec b/autofs.spec index c5676d2..010e788 100644 --- a/autofs.spec +++ b/autofs.spec @@ -12,7 +12,7 @@ Summary: A tool for automatically mounting and unmounting filesystems Name: autofs Version: 5.1.7 -Release: 57%{?dist} +Release: 58%{?dist} Epoch: 1 License: GPLv2+ Source: https://www.kernel.org/pub/linux/daemons/autofs/v5/autofs-%{version}-2.tar.gz @@ -189,6 +189,9 @@ Patch175: autofs-5.1.8-fix-expire-retry-looping.patch Patch176: autofs-5.1.8-allow-null-map-in-indirect-maps.patch Patch177: autofs-5.1.8-fix-multi-mount-check.patch +Patch178: autofs-5.1.9-fix-get-parent-multi-mount-check-in-try_remount.patch +Patch179: autofs-5.1.9-fix-deadlock-in-remount.patch + %if %{with_systemd} BuildRequires: systemd-units BuildRequires: systemd-devel @@ -421,6 +424,9 @@ echo %{version}-%{release} > .version %patch176 -p1 %patch177 -p1 +%patch178 -p1 +%patch179 -p1 + %build LDFLAGS=-Wl,-z,now %configure \ @@ -528,6 +534,13 @@ fi %dir /etc/auto.master.d %changelog +* Fri Dec 22 2023 Ian Kent - 1:5.1.7-58 +- RHEL-19731 - SIGSEGV using hierarchical map entries on reload with + autofs-5.1.4-109 + - fix get parent multi-mount check in try_remount(). + - fix deadlock in remount. +- Resolves: RHEL-19731 + * Mon Oct 30 2023 Ian Kent - 1:5.1.7-57 - RHEL-13084 - multi mount detection fails for share with blank+dash causing SEGV crash