fsck.f2fs: fix to do sanity check with inode.i_inline_xattr_size
authorChao Yu <yuchao0@huawei.com>
Mon, 4 Mar 2019 09:21:37 +0000 (17:21 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 27 Mar 2019 14:02:56 +0000 (07:02 -0700)
This patch adds to do sanity check with inode.i_inline_xattr_size,
and once it is corrupted, recover it to default value.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/fsck.c
fsck/xattr.h
include/f2fs_fs.h

index 7f14bac..a17555c 100644 (file)
@@ -9,6 +9,7 @@
  * published by the Free Software Foundation.
  */
 #include "fsck.h"
+#include "xattr.h"
 #include "quotaio.h"
 #include <time.h>
 
@@ -748,6 +749,24 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
                        node_blk->i.i_inline &= ~F2FS_EXTRA_ATTR;
                        need_fix = 1;
                }
+
+               if ((c.feature &
+                       cpu_to_le32(F2FS_FEATURE_FLEXIBLE_INLINE_XATTR)) &&
+                       (node_blk->i.i_inline & F2FS_INLINE_XATTR)) {
+                       unsigned int inline_size =
+                               le16_to_cpu(node_blk->i.i_inline_xattr_size);
+
+                       if (!inline_size ||
+                                       inline_size > MAX_INLINE_XATTR_SIZE) {
+                               FIX_MSG("ino[0x%x] recover inline xattr size "
+                                       "from %u to %u",
+                                       nid, inline_size,
+                                       DEFAULT_INLINE_XATTR_ADDRS);
+                               node_blk->i.i_inline_xattr_size =
+                                       cpu_to_le16(DEFAULT_INLINE_XATTR_ADDRS);
+                               need_fix = 1;
+                       }
+               }
        }
        ofs = get_extra_isize(node_blk);
 
index e4a98e2..dc80faf 100644 (file)
@@ -134,4 +134,9 @@ static inline int f2fs_acl_count(int size)
                sizeof(struct f2fs_xattr_header) -              \
                sizeof(struct f2fs_xattr_entry))
 
+#define MAX_INLINE_XATTR_SIZE                                          \
+                       (DEF_ADDRS_PER_INODE -                          \
+                       F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) -   \
+                       DEF_INLINE_RESERVED_SIZE -                      \
+                       MIN_INLINE_DENTRY_SIZE / sizeof(__le32))
 #endif
index 02b500e..e84cccc 100644 (file)
@@ -1071,6 +1071,7 @@ typedef __le32    f2fs_hash_t;
 #define SIZE_OF_RESERVED       (PAGE_SIZE - ((SIZE_OF_DIR_ENTRY + \
                                F2FS_SLOT_LEN) * \
                                NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP))
+#define MIN_INLINE_DENTRY_SIZE         40      /* just include '.' and '..' entries */
 
 /* One directory entry slot representing F2FS_SLOT_LEN-sized file name */
 struct f2fs_dir_entry {