From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796409906; b=pntk/T29dkwPNxK//p/O8bEZYobEchYqyk4XQS45jaOd/T0XNGvFBxBbmWwzfRcCr4bH Jb3ewpegffipOJc1iFLFNZI4pgFmUuDkYmSsd0RN1D0ZtJ9cEYUwKXSl7MsaaE9zQ9QTW Vk0BuvzejJu9Gher+8xKkr1Y+jUPjZ0k/HykPe/teifUEBCGmLWd+H977M7NZPkXgIzxD W9Vc0kWJ1YrTU+dASqvWKF+RyjqycLkTUnDgzB3B0c4dNcPIm1jdlK/9aZRL49aTyALnm xdNfvkZ7VQqVNeAMUXJebKm7P80roCH92G8toBjlPsFl21v3Z3akQgKZf69d1d1ubCA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796409906; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=mNY0wE2vZI0TadZI7eIMBdh1ThSUt9mr81cGRI03Z6Y=; b=Pw37g5uk6UyBdj1KBHx6hsNBC+RNOPImRhBII05xjUBI5AFvcZHuhLYLWU4DGSku4xpu ZwEbZGt8zvnV1oLDmZUzqHwqnOGiiOiN53QnVttWtRGhGDFgX9EosGXkEjQD+wGy0BdxM E9NEYJUQCiFUR83Cox1WD3EyeDLz9WiRI4Rs/FetJs18JIJZF1At5AQJ+BShZVM9cWeFX VMBSB2Hh8rU4v0mie1euTq5ka4QbLlcXGNpKnRU/Pig8JYiD+/dmjUcZ5ZQCaa7zhEXti dadHxzB2saJOqciF1jyTeGpsSNO0UpSjR4bAKHhNcJRsTn0caWaBwT0pdoHODTakvQw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Qv9wkzCw; arc=none smtp.remote-ip=74.125.82.180 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E9A2606A689 for ; Fri, 4 Dec 2026 18:45:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2E9A2606A689 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Qv9wkzCw Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-387609bc451so175716eec.1 for ; Fri, 04 Dec 2026 10:45:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796409905; x=1797014705; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=mNY0wE2vZI0TadZI7eIMBdh1ThSUt9mr81cGRI03Z6Y=; b=Qv9wkzCwqwbA4tV06udnEyy+t6kke4oO8/x+E/NlAMb6T3A9ES5as9Z4rUu6owb8vT uMah6GpFX2JyxoQ6MGtL8W3QOjjlG+ypV6QtaaTR3RFKxF/p+I/2ZPF4JHajzABQ0HV1 oGj+pFnpcybzU2TkXMulwk2+Zsz5FuJTrSQ/4CdBf7ffx0Nx6WPnXrCgRvwKofzxcwGO +NonhlBhISmmM1OzVLZ6zIPSo5QN/WstUnyIcAckr9ZO2Vfb6ybaQxUdCRpr7YE/8YxN zIK/dBDwSZEL/zXYz7nFOuYpN9P9sftOOmgQ9ikTOA4AnTc9FilzYohk6iEyK64AMd1h n31w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796409905; x=1797014705; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=mNY0wE2vZI0TadZI7eIMBdh1ThSUt9mr81cGRI03Z6Y=; b=VaJ7nd3bx5WW5St4Pabg/sF/46ouWr7HpKWckBr1E74L4zi2kz5pVv8P/2S45A3lAy c+XvxzBYU0uHIrOH4DGTyTDOdo6iCzQFnIoRqpHXBO2RvmN2kALXwYiGbyXARLmcYetC RcfzFeEsjIV4tYDzo68sPubQjWjfG86IgYngj5SFSS+gSHSAaYT9Y3ssK+mJ7iYov9NQ v1kKqOlc3s/ydMTcPKIW4wHF+/agLKrJf540QMyo/MO155vHa3bHW3ieIYVzLZ/cFyXS PEzCb+wMEhYh8e85M6V17IQ58PRbR87dAJj8Lyud2mS4exEvVstHjGUJHuyIM2vdpuTK Ydpw== X-Forwarded-Encrypted: i=1; AL+hErE35cNsf6RSjeFAXQ7RmJV6W8Jno3OugHx8zqrTCFfjAs7aQgjqj3q78ik76frobn/429kPlnj90oY+Lww=@vger.kernel.org X-Gm-Message-State: AB4q+uFh37elQb6iH0UeBX0TA/ZawXnqBRL9tqwb2iB6zyV7CyyRIsW6 qF0jx+P4NvONqbR793ncKFYm3DqH7lkq/Jxzc4CjljMQX/VtQbKyD6Yo X-Gm-Gg: AZFdTZfG7PRXx38H/b1vp+IScuiOj0UOKFbHZ5nvHs32v1Rx3PnJuXQ9UJLXBxf6aiO +6HtoXpvb4t2c3aGJ7HuTkFg07ynfa9fY7RE0+ousGB2s48K0d41qA+PQ0L2hF4UrpAsvaMKKUU lX5SKEqCTK/c8DRTg/j1oemG1QI7C9YZYMHunHGxQ7AY7boITX7foih6wFp1HSCmzWzL+bN6Ci4 NFC5cJyMJsKSbj6S0HDTMn76pswN6ie4tAU+zJFSGmXxYrC5T4v7raQW2vZkCDVAh8HYYxTfh5V z9gRtJ7oS2+Fbs9pBV5lKUxuQBtR0ST10Y4rg1g4RgiR10QlDrBW4BfOYWe+4yEekohHmuBrrza 2sv0ijpqxenWlxibV39sMf2+y0NeUFyyjbN5JzAR50DGY1QiGH1AwN2g1XKRfiRzDBzDX9QnKUv /yi7r1bLiadiFUaoORv+nYbrXqsZi+IVkwEq6No+7d8FQNFMKX7hi9aG7BFycyHAfD8fiHm2q8y HFYfgQKnSkgRjGlRH0TORcT3qZl/o1vA2bsJsOFMulmy6kn1MoV7QN7VoY06htYkyiJzMB7f6go ilvrqvSAcC5HXIiC2QAcSLCbeZrQ9YZ/nWABT9Y5ukli0HrM950rkWTWyLjigaZwwWE= X-Received: by 2002:a05:693c:80dc:b0:36a:2f6c:490e with SMTP id 5a478bee46e88-38742cf7f94mr5748957eec.6.1796409905071; Fri, 04 Dec 2026 10:45:05 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38751f0f658sm11201433eec.0.2026.12.04.10.45.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 10:45:04 -0800 (PST) From: Praneeth Balasubramanian To: Ilya Dryomov , Alex Markuze , Xiubo Li Cc: Viacheslav Dubeyko , Max Kellermann , ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Praneeth Balasubramanian , 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 Message-Id: <20261204184500.1685696-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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