[PATCH 5/9] ceph: fix mdsmap use-after-free in mds_peer_reset()
From: Max Kellermann
Date: Wed Nov 11 2026 - 11:20:26 EST
mds_peer_reset() reads the MDS state from mdsc->mdsmap without holding
mdsc->mutex, but ceph_mdsc_handle_mdsmap() replaces the mdsmap and
frees the old one under that mutex. A peer reset often coincides with
an MDS failover, which is exactly when a new mdsmap arrives, so this
can read freed memory.
Read the state while holding mdsc->mutex. The messenger drops
con->mutex before calling ->peer_reset(), so no lock is held here.
Fixes: cbcb358b744b ("ceph: skip reconnecting if MDS is not ready")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Max Kellermann <max.kellermann@xxxxxxxxx>
---
fs/ceph/mds_client.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index a43ce23d48f4..aa4406fd65b9 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -7300,13 +7300,19 @@ static void mds_peer_reset(struct ceph_connection *con)
{
struct ceph_mds_session *s = con->private;
struct ceph_mds_client *mdsc = s->s_mdsc;
+ int mds_state;
int rc;
pr_warn_client(mdsc->fsc->client, "mds%d closed our session\n",
s->s_mds);
+ /* ceph_mdsc_handle_mdsmap() replaces and frees the mdsmap */
+ mutex_lock(&mdsc->mutex);
+ mds_state = ceph_mdsmap_get_state(mdsc->mdsmap, s->s_mds);
+ mutex_unlock(&mdsc->mutex);
+
if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_FENCE_IO ||
- ceph_mdsmap_get_state(mdsc->mdsmap, s->s_mds) < CEPH_MDS_STATE_RECONNECT)
+ mds_state < CEPH_MDS_STATE_RECONNECT)
return;
/*
--
2.53.0