From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796409907; b=y28c4LccWWd90pyC2NDHWaCgBSOoG1HIsN134vakdMrzsUzdc7Ab3idif6yUqzSVNXzh uG1IaUl+PgkgKLXQ18TOL3hNoJl2VFOYsgVG0l44R65sEFPmK+Q4kGZMfSKPesEEq7bMU lH8NEoGjWV3T6SP58n8LJK2qOcaCho8wWS/H7Fb5ZLz82RXvkEgqr3URNDbLsQcXWFbYn uG5+yqv8nTZQ4ZBWxnx2arJi/u0OSHr9ZWIpZGMT2F3pVOa2peMgSgqITpuJBvRJkQWO/ CEzsAlaHWuY0tIZkRba8VajhQmLYdLhYwkE9Cc7u7b2iS+WvFNhsbAn3ZD76z8vrPUQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796409907; 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=Y2DCzgRuXtV/mmwh30SQWW4572nbxb3BObGJI3pNeK6oSPFc/MAZIWW0gc04pYKSkvN5 A98AGx5yHJZeng0DCsFhDpFQ7bAzc2m/GuxP60stfBOPCCgYJ2vPYqoLpqD/BsUtDqCOZ vmi8jeyz0OzJBItx8NCRNftA4M4NxbdNS95FupvL1QfUioHBZAZvK8ftF8Lzygu6SKOLB noRsBrFTeLYLSSR/j30Ob4BhqGxp8gIE1oB5SjRFIJuUYh4lkPFMquKYJPAd1caT9+oDB 68aDFqcyQIswouAbLbCFCrkG1+DkH9SrE0N1fi5PeS1g/DmiDC/BLiL8Zbbf+z+faKA== 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.169 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (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 3423C606A6AF for ; Fri, 4 Dec 2026 18:45:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3423C606A6AF 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-f169.google.com with SMTP id 5a478bee46e88-386d1859e1cso1236578eec.0 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=tzPm7cd8SJMQAhIeXPgQjb+0fQbfNF4M9HKmWT77YNNDSwTdk+9N1m8jEz6LG500od PACDCjc9XA+M5Q/pz1GehdLUtfsXaogA8l9H13qgXOv3VmMOBUD8XK6XlmF4vdoTbqLL /p6aZqYJlPDc8Ve4yYQmfRAebFonw+J2XGJKSvpB0yl7rzPTgwPwuib1KpKtNkSodBql puqIY/pSlIkI6a4wNgyDM3FjHVR6N2hTTYyqq4oaX2UaTV7QfNa62zGkN47Q5P+sxApI 70cY1t6qG+Sb2KnXyxKMcxrH6LRP5fcx/ov80WcNwt3bqOEZ+yxK23b2b4/jc52MVd8I zksQ== X-Forwarded-Encrypted: i=1; AL+hErH0/sA+61nUwC4wwFu/upW5bj3E6wHFO2tkOte8InyCdmkFlEKxsbUi6MiY5vr2VQ8erC3creo=@vger.kernel.org X-Gm-Message-State: AB4q+uEcn5WxCeqwXEpfQVx+kdHOG+UjxNJpRTRmtPYDiIYLxVSae4cK i5L4NDOLiTjfJA/faQKduzfVY5hAytCZQ+eGgXZ6RX+qQjKaSo7j5/GjrSqSTc+E X-Gm-Gg: AZFdTZc3eGDKgqYeSa+NSq6d8z23TdIaxdrRtdKc68dhb7DV2SkypAUJJDcIzX+LWJj fTj91wT8WLr6yh2cnsafaz35IusS/Wa6VPaPLZBoCK2Xx+d1zc8hHD17fTFpFyhoRp82J7c19Wv 6y9FRdEI9fsgkvkApsCDnY3HqiTLK3gLSX2f0td418prNhQGmMpox6VdIWnPMpsAJ2Hs2/no5ys 6pa4I6KSkRHvORPIZG3PxZrfczbeoU9bNmRIH0sSiob6CJecwPtvGenYMkCX+u7Vo9zoDx/O40L dEeUgWukom/fTGWLnteV0xiwV2UKK1LocJ4bYLm1ryy6htEeNF7lsBOZDQPfMqSZ7NCEoXuEImn uWHxpan2PsLC9/6k0w0wQ2xEhGRpavW4hYn4joH896cSZW2yUnUAMr97jYcIIkYRx0AQov4erLK GUpd3HRoM3Td8f72cwtBhO+rHaM0KFjF4IQ5ybAImvYdrxCnWg9yyic31/HxB9j/7NP6FmR26Sx fEn9zCLr7XlD+zUCMoFciOK+9cp1zVvYTExUNutkS7fO8eW33mKtO50sg34Jfn4EStW5PzhkMMs ofO5lXQWE/PdBCCay+XUSdj3M01G+DDLD/du4+a56MahsuKABj54BBDvJaWhu+NlG0A= 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: stable@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