From: Yangtao Li <frank.li@vivo.com>
To: jaegeuk@kernel.org, chao@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, Yangtao Li <frank.li@vivo.com>
Subject: [PATCH] f2fs: fix to check quota inums
Date: Thu, 23 Feb 2023 15:32:22 +0800 [thread overview]
Message-ID: <20230223073222.81702-1-frank.li@vivo.com> (raw)
We should check quota file ino before enable quota, and not only 0.
BTW fix following check error:
WARNING: Do not crash the kernel unless it is absolutely
unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible)
instead of BUG() or variants.
Fixes: ea6767337f86 ("f2fs: support quota sys files")
Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
fs/f2fs/super.c | 54 ++++++++++++++++++++++++++++++++-----------------
1 file changed, 36 insertions(+), 18 deletions(-)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index aa55dc12aff2..c7e0639892e2 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -2652,22 +2652,40 @@ int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
return enabled;
}
+static inline bool f2fs_check_quota_inum(int type, unsigned long qf_inum)
+{
+ switch (type) {
+ case USRQUOTA:
+ return qf_inum == 4;
+ case GRPQUOTA:
+ return qf_inum == 5;
+ case PRJQUOTA:
+ return qf_inum == 6;
+ default:
+ return false;
+ }
+}
+
static int f2fs_quota_enable(struct super_block *sb, int type, int format_id,
unsigned int flags)
{
+ struct f2fs_sb_info *sbi = F2FS_SB(sb);
struct inode *qf_inode;
unsigned long qf_inum;
int err;
- BUG_ON(!f2fs_sb_has_quota_ino(F2FS_SB(sb)));
+ f2fs_bug_on(sbi, !f2fs_sb_has_quota_ino(sbi));
qf_inum = f2fs_qf_ino(sb, type);
- if (!qf_inum)
- return -EPERM;
+ if (!f2fs_check_quota_inum(type, qf_inum)) {
+ f2fs_err(sbi, "Bad quota inum: %lu, type: %d",
+ qf_inum, type);
+ return -EFSCORRUPTED;
+ }
qf_inode = f2fs_iget(sb, qf_inum);
if (IS_ERR(qf_inode)) {
- f2fs_err(F2FS_SB(sb), "Bad quota inode %u:%lu", type, qf_inum);
+ f2fs_err(sbi, "Bad quota inode %u:%lu", type, qf_inum);
return PTR_ERR(qf_inode);
}
@@ -2682,7 +2700,7 @@ static int f2fs_enable_quotas(struct super_block *sb)
{
struct f2fs_sb_info *sbi = F2FS_SB(sb);
int type, err = 0;
- unsigned long qf_inum;
+ char count = MAXQUOTAS;
bool quota_mopt[MAXQUOTAS] = {
test_opt(sbi, USRQUOTA),
test_opt(sbi, GRPQUOTA),
@@ -2696,21 +2714,21 @@ static int f2fs_enable_quotas(struct super_block *sb)
sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE;
- for (type = 0; type < MAXQUOTAS; type++) {
- qf_inum = f2fs_qf_ino(sb, type);
- if (qf_inum) {
- err = f2fs_quota_enable(sb, type, QFMT_VFS_V1,
+ if (!f2fs_sb_has_project_quota(sbi))
+ count--;
+
+ for (type = 0; type < count; type++) {
+ err = f2fs_quota_enable(sb, type, QFMT_VFS_V1,
DQUOT_USAGE_ENABLED |
(quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0));
- if (err) {
- f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.",
- type, err);
- for (type--; type >= 0; type--)
- dquot_quota_off(sb, type);
- set_sbi_flag(F2FS_SB(sb),
- SBI_QUOTA_NEED_REPAIR);
- return err;
- }
+ if (err) {
+ f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.",
+ type, err);
+ for (type--; type >= 0; type--)
+ dquot_quota_off(sb, type);
+ set_sbi_flag(F2FS_SB(sb),
+ SBI_QUOTA_NEED_REPAIR);
+ return err;
}
}
return 0;
--
2.25.1
next reply other threads:[~2023-02-23 7:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-23 7:32 Yangtao Li [this message]
2023-03-06 20:59 ` Jaegeuk Kim
2023-04-02 3:16 ` Chao Yu
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=20230223073222.81702-1-frank.li@vivo.com \
--to=frank.li@vivo.com \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®