Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Ilya Dryomov <idryomov@gmail.com>,
	Alex Markuze <amarkuze@redhat.com>, Xiubo Li <xiubo.li@clyso.com>
Cc: Viacheslav Dubeyko <slava@dubeyko.com>,
	Max Kellermann <max.kellermann@ionos.com>,
	ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Praneeth Balasubramanian <praneethb2002@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] ceph: Hold s_mutex while waking up session caps in check_new_map()
Date: Fri,  4 Dec 2026 10:45:00 -0800	[thread overview]
Message-ID: <20261204184500.1685696-1-praneethb2002@gmail.com> (raw)

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


                 reply	other threads:[~2026-12-04 18:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204184500.1685696-1-praneethb2002@gmail.com \
    --to=praneethb2002@gmail.com \
    --cc=amarkuze@redhat.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=idryomov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=max.kellermann@ionos.com \
    --cc=slava@dubeyko.com \
    --cc=stable@vger.kernel.org \
    --cc=xiubo.li@clyso.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox