]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
f2fs: fix to do sanity check on nat entry of quota inode
authorChao Yu <chao@kernel.org>
Fri, 19 Dec 2025 02:51:04 +0000 (10:51 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Thu, 1 Jan 2026 03:26:56 +0000 (03:26 +0000)
As Zhiguo reported, nat entry of quota inode could be corrupted:

"ino/block_addr=NULL_ADDR in nid=4 entry"

We'd better to do sanity check on quota inode to detect and record
nat.blk_addr inconsistency, so that we can have a chance to repair
it w/ later fsck.

Reported-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
Signed-off-by: Chao Yu <chao@kernel.org>
Reviewed-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/f2fs.h
fs/f2fs/inode.c
fs/f2fs/node.c

index 53cbce96f1266e6324cddc672945394ace11b111..291a694fdaf070b59fc3862bd296b40f33f02b07 100644 (file)
@@ -4917,16 +4917,16 @@ static inline bool is_journalled_quota(struct f2fs_sb_info *sbi)
        return false;
 }
 
-static inline bool f2fs_quota_file(struct inode *inode)
+static inline bool f2fs_quota_file(struct f2fs_sb_info *sbi, nid_t ino)
 {
 #ifdef CONFIG_QUOTA
        int i;
 
-       if (!f2fs_sb_has_quota_ino(F2FS_I_SB(inode)))
+       if (!f2fs_sb_has_quota_ino(sbi))
                return false;
 
        for (i = 0; i < MAXQUOTAS; i++) {
-               if (f2fs_qf_ino(F2FS_I_SB(inode)->sb, i) == inode->i_ino)
+               if (f2fs_qf_ino(sbi->sb, i) == ino)
                        return true;
        }
 #endif
index 921fb02c0f494bb081b34706726957c3e526abb9..d1270b25ad7d7c030f1870e7d161f97073fd0fdb 100644 (file)
@@ -621,7 +621,7 @@ make_now:
                inode->i_fop = &f2fs_file_operations;
                inode->i_mapping->a_ops = &f2fs_dblock_aops;
                if (IS_IMMUTABLE(inode) && !f2fs_compressed_file(inode) &&
-                   !f2fs_quota_file(inode))
+                   !f2fs_quota_file(sbi, inode->i_ino))
                        mapping_set_folio_min_order(inode->i_mapping, 0);
        } else if (S_ISDIR(inode->i_mode)) {
                inode->i_op = &f2fs_dir_inode_operations;
index 482a362f262543948c5baea5bd80a1cdd2c7f3aa..3a80da524739667fda5799476753191a8a90d5b6 100644 (file)
@@ -643,6 +643,17 @@ sanity_check:
                return -EFSCORRUPTED;
        }
 
+       if (unlikely(f2fs_quota_file(sbi, ni->nid) &&
+               !__is_valid_data_blkaddr(ni->blk_addr))) {
+               set_sbi_flag(sbi, SBI_NEED_FSCK);
+               f2fs_err_ratelimited(sbi,
+                       "f2fs_get_node_info of %pS: inconsistent nat entry from qf_ino, "
+                       "ino:%u, nid:%u, blkaddr:%u, ver:%u, flag:%u",
+                       __builtin_return_address(0),
+                       ni->ino, ni->nid, ni->blk_addr, ni->version, ni->flag);
+               f2fs_handle_error(sbi, ERROR_INCONSISTENT_NAT);
+       }
+
        /* cache nat entry */
        if (need_cache)
                cache_nat_entry(sbi, nid, &ne);