Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795060122; b=h6mmYslFI+KX2dml1/+veFOX0Znie9w7WS2qeeLqh+ObKvtoFN2JqDYI/qvrIcciV1Hb Hh7gIoO8NDLrOObjT1LEJsZ7o71fS4Q0Pq23W2wXRs8uyBjbaX4oC/uBhxjquD+fT838C ukwwnxPPJadg6V7WQJ4RosR6QNkNJYwDR8IBD7rCr384hdiMbnTi9ixJ6SaKAJBYb+PSW PmhwK5WISG3xgur3JvZYGYdWLKPTH2orSl2nWvVtqAElnPqcweiv6s7ClcHpoA4KLQk1f 1tg63fS3dZcFT8B2eX0cUCF/uWncQ9QXkwqF/L8+LmwFZJ2oJ03VBhnYWUfVvZL1shw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795060122; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=UHDS9bFqgM4hoHvg0te/zbcbMjToV4WCg5g1pfcfAy8=; b=WM5uEqJ6JBnNvQl/WJrITTud/00rUAVMv5FeX9l+KXrT2xEfCqF2IXMTUwkTXZNKFI3R v2NRaTqCSq9GeveJ8HqikogQvuRHuwKY26pvpv91+++ZFcn+TJK1dy/RCNU/adTdAk9E6 Itnnc1p6N7OVbBel5+LtNnAQvGFZyIWvIvzSmZ4UNwugRFTYHamDThS9KNlZFu/dwjrLi oxOgXLJAi5R35CE9PqAGMAnOoTvF8PzlFIvktGracUAaekeG97Sn7Wzq4KF3CxZAVI9Dp lVFNEWsTjtzrhOkDFHW6CTvc1W8GNxcSrkQig+Fc/qLWpIRQH0IvadiEfq5CLA10k0Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Do5Ktj6A; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB264606A320; Thu, 19 Nov 2026 03:48:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Do5Ktj6A Received: by smtp.kernel.org (Postfix) with ESMTPSA id 121BF1F000C4; Thu, 19 Nov 2026 03:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795060122; bh=UHDS9bFqgM4hoHvg0te/zbcbMjToV4WCg5g1pfcfAy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Do5Ktj6AqjQnicMUODngmkMhOniWYOm+DotPmbXgDooFJEKOfqz5+QdLJZ8xcdtCI Vf/lzbBqRiCm0DiS2XqRCyEhpyBXxyAAUtshska2jb+GoNySGDwEB4ZTbyl2bzoTMD VwC7eDaD4LFm8V34MTaKM3pckddMb1Rvj2rk+D7E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Joseph Qi , Andrew Morton , Heming Zhao , Mark Fasheh , Joel Becker , Sasha Levin Subject: [PATCH 5.10 1086/1848] ocfs2: do not read the entry array of an empty xattr bucket Date: Wed, 18 Nov 2026 15:52:04 +0100 Message-ID: <20261118150004.068196565@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118145911.150052362@linuxfoundation.org> References: <20261118145911.150052362@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Joseph Qi [ Upstream commit e8de099f2958c84aa23186c5481e69f7ffd39355 ] ocfs2_check_xattr_bucket_collision() decides whether splitting a bucket can make room by comparing the hash being inserted against the first and the last entry. xh_count comes off disk and is never checked, and a bucket is allowed to hold no entries: ocfs2_xa_remove_entry() keeps the last slot when it removes the only one, so that an empty bucket still carries the hash it is keyed by. xh_count then reads back as 0 while xh_entries[0] is still meaningful, and the second comparison indexes xh_entries[-1]. That is outside the __counted_by_le(xh_count) bounds of xh_entries[] and lands on the header. An entry is 16 bytes and xe_name_hash is its first field, so the value read is xh_count | xh_free_start << 16. It stays inside the block, but the answer is arbitrary, and for an empty bucket it says there is no collision, so a new bucket gets added on the strength of it. An empty bucket holds no entries to collide with. Return before reading the array. One way to reach the test with an empty bucket is a set that removes the bucket's only entry during cleanup and then fails for space again, since it is that second -ENOSPC which calls this. Growing a value past OCFS2_XATTR_INLINE_SIZE is the easy route: the cluster allocation fails, the "!orig_clusters" arm of ocfs2_xa_cleanup_value_truncate() removes the entry, and although the "growing" caller does set ctxt->set_abort, only ocfs2_xattr_block_set() and __ocfs2_xattr_set_handle() look at it, so ocfs2_xattr_set_entry_index_block() goes straight on to the collision check. This sits on commit a9ea8b397864 ("ocfs2: use the stored hash when checking xattr bucket collision"), which gave the collision check its two argument form and is marked for 6.2 and later. The read fixed here is present in the three argument version too, but a tree without that commit needs the hunk adapted by hand. Link: https://lore.kernel.org/20261024151012.1059683-5-joseph.qi@linux.alibaba.com Fixes: 012255961c9e ("ocfs2: Enable xattr set in index btree") Signed-off-by: Joseph Qi Signed-off-by: Andrew Morton Cc: Heming Zhao Cc: Mark Fasheh Cc: Joel Becker Cc: Signed-off-by: Sasha Levin --- fs/ocfs2/xattr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 35fab516b86ff..52419b31b21af 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -5611,11 +5611,20 @@ static int ocfs2_check_xattr_bucket_collision(struct ocfs2_xattr_bucket *bucket, u32 name_hash) { struct ocfs2_xattr_header *xh = bucket_xh(bucket); + u16 count = le16_to_cpu(xh->xh_count); + + /* + * An empty bucket keeps the hash of the entry that was removed in + * xh_entries[0] so that it can still be found, but it holds no + * entries to collide with. + */ + if (!count) + return 0; if (name_hash != le32_to_cpu(xh->xh_entries[0].xe_name_hash)) return 0; - if (xh->xh_entries[le16_to_cpu(xh->xh_count) - 1].xe_name_hash == + if (xh->xh_entries[count - 1].xe_name_hash == xh->xh_entries[0].xe_name_hash) { mlog(ML_ERROR, "Too much hash collision in xattr bucket %llu, " "hash = %u\n", -- 2.53.0