From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.98 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792854626; b=NFUJW7yC8r1/sKnqIy9t8d+1j1LDRMwtjORYPyc+Vh/Nk25D+N9OoueV0TZG6pr9SPSY J+nHEpFzV90BpP3SGaj8T/KlWGEdEcCZwya0ebt4z789JDFb88P9/ooQErKvY8PwuKjO8 kgglBmJL56Hz4cASzaxhMxeFTip79uSFIZ2HRLpDyIHSAPQf4FT6tKeUTzIpWch4I7cOA sM2YAbPlgvcXUF+kiUnioaErtNKg9wTd8jPI6KSw8Bp/39YOfPNNviyCWFHIc+rY1Zz6o 9k/l7DflvVVP+CaFUQgPoXtb7TDJDUphpIoh/Y1Jso88Asm0x2xBXRX6j4z7YzDaOVQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792854626; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc: Subject:Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=ZDlcAeojPWg25zmpljtugJi6kVq+0n3tsOpMW2HWI1o=; b=NF3HHwpjrlxnWNXjVIQFBWv/gWm+2w+tjjCfIWXWLzBbNblMztTzJwoWAPhttSHGBDZt 5Q9XGe2OawaM7pIwXhSOkEqOYht8D7xyHNjGnv5fcs5YANdYrVI6v17GuPwsbND6Ak7oy 4As2L2/NdaCPQb1zmPHno8/WHO9HbXwmC6sLWzJVhM3ak+0Z7zgxrHn/8zhSOe/vJDePm 2/tiTEAzLJhe8i65pshNwQIIC5tAcK1BPbItvkVLC493xVzdvqvZfrm5KxAi78oAUoieh XZ1frH7pZl/u79jQyVeDPR1XPHLcs3n0zEEc7t6LuJsUmATyVS8p1g6NDVJJuBJaLfw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=qGBBI1+i; arc=none smtp.remote-ip=115.124.30.98 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CED6606A329 for ; Sat, 24 Oct 2026 15:10:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4CED6606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=qGBBI1+i DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1792854617; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=ZDlcAeojPWg25zmpljtugJi6kVq+0n3tsOpMW2HWI1o=; b=qGBBI1+iZ9rJ7D0XeJmeyrbrs1jVTR1ZwYaBXMd8qk/F8LE30eCJD7IWpf/OlYo9q6P3xOu+15WxKawmuac/OreBGUGAkytr38p4q/9PQ05MApjg6NNbXMhEmwHsbIHg58yDeTKsWLN6v/T/zYtBPJ3Kbu3Eqm3P3ttWMiSipjA= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R671e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033032089153;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0XDONeQd_1792854615; Received: from localhost(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0XDONeQd_1792854615 cluster:ay36) by smtp.aliyun-inc.com; Sat, 24 Oct 2026 23:10:16 +0800 From: Joseph Qi To: Andrew Morton , Heming Zhao Cc: Mark Fasheh , Joel Becker , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 4/6] ocfs2: do not read the entry array of an empty xattr bucket Date: Sat, 24 Oct 2026 23:10:10 +0800 Message-Id: <20261024151012.1059683-5-joseph.qi@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20261024151012.1059683-1-joseph.qi@linux.alibaba.com> References: <20261024151012.1059683-1-joseph.qi@linux.alibaba.com> 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 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. Fixes: 012255961c9e ("ocfs2: Enable xattr set in index btree") Cc: Signed-off-by: Joseph Qi --- 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 2c069029cef7..3a16b4a36d9a 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -6061,11 +6061,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.39.3