From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2415E335BBB; Fri, 4 Sep 2026 05:45:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788500721; cv=none; b=oToDZ5LrGyu453iK0XJoGnehFvpj7Rh1iUWx1EOQUghCiwXKGwKP4dD42x1HPnQSLOsfUoRv/KzF3kCKD5yaInto+jd3WvQkOSAGyRdpEgfZ5vrocaDMrLJfGkla6IiH2KeENOcA4zqaCSmX/YyZpP0EKsm/becreOOGyXGG4vg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788500721; c=relaxed/simple; bh=B61YOZAW9ShpGz8nTjO7IIKuhXDJzFgSxOaTlylbRKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VgLuDGnWS/ORnUqqRo6xhh4GuHrmcTVi45/ZzG68Wr9Y/vB5TwedwqdZ/ehHcHgS2UNRdi2SPTGTZ2RjiukfyRpx+5rQ/biva1d6UDqlppywbLo6GRKt+U7Q1GLU4p8+wYspZOs5NCB9/QNOfvvM3R3/Onxjt15TjpgfbhEO2Xs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=2YcVT+wP; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="2YcVT+wP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3568B1F00A3D; Fri, 4 Sep 2026 05:45:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788500719; bh=3vYWrFSgQs+rY2ifKeyskR2elbgYsn8HGip6N/8vXQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2YcVT+wPlO4/VllfNv7zwAK3jTfn2jTfAmiLZO0sGd0BWmoV0j07dhQ6hAqQ+3F+d i4gXvyBDd71Xfm0oBXI5zKh3UP8+T8nnVwqADDK2Gdc7i6FDu+i+NyemKr2o5xG8T/ 7qxAjqLcxIwSOy/wGOv61dreCkYAWuqFmIIdefXA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Xiubo Li , Viacheslav Dubeyko , Ilya Dryomov Subject: [PATCH 6.18 155/552] ceph: fix UAF in __kick_flushing_caps() on cf entry freed during unlock Date: Fri, 4 Sep 2026 06:55:12 +0200 Message-ID: <20260904045752.354881728@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904045747.813364717@linuxfoundation.org> References: <20260904045747.813364717@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Xiubo Li commit 7af4c4f01305b0935adf6d4301b1ec407025485d upstream. list_for_each_entry() iterates ci->i_cap_flush_list but drops i_ceph_lock to send cap messages. During the unlock window, handle_cap_flush_ack() can acquire i_ceph_lock, detach cf entries with tid <= flush_tid from the list, release i_ceph_lock, and free them via ceph_free_cap_flush() outside any lock. When the original thread reacquires i_ceph_lock and the for-loop macro advances via cf = list_next_entry(cf, i_list), it dereferences cf->i_list.next on freed memory. The race timeline: __kick_flushing_caps() handle_cap_flush_ack() ----------------------- ----------------------- holds i_ceph_lock <--- iterates to cf (tid=10) prepares FLUSH message drops i_ceph_lock <--- __send_cap() ── FLUSH(tid=10) MDS sends FLUSH_ACK(tid=10) ---> acquires i_ceph_lock cf->tid(10) <= flush_tid(10), detaches cf from i_cap_flush_list drops i_ceph_lock ceph_free_cap_flush(cf) <- frees it! acquires i_ceph_lock <--- for-loop advances: cf = list_next_entry(cf, i_list) -- UAF on freed cf->i_list.next The cf was just sent by __kick_flushing_caps itself via __send_cap(). The MDS may respond with FLUSH_ACK quickly enough that handle_cap_flush_ack() frees cf before __kick_flushing_caps can finish the iteration. Fix by converting to a manual while loop: save the next pointer under i_ceph_lock before dropping it, then use the saved pointer after reacquiring, so the potentially-freed cf is never accessed again. Cc: stable@vger.kernel.org Signed-off-by: Xiubo Li Reviewed-by: Viacheslav Dubeyko Signed-off-by: Ilya Dryomov Signed-off-by: Greg Kroah-Hartman --- fs/ceph/caps.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -2585,9 +2585,14 @@ static void __kick_flushing_caps(struct } } - list_for_each_entry(cf, &ci->i_cap_flush_list, i_list) { - if (cf->tid < first_tid) + cf = list_first_entry(&ci->i_cap_flush_list, struct ceph_cap_flush, i_list); + while (&cf->i_list != &ci->i_cap_flush_list) { + struct ceph_cap_flush *next; + + if (cf->tid < first_tid) { + cf = list_next_entry(cf, i_list); continue; + } cap = ci->i_auth_cap; if (!(cap && cap->session == session)) { @@ -2597,6 +2602,7 @@ static void __kick_flushing_caps(struct } first_tid = cf->tid + 1; + next = list_next_entry(cf, i_list); if (!cf->is_capsnap) { struct cap_msg_args arg; @@ -2637,6 +2643,7 @@ static void __kick_flushing_caps(struct } spin_lock(&ci->i_ceph_lock); + cf = next; } }