* [PATCH] ceph: Hold s_mutex while waking up session caps in check_new_map()
@ 2026-12-04 18:45 Praneeth Balasubramanian
0 siblings, 0 replies; only message in thread
From: Praneeth Balasubramanian @ 2026-12-04 18:45 UTC (permalink / raw)
To: Ilya Dryomov, Alex Markuze, Xiubo Li
Cc: Viacheslav Dubeyko, Max Kellermann, ceph-devel, linux-kernel,
Praneeth Balasubramanian, stable
ceph_iterate_session_caps() says that the caller must hold the session
s_mutex. The iterator drops s_cap_lock around each callback and records
the current cap in session->s_cap_iterator, a single slot.
__ceph_remove_cap() leaves that cap on the list so that the iterator
can finish removing it. This only works if one iteration runs at a
time. Every other caller holds s_mutex: remove_session_caps(),
ceph_trim_caps(), send_mds_reconnect(), handle_session() for
RENEWCAPS and FORCE_RO, and the debugfs caps file.
check_new_map() drops s_mutex right after ceph_kick_flushing_caps() and
then calls wake_up_session_caps(s, RECONNECT). Session messages for the
same MDS are handled on its connection under s_mutex and can run at the
same time, for example CEPH_SESSION_RECALL_STATE, which trims caps with
ceph_trim_caps(). The second iteration overwrites s_cap_iterator and
clears it when it ends, so the cap that the first iteration is working
on loses its protection. If that cap is removed and put in the meantime,
the first iteration then follows the list pointers of a cap that was
already put.
Move the mutex_unlock() below wake_up_session_caps(). The session is
locked before mdsc->mutex here, which is the usual order, and
wake_up_session_cb() takes neither lock.
The missing lock was found by a static check that turns the locking rule
in a function's comment into a Clang context-analysis requirement on its
callers.
Fixes: 0dc2570fab22 ("ceph: reset requested max_size after mds reconnect")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
Notes:
This was found by a compiler-based check, part of research at UCSB SecLab.
The locking rule stated in the kernel-doc comment of the called function
was turned into a Clang context-analysis requirement (__must_hold) on that
function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every
caller. An LLM was used only to turn the comment into a machine-readable
rule; the report itself comes from the compiler. The patch and changelog
were drafted with Claude Opus 5.5. I reviewed the patch and take
responsibility for it.
Testing: builds without new warnings with W=1 (x86_64, clang 23,
allmodconfig). Not runtime-tested, and I have not observed the race
myself.
fs/ceph/mds_client.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 3791fc627714..61fc8bb826df 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -6005,8 +6005,8 @@ static void check_new_map(struct ceph_mds_client *mdsc,
mutex_lock(&mdsc->mutex);
ceph_put_mds_session(s);
ceph_kick_flushing_caps(mdsc, s);
- mutex_unlock(&s->s_mutex);
wake_up_session_caps(s, RECONNECT);
+ mutex_unlock(&s->s_mutex);
}
}
--
2.25.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-04 18:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 18:45 [PATCH] ceph: Hold s_mutex while waking up session caps in check_new_map() Praneeth Balasubramanian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox