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 04E0352B1ED for ; Wed, 9 Sep 2026 10:43:06 +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=1788950588; cv=none; b=Fl5wmNOVJKS5YLAG2eWiX10bTlmWXHPWnhoTi/952rq+NXHdRlRBevYT7qzHewmo2yCpe98Gv912CnxXXbO8daLNp+MTYxtLazSbC5/QOiNutBBZsvMwKrhTo2kCWVZZ8bgsjFCgdpW3Pod7lRGCYslSsZX9jqwpAPzqF8Utd8k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788950588; c=relaxed/simple; bh=de37tqjFOv7LLgm5s0Yu+UWX6vCe1X5zJEK07lA3fMk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=unWTBk+1OJB8zN1dQ89mhS+3AYWGotBflrb63USeEXXY3scys00zS2xfCJa664GR8THDW6oeseCCzecYpffTLX2jAF5AMjyUGvlGnibcWb1TaxGMaD2AaX+1Y0u5/rlZCizmv2AiiaEYL0B3HlxRZWEVXdyVMoFPrGDvYzzw+c0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ihsqo9Sp; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ihsqo9Sp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A20A1F00A3D; Wed, 9 Sep 2026 10:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788950586; bh=+LSHv1nkA4EVOa0TQC8Iv/1lEymUbWk7sFv3AfFo0Ak=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ihsqo9SpEfEKh4akZ+BbNTP6yxOnrP4B/RI6v8nXi64uRRx2Qm8knROGplMJ61jQb jtksyTBB3dx1gpPipgFDn5zwBrT0rcpM7VKmZOp3FIAO8hkV2bI0/HF1siNOxi2zxT IHTfzgN0wsY+lB8nhj6EWYHCDX0de2xw1fgE9BsZtFSjWExW2+3cjMv0GWJHetSuWn qXi1QrVT+RfbGCM04UarNQ+lfbDgqhFLRN79ydgd1Cq2eiJQmjTva0Eqk9SIPfDcb0 P9e27/26CXZpur6aqt2el3ShWbXYhgLnS7wE+kigWfu+ttLSdy1lehK6gDj2dOEUD2 rt1vRwpUylvlg== From: Sasha Levin To: stable@vger.kernel.org Cc: Joseph Qi , Heming Zhao , Mark Fasheh , Joel Becker , Junxiao Bi , Changwei Ge , Jun Piao , Andrew Morton , Sasha Levin Subject: [PATCH 6.1.y 1/2] ocfs2: validate dx_root extent list fields during block read Date: Wed, 9 Sep 2026 06:43:03 -0400 Message-ID: <20260909104304.1557880-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026090341-laundry-deceiving-d857@gregkh> References: <2026090341-laundry-deceiving-d857@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Joseph Qi [ Upstream commit 775c17386a6fd695f999d4cda90e3931386570dd ] Patch series "ocfs2: consolidate extent list validation into block read callbacks". ocfs2 validates extent list fields (l_count, l_next_free_rec) at various points during extent tree traversal. This is fragile because each caller must remember to check for corrupted on-disk data before using it. This series moves those checks into the block read validation callbacks (ocfs2_validate_dx_root and ocfs2_validate_extent_block), so corrupted fields are caught early at block read time. Redundant post-read checks are then removed. This patch (of 4): Move the extent list l_count validation from ocfs2_dx_dir_lookup_rec() into ocfs2_validate_dx_root(), so that corrupted on-disk fields are caught early at block read time rather than during directory lookups. Additionally, add a l_next_free_rec <= l_count check to prevent out-of-bounds access when iterating over extent records. Both checks are skipped for inline dx roots (OCFS2_DX_FLAG_INLINE), which use dr_entries instead of dr_list. Link: https://lkml.kernel.org/r/20260403090803.3860971-1-joseph.qi@linux.alibaba.com Link: https://lkml.kernel.org/r/20260403090803.3860971-2-joseph.qi@linux.alibaba.com Signed-off-by: Joseph Qi Reviewed-by: Heming Zhao Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Changwei Ge Cc: Jun Piao Signed-off-by: Andrew Morton Stable-dep-of: bc70726ddad5 ("ocfs2: validate directory-index entry counts when reading metadata") Signed-off-by: Sasha Levin --- fs/ocfs2/dir.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c index de6fd4a09ffd3..bf2a523a357b2 100644 --- a/fs/ocfs2/dir.c +++ b/fs/ocfs2/dir.c @@ -580,7 +580,7 @@ static int ocfs2_validate_dx_root(struct super_block *sb, mlog(ML_ERROR, "Checksum failed for dir index root block %llu\n", (unsigned long long)bh->b_blocknr); - return ret; + goto bail; } if (!OCFS2_IS_VALID_DX_ROOT(dx_root)) { @@ -588,8 +588,32 @@ static int ocfs2_validate_dx_root(struct super_block *sb, "Dir Index Root # %llu has bad signature %.*s\n", (unsigned long long)le64_to_cpu(dx_root->dr_blkno), 7, dx_root->dr_signature); + goto bail; + } + + if (!(dx_root->dr_flags & OCFS2_DX_FLAG_INLINE)) { + struct ocfs2_extent_list *el = &dx_root->dr_list; + + if (le16_to_cpu(el->l_count) != ocfs2_extent_recs_per_dx_root(sb)) { + ret = ocfs2_error(sb, + "Dir Index Root # %llu has invalid l_count %u (expected %u)\n", + (unsigned long long)le64_to_cpu(dx_root->dr_blkno), + le16_to_cpu(el->l_count), + ocfs2_extent_recs_per_dx_root(sb)); + goto bail; + } + + if (le16_to_cpu(el->l_next_free_rec) > le16_to_cpu(el->l_count)) { + ret = ocfs2_error(sb, + "Dir Index Root # %llu has invalid l_next_free_rec %u (l_count %u)\n", + (unsigned long long)le64_to_cpu(dx_root->dr_blkno), + le16_to_cpu(el->l_next_free_rec), + le16_to_cpu(el->l_count)); + goto bail; + } } +bail: return ret; } -- 2.53.0