]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
f2fs: fix to do sanity check on blocks for inline_data inode
authorChao Yu <chao@kernel.org>
Tue, 21 May 2024 06:23:18 +0000 (14:23 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 12 Jun 2024 15:46:02 +0000 (15:46 +0000)
inode can be fuzzed, so it can has F2FS_INLINE_DATA flag and valid
i_blocks/i_nid value, this patch supports to do extra sanity check
to detect such corrupted state.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/f2fs.h
fs/f2fs/inline.c
fs/f2fs/inode.c

index 1974b6aff397cca4560d7be3a092fe90ec7ce70a..f463961b497c42e1c55567b0002bdc8d32fc9195 100644 (file)
@@ -4149,7 +4149,7 @@ extern struct kmem_cache *f2fs_inode_entry_slab;
  * inline.c
  */
 bool f2fs_may_inline_data(struct inode *inode);
-bool f2fs_sanity_check_inline_data(struct inode *inode);
+bool f2fs_sanity_check_inline_data(struct inode *inode, struct page *ipage);
 bool f2fs_may_inline_dentry(struct inode *inode);
 void f2fs_do_read_inline_data(struct folio *folio, struct page *ipage);
 void f2fs_truncate_inline_inode(struct inode *inode,
index 7638d0d7b7eed9e969c889115c4344c71cf1548c..0203c3baabb66ea0ce57cabf8e9213fb18c3597e 100644 (file)
@@ -33,11 +33,29 @@ bool f2fs_may_inline_data(struct inode *inode)
        return !f2fs_post_read_required(inode);
 }
 
-bool f2fs_sanity_check_inline_data(struct inode *inode)
+static bool inode_has_blocks(struct inode *inode, struct page *ipage)
+{
+       struct f2fs_inode *ri = F2FS_INODE(ipage);
+       int i;
+
+       if (F2FS_HAS_BLOCKS(inode))
+               return true;
+
+       for (i = 0; i < DEF_NIDS_PER_INODE; i++) {
+               if (ri->i_nid[i])
+                       return true;
+       }
+       return false;
+}
+
+bool f2fs_sanity_check_inline_data(struct inode *inode, struct page *ipage)
 {
        if (!f2fs_has_inline_data(inode))
                return false;
 
+       if (inode_has_blocks(inode, ipage))
+               return false;
+
        if (!support_inline_data(inode))
                return true;
 
index 005dde72aff3d749e171f91e3d1e9d7ff70133b2..33b2778d5452500345166fdb39733e985827a82d 100644 (file)
@@ -344,7 +344,7 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page)
                }
        }
 
-       if (f2fs_sanity_check_inline_data(inode)) {
+       if (f2fs_sanity_check_inline_data(inode, node_page)) {
                f2fs_warn(sbi, "%s: inode (ino=%lx, mode=%u) should not have inline_data, run fsck to fix",
                          __func__, inode->i_ino, inode->i_mode);
                return false;