[PATCH 1/9] ceph: fix mdsmap use-after-free in ceph_statfs()

From: Max Kellermann

Date: Wed Nov 11 2026 - 11:20:28 EST


ceph_statfs() reads mdsc->mdsmap without holding mdsc->mutex, but
ceph_mdsc_handle_mdsmap() replaces the mdsmap and frees the old one
under that mutex. A statfs() racing with an mdsmap update can
therefore read m_num_data_pg_pools from freed memory, and then load
the m_data_pg_pools pointer from it and dereference it.

Any user can call statfs(), and mdsmap updates happen whenever an
MDS changes state.

Read the data pool while holding mdsc->mutex.

Fixes: 06d74376c8af ("ceph: more accurate statfs")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Max Kellermann <max.kellermann@xxxxxxxxx>
---
fs/ceph/super.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index bb5591c1e154..01f92d77ef45 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -64,6 +64,7 @@ static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
{
struct ceph_fs_client *fsc = ceph_inode_to_fs_client(d_inode(dentry));
struct ceph_mon_client *monc = &fsc->client->monc;
+ struct ceph_mds_client *mdsc = fsc->mdsc;
struct ceph_monmap *monmap;
struct ceph_statfs st;
int i, err;
@@ -73,11 +74,14 @@ static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
ceph_blog_enter(fsc, &__ji);

boutc(fsc->client, "begin\n");
- if (fsc->mdsc->mdsmap->m_num_data_pg_pools == 1) {
- data_pool = fsc->mdsc->mdsmap->m_data_pg_pools[0];
- } else {
+
+ /* ceph_mdsc_handle_mdsmap() replaces and frees the mdsmap */
+ mutex_lock(&mdsc->mutex);
+ if (mdsc->mdsmap->m_num_data_pg_pools == 1)
+ data_pool = mdsc->mdsmap->m_data_pg_pools[0];
+ else
data_pool = CEPH_NOPOOL;
- }
+ mutex_unlock(&mdsc->mutex);

err = ceph_monc_do_statfs(monc, data_pool, &st);
if (err < 0) {
--
2.53.0