From: Zhang Yi <yi.zhang@huawei.com>
To: <linux-fsdevel@vger.kernel.org>
Cc: <jack@suse.cz>, <yi.zhang@huawei.com>, <yukuai3@huawei.com>
Subject: [PATCH 1/2] quota: check block number when reading the block in quota file
Date: Fri, 8 Oct 2021 17:38:20 +0800 [thread overview]
Message-ID: <20211008093821.1001186-2-yi.zhang@huawei.com> (raw)
In-Reply-To: <20211008093821.1001186-1-yi.zhang@huawei.com>
The block number in the quota tree on disk should smaller than the
v2_disk_dqinfo.dqi_blocks. If the quota file was corrupted, we may
allocating an 'allocated' block and lead to the tree infinite loop,
which may probably trigger oops later. This patch add a check for
getting block number in the quota tree to prevent such potential issue.
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Cc: stable@kernel.org
---
fs/quota/quota_tree.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/fs/quota/quota_tree.c b/fs/quota/quota_tree.c
index d3e995e1046f..583b7f7715f9 100644
--- a/fs/quota/quota_tree.c
+++ b/fs/quota/quota_tree.c
@@ -479,6 +479,13 @@ static int remove_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot,
goto out_buf;
}
newblk = le32_to_cpu(ref[get_index(info, dquot->dq_id, depth)]);
+ if (newblk < QT_TREEOFF || newblk >= info->dqi_blocks) {
+ quota_error(dquot->dq_sb, "Getting block too big (%u >= %u)",
+ newblk, info->dqi_blocks);
+ ret = -EUCLEAN;
+ goto out_buf;
+ }
+
if (depth == info->dqi_qtree_depth - 1) {
ret = free_dqentry(info, dquot, newblk);
newblk = 0;
@@ -578,6 +585,13 @@ static loff_t find_tree_dqentry(struct qtree_mem_dqinfo *info,
blk = le32_to_cpu(ref[get_index(info, dquot->dq_id, depth)]);
if (!blk) /* No reference? */
goto out_buf;
+ if (blk < QT_TREEOFF || blk >= info->dqi_blocks) {
+ quota_error(dquot->dq_sb, "Getting block too big (%u >= %u)",
+ blk, info->dqi_blocks);
+ ret = -EUCLEAN;
+ goto out_buf;
+ }
+
if (depth < info->dqi_qtree_depth - 1)
ret = find_tree_dqentry(info, dquot, blk, depth+1);
else
--
2.31.1
next prev parent reply other threads:[~2021-10-08 9:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-08 9:38 [PATCH 0/2] quota: fix oops when loading corrupted quota file Zhang Yi
2021-10-08 9:38 ` Zhang Yi [this message]
2021-10-08 9:38 ` [PATCH 2/2] qupta: correct error number in free_dqentry() Zhang Yi
2021-10-11 8:58 ` [PATCH 0/2] quota: fix oops when loading corrupted quota file Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211008093821.1001186-2-yi.zhang@huawei.com \
--to=yi.zhang@huawei.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=yukuai3@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).