Re: [PATCH 0/9] ceph: fix mdsmap and osdmap use-after-free in unlocked readers

From: Xiubo Li

Date: Thu Nov 12 2026 - 10:10:00 EST


Hi Max,

Tested on a KASAN+lockdep kernel (on top of the ceph testing branch)
with sleep injection widening each window: all the UAFs fixed by
patches 1-6 and 9 reproduce on the base and are gone with the series;
patches 7-8 were exercised under osdmap churn; lockdep stays quiet,
also across fsstress with MDS failovers.

One reader is missed: send_mds_reconnect() still does

ceph_con_open(&session->s_con, CEPH_ENTITY_TYPE_MDS, mds,
ceph_mdsmap_get_addr(mdsc->mdsmap, mds));

with only s_mutex held, and it is reached from mds_peer_reset() (the
path patch 5 fixes). With the series applied:

BUG: KASAN: slab-use-after-free in ceph_con_open+0x14f/0x230 [libceph]
Read of size 136 ...
send_mds_reconnect+0xa91/0x1710 [ceph]
mds_peer_reset+0x26c/0x36b [ceph]
process_session_reset+0x349/0x540 [libceph]
Freed by: ceph_mdsmap_destroy <- ceph_mdsc_handle_mdsmap

Copying the address into a local while mdsc->mutex is held for the
sessions[mds] check a few lines earlier would fix it; could you add
that as a follow-up patch?

Nit for 7-9: incremental maps are applied in place, so the osdmap is
only replaced on a full map; the rbd case is really hit through
incrementals (a pool rename kfree()s pi->name).

Thanks
- Xiubo

Max Kellermann <max.kellermann@xxxxxxxxx> 于2026年11月11日周三 17:25写道:
>
> The MDS and OSD clients replace their maps and free the old ones
> under a lock: mdsc->mutex for the mdsmap and osdc->lock for the
> osdmap. Several readers dereference these maps without that lock and
> can therefore access freed memory if a new map arrives concurrently.
> The worst is ceph_statfs(), which any user can reach and which loads
> and dereferences a pointer from the old mdsmap.
>
> Each patch takes the lock that protects the replacement around the
> reads. __ceph_setxattr() cannot take mdsc->mutex under i_ceph_lock,
> so it uses a copy of m_max_xattr_size kept in the mds client.
>
> The same problem in ceph_compare_options() was already fixed by
> commit 19db525816db ("libceph: use RCU to protect monmap in
> ceph_compare_options()").
>
> These bugs were found by code review and have not been reproduced.
>
> Max Kellermann (9):
> ceph: fix mdsmap use-after-free in ceph_statfs()
> ceph: fix mdsmap use-after-free in debugfs mdsmap_show()
> ceph: fix mdsmap use-after-free in __ceph_setxattr()
> ceph: fix mdsmap use-after-free in send_renew_caps() and
> renewed_caps()
> ceph: fix mdsmap use-after-free in mds_peer_reset()
> ceph: fix mdsmap use-after-free in ceph_get_tree() error path
> ceph: fix osdmap use-after-free in ceph_sync_setxattr()
> libceph: fix osdmap use-after-free in ceph_wait_for_latest_osdmap()
> rbd: fix osdmap use-after-free in pool lookups
>
> drivers/block/rbd.c | 13 +++++++++++--
> fs/ceph/debugfs.c | 12 ++++++++++--
> fs/ceph/mds_client.c | 18 ++++++++++++++++--
> fs/ceph/mds_client.h | 7 +++++++
> fs/ceph/super.c | 19 ++++++++++++++-----
> fs/ceph/xattr.c | 13 +++++++++----
> net/ceph/ceph_common.c | 8 +++++++-
> 7 files changed, 74 insertions(+), 16 deletions(-)
>
> --
> 2.53.0
>
>