[PATCH 7/9] ceph: fix osdmap use-after-free in ceph_sync_setxattr()
From: Max Kellermann
Date: Wed Nov 11 2026 - 11:29:00 EST
ceph_sync_setxattr() reads osdc->osdmap->epoch without holding
osdc->lock, but ceph_osdc_handle_map() replaces the osdmap and frees
the old one under that lock (held for writing). A setxattr() racing
with an osdmap update can therefore read the epoch from freed memory
and send a garbage epoch to the MDS, which uses it to decide whether
it needs a newer osdmap to validate the layout.
Read the epoch while holding osdc->lock for reading.
Fixes: 968cd14edc3a ("ceph: set osdmap epoch for setxattr")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Max Kellermann <max.kellermann@xxxxxxxxx>
---
fs/ceph/xattr.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index 8f97b6448d7a..64ccf70aa3dd 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -1179,8 +1179,11 @@ static int ceph_sync_setxattr(struct inode *inode, const char *name,
if (op == CEPH_MDS_OP_SETXATTR) {
req->r_args.setxattr.flags = cpu_to_le32(flags);
+ /* ceph_osdc_handle_map() replaces and frees the osdmap */
+ down_read(&osdc->lock);
req->r_args.setxattr.osdmap_epoch =
cpu_to_le32(osdc->osdmap->epoch);
+ up_read(&osdc->lock);
req->r_pagelist = pagelist;
pagelist = NULL;
}
--
2.53.0