[PATCH 6/9] ceph: fix mdsmap use-after-free in ceph_get_tree() error path
From: Max Kellermann
Date: Wed Nov 11 2026 - 11:21:56 EST
When mounting fails, ceph_get_tree() calls
ceph_mdsmap_is_cluster_available() on mdsc->mdsmap without holding
mdsc->mutex. The MDS client is still running at that point, and
ceph_mdsc_handle_mdsmap() can replace the mdsmap and free the old one
concurrently, so this can walk freed memory.
Check the map while holding mdsc->mutex.
Fixes: 97820058fb28 ("ceph: check availability of mds cluster on mount after wait timeout")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Max Kellermann <max.kellermann@xxxxxxxxx>
---
fs/ceph/super.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index 01f92d77ef45..94ff935492e5 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -1364,6 +1364,7 @@ static int ceph_get_tree(struct fs_context *fc)
struct dentry *res;
int (*compare_super)(struct super_block *, struct fs_context *) =
ceph_compare_super;
+ bool available;
int err;
dout("ceph_get_tree\n");
@@ -1429,7 +1430,11 @@ static int ceph_get_tree(struct fs_context *fc)
return 0;
out_splat:
- if (!ceph_mdsmap_is_cluster_available(fsc->mdsc->mdsmap)) {
+ /* ceph_mdsc_handle_mdsmap() replaces and frees the mdsmap */
+ mutex_lock(&fsc->mdsc->mutex);
+ available = ceph_mdsmap_is_cluster_available(fsc->mdsc->mdsmap);
+ mutex_unlock(&fsc->mdsc->mutex);
+ if (!available) {
pr_info("No mds server is up or the cluster is laggy\n");
err = -EHOSTUNREACH;
}
--
2.53.0