When a cephfs mount fails after the mon client has subscribed to the MDS map, ceph_get_tree() jumps to out_splat and calls ceph_mdsmap_is_cluster_available(fsc->mdsc->mdsmap) (super.c:1373-1381) without mdsc->mutex. That function (mdsmap.c:457-471) dereferences m_enabled, m_damaged, m_num_laggy and then walks m_info[]. In the meantime ceph_mdsc_handle_mdsmap() may publish a new map and free the old struct ceph_mdsmap (mds_client.c:7057-7061; no refcount/RCU), so the mount-failure path can read freed memory. I reproduced the UAF in the real function on 7.3 (KASAN, "Read of size 1" in ceph_mdsmap_is_cluster_available+0x18, i.e. the first m->m_enabled read), with a release-before-publish control run giving zero reports. The detailed description: * Test environment / affected version Linux 7.3.0 tree (Makefile: VERSION 7, PATCHLEVEL 3, SUBLEVEL 0) at /home/xuhanxiang/project/race/linux, not a git checkout: fs/ceph/super.c d06bb506183e26374582ee5d82322b8c fs/ceph/mds_client.c 8678459253e5b1452667946bf4457c5a fs/ceph/mdsmap.c 5cb2b54f0d3007961c36e68da1f6318c All line numbers are from this tree. Kernel 7.3.0 #2 PREEMPT(lazy), gcc 13.3.0, KASAN enabled (CONFIG_KASAN=y, CONFIG_CEPH_FS=y, CONFIG_CEPH_LIB=y, CONFIG_DEBUG_FS=y). QEMU/KVM, 4 vCPU/4G, busybox initramfs. * Mechanism ceph_get_tree() (super.c:1309-1388) creates the fs client, runs ceph_mdsc_init(), then ceph_real_mount(). If real_mount fails (e.g. __ceph_open_session() error, ceph_fs_debugfs_init()/fscache failure, open_root_dentry() error - super.c:1158-1212), or if ceph_setup_bdi() fails, control reaches: out_splat: if (!ceph_mdsmap_is_cluster_available(fsc->mdsc->mdsmap)) { pr_info("No mds server is up or the cluster is laggy\n"); err = -EHOSTUNREACH; } ceph_mdsc_close_sessions(fsc->mdsc); deactivate_locked_super(sb); ceph_mdsmap_is_cluster_available() (mdsmap.c:457-471): if (!m->m_enabled) return false; if (m->m_damaged) return false; if (m->m_num_laggy == m->m_num_active_mds) return false; for (i = 0; i < m->possible_max_rank; i++) { if (m->m_info[i].state == CEPH_MDS_STATE_ACTIVE) nr_active++; } return nr_active > 0; The map can already have been replaced and freed by the time this runs: create_fs_client() installs extra_mon_dispatch (super.c:836) and subscribes to CEPH_SUB_MDSMAP (super.c:839-841) before ceph_real_mount(), so mon connection work can call ceph_mdsc_handle_mdsmap() while the mount thread is failing. mount_mutex does not protect mdsc->mdsmap (the writer never takes it). The writer path is mds_client.c:7057-7061 with the synchronous free in mdsmap.c:443-455. * Trigger model - Needs CAP_SYS_ADMIN (or a userns mount) to attempt a ceph mount, and a mount failure that happens after the mon client subscribed to the MDS map (wrong root path, shortened mount_timeout, fscache/setup failure, ...). - Needs an MDS map update (MDS restart/failover, rank change, laggy set) concurrent with the failure path. - The reader dereferences the map immediately; in production the window is the interval between loading fsc->mdsc->mdsmap and the first m_enabled read. * Reproducer (attached: ceph_mdsmap_race_harness.c + instrumentation.patch) and results on 7.3 The harness builds a real struct ceph_mds_client (real ceph_mdsc_init()), publishes a minimal MDS map through the real ceph_mdsc_handle_mdsmap(), and runs a kthread that snapshots mdsc->mdsmap, waits until the map has been published and freed by the harness, then calls the real ceph_mdsmap_is_cluster_available() on the stale pointer (this is exactly what out_splat does, minus the mount syscall). # plan mr03: # setup (epoch 2) -> reader3 (snapshot + block) -> trigger # (publish epoch 3, free epoch 2) -> release (call the real function) Result: BUG: KASAN: slab-use-after-free in ceph_mdsmap_is_cluster_available+0x18/0xd0 Read of size 1 at addr ff11000100c10c58 by task cephrv3/115 Allocated by: ceph_mdsmap_decode+0xe1 <- ceph_mdsc_handle_mdsmap+0x288 Freed by: ceph_mdsc_handle_mdsmap+0x2c7 Control run mr03ctl (reader completes before the new map is published): KASAN count 0. * Suggested direction Take mdsc->mutex around the sanity check in ceph_get_tree()'s out_splat path (the writer holds it, and the check is only called from this unlocked site), or better, publish mdsc->mdsmap with RCU so readers can take a stable snapshot. Please keep me in Cc; I am not subscribed to the lists. Regards, Hanxiang Xu xuhx@hust.edu.cn