Skip to content

Commit 191249f

Browse files
Zhihao Chengjankara
authored andcommitted
quota: Add more checking after reading from quota file
It would be better to do more sanity checking (eg. dqdh_entries, block no.) for the content read from quota file, which can prevent corrupting the quota file. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Zhihao Cheng <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 3fc61e0 commit 191249f

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

fs/quota/quota_tree.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ static int check_dquot_block_header(struct qtree_mem_dqinfo *info,
9696
err = do_check_range(info->dqi_sb, "dqdh_prev_free",
9797
le32_to_cpu(dh->dqdh_prev_free), 0,
9898
info->dqi_blocks - 1);
99+
if (err)
100+
return err;
101+
err = do_check_range(info->dqi_sb, "dqdh_entries",
102+
le16_to_cpu(dh->dqdh_entries), 0,
103+
qtree_dqstr_in_blk(info));
99104

100105
return err;
101106
}
@@ -348,6 +353,10 @@ static int do_insert_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot,
348353
}
349354
ref = (__le32 *)buf;
350355
newblk = le32_to_cpu(ref[get_index(info, dquot->dq_id, depth)]);
356+
ret = do_check_range(dquot->dq_sb, "block", newblk, 0,
357+
info->dqi_blocks - 1);
358+
if (ret)
359+
goto out_buf;
351360
if (!newblk)
352361
newson = 1;
353362
if (depth == info->dqi_qtree_depth - 1) {
@@ -739,15 +748,21 @@ static int find_next_id(struct qtree_mem_dqinfo *info, qid_t *id,
739748
goto out_buf;
740749
}
741750
for (i = __get_index(info, *id, depth); i < epb; i++) {
742-
if (ref[i] == cpu_to_le32(0)) {
751+
uint blk_no = le32_to_cpu(ref[i]);
752+
753+
if (blk_no == 0) {
743754
*id += level_inc;
744755
continue;
745756
}
757+
ret = do_check_range(info->dqi_sb, "block", blk_no, 0,
758+
info->dqi_blocks - 1);
759+
if (ret)
760+
goto out_buf;
746761
if (depth == info->dqi_qtree_depth - 1) {
747762
ret = 0;
748763
goto out_buf;
749764
}
750-
ret = find_next_id(info, id, le32_to_cpu(ref[i]), depth + 1);
765+
ret = find_next_id(info, id, blk_no, depth + 1);
751766
if (ret != -ENOENT)
752767
break;
753768
}

0 commit comments

Comments
 (0)