Skip to content

Commit 9bf3d20

Browse files
zhangyi089jankara
authored andcommitted
quota: check block number when reading the block in quota file
The block number in the quota tree on disk should be smaller than the v2_disk_dqinfo.dqi_blocks. If the quota file was corrupted, we may be allocating an 'allocated' block and that would lead to a loop in a tree, which will probably trigger oops later. This patch adds a check for the block number in the quota tree to prevent such potential issue. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Zhang Yi <[email protected]> Cc: [email protected] Signed-off-by: Jan Kara <[email protected]>
1 parent 64570fb commit 9bf3d20

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

fs/quota/quota_tree.c

+14
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,13 @@ static int remove_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot,
479479
goto out_buf;
480480
}
481481
newblk = le32_to_cpu(ref[get_index(info, dquot->dq_id, depth)]);
482+
if (newblk < QT_TREEOFF || newblk >= info->dqi_blocks) {
483+
quota_error(dquot->dq_sb, "Getting block too big (%u >= %u)",
484+
newblk, info->dqi_blocks);
485+
ret = -EUCLEAN;
486+
goto out_buf;
487+
}
488+
482489
if (depth == info->dqi_qtree_depth - 1) {
483490
ret = free_dqentry(info, dquot, newblk);
484491
newblk = 0;
@@ -578,6 +585,13 @@ static loff_t find_tree_dqentry(struct qtree_mem_dqinfo *info,
578585
blk = le32_to_cpu(ref[get_index(info, dquot->dq_id, depth)]);
579586
if (!blk) /* No reference? */
580587
goto out_buf;
588+
if (blk < QT_TREEOFF || blk >= info->dqi_blocks) {
589+
quota_error(dquot->dq_sb, "Getting block too big (%u >= %u)",
590+
blk, info->dqi_blocks);
591+
ret = -EUCLEAN;
592+
goto out_buf;
593+
}
594+
581595
if (depth < info->dqi_qtree_depth - 1)
582596
ret = find_tree_dqentry(info, dquot, blk, depth+1);
583597
else

0 commit comments

Comments
 (0)