[PATCH 2/9] ceph: fix mdsmap use-after-free in debugfs mdsmap_show()
From: Max Kellermann
Date: Wed Nov 11 2026 - 11:21:52 EST
mdsmap_show() walks mdsc->mdsmap without holding mdsc->mutex, but
ceph_mdsc_handle_mdsmap() replaces the mdsmap and frees the old one
under that mutex. Reading the debugfs "mdsmap" file while an MDS
changes state can therefore access freed memory, including the m_info
array.
Hold mdsc->mutex while printing the map.
Fixes: 76aa844d5b2f ("ceph: debugfs")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Max Kellermann <max.kellermann@xxxxxxxxx>
---
fs/ceph/debugfs.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/fs/ceph/debugfs.c b/fs/ceph/debugfs.c
index 6a9a5551d9d7..01c9f1896aa1 100644
--- a/fs/ceph/debugfs.c
+++ b/fs/ceph/debugfs.c
@@ -59,11 +59,17 @@ static int mdsmap_show(struct seq_file *s, void *p)
{
int i;
struct ceph_fs_client *fsc = s->private;
+ struct ceph_mds_client *mdsc = fsc->mdsc;
struct ceph_mdsmap *mdsmap;
- if (!fsc->mdsc || !fsc->mdsc->mdsmap)
+ if (!mdsc)
return 0;
- mdsmap = fsc->mdsc->mdsmap;
+
+ /* ceph_mdsc_handle_mdsmap() replaces and frees the mdsmap */
+ mutex_lock(&mdsc->mutex);
+ mdsmap = mdsc->mdsmap;
+ if (!mdsmap)
+ goto out;
seq_printf(s, "epoch %d\n", mdsmap->m_epoch);
seq_printf(s, "root %d\n", mdsmap->m_root);
seq_printf(s, "max_mds %d\n", mdsmap->m_max_mds);
@@ -76,6 +82,8 @@ static int mdsmap_show(struct seq_file *s, void *p)
ceph_pr_addr(addr),
ceph_mds_state_name(state));
}
+out:
+ mutex_unlock(&mdsc->mutex);
return 0;
}
--
2.53.0