[PATCH] ocfs2: validate quota file block count in ocfs2_local_read_info()

Dmitry Antipov <[email protected]> Thu, 25 Jun 2026 11:44:48 +0300
Newsgroups dev.linux.lists.ocfs2-devel
Message-ID <[email protected]>
In 'ocfs2_local_read_info()', assume that number of blocks allocated
for local quota file should not exceed the limit based on claimed
number of chunks, and refuse an attempt to enable quota otherwise.

Reported-by: Sam Sun <[email protected]>
Signed-off-by: Dmitry Antipov <[email protected]>
---
 fs/ocfs2/quota_local.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/ocfs2/quota_local.c b/fs/ocfs2/quota_local.c
index f55810c59b1b..33a9b5b449c8 100644
--- a/fs/ocfs2/quota_local.c
+++ b/fs/ocfs2/quota_local.c
@@ -733,6 +733,13 @@ static int ocfs2_local_read_info(struct super_block *sb, int type)
 	oinfo->dqi_blocks = le32_to_cpu(ldinfo->dqi_blocks);
 	oinfo->dqi_libh = bh;
 
+	if (oinfo->dqi_blocks > oinfo->dqi_chunks * ol_chunk_blocks(sb)) {
+		mlog(ML_ERROR, "unexpectedly large local quota "
+		     "file block count %u\n", oinfo->dqi_blocks);
+		status = -EFSCORRUPTED;
+		goto out_err;
+	}
+
 	/* We crashed when using local quota file? */
 	if (!(oinfo->dqi_flags & OLQF_CLEAN)) {
 		rec = OCFS2_SB(sb)->quota_rec;
-- 
2.54.0