[PATCH 8/9] libceph: fix osdmap use-after-free in ceph_wait_for_latest_osdmap()
From: Max Kellermann
Date: Wed Nov 11 2026 - 11:24:09 EST
ceph_wait_for_latest_osdmap() 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). The function
waits for the monitor's reply first, so an osdmap update arriving in
the meantime is likely, and the epoch can then be read from freed
memory.
Read the epoch while holding osdc->lock for reading.
Fixes: bb229bbb3bf6 ("libceph: wait for latest osdmap in ceph_monc_blacklist_add()")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Max Kellermann <max.kellermann@xxxxxxxxx>
---
net/ceph/ceph_common.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/net/ceph/ceph_common.c b/net/ceph/ceph_common.c
index 67e88f30409d..39a0ddde3554 100644
--- a/net/ceph/ceph_common.c
+++ b/net/ceph/ceph_common.c
@@ -863,13 +863,19 @@ int ceph_wait_for_latest_osdmap(struct ceph_client *client,
unsigned long timeout)
{
u64 newest_epoch;
+ u32 epoch;
int ret;
ret = ceph_monc_get_version(&client->monc, "osdmap", &newest_epoch);
if (ret)
return ret;
- if (client->osdc.osdmap->epoch >= newest_epoch)
+ /* ceph_osdc_handle_map() replaces and frees the osdmap */
+ down_read(&client->osdc.lock);
+ epoch = client->osdc.osdmap->epoch;
+ up_read(&client->osdc.lock);
+
+ if (epoch >= newest_epoch)
return 0;
ceph_osdc_maybe_request_map(&client->osdc);
--
2.53.0