diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index ff95fbc569..594efea989 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -251,7 +251,13 @@ int bind_remount_recursive_with_mountinfo( r = hashmap_ensure_put(&todo, &path_hash_ops_free, d, ULONG_TO_PTR(flags)); if (r == -EEXIST) - continue; + /* If the same path was recorded, but with different mount flags, update it: + * it means a mount point is overmounted, and libmount returns the "bottom" (or + * older one) first, but we want to reapply the flags from the "top" (or newer + * one). See: https://github.com/systemd/systemd/issues/20032 + * Note that this shouldn't really fail, as we were just told that the key + * exists, and it's an update so we want 'd' to be freed immediately. */ + r = hashmap_update(todo, d, ULONG_TO_PTR(flags)); if (r < 0) return r; if (r > 0)