f2fs: fix to trigger fsck if dirent.name_len is zero
authorChao Yu <yuchao0@huawei.com>
Tue, 8 Jan 2019 02:21:24 +0000 (10:21 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 22 Jan 2019 23:31:25 +0000 (15:31 -0800)
While traversing dirents in f2fs_fill_dentries(), if bitmap is valid,
filename length should not be zero, otherwise, directory structure
consistency could be corrupted, in this case, let's print related
info and set SBI_NEED_FSCK to trigger fsck for repairing.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/dir.c

index 50d0d36280fac5e92094743c1a868bad55a25bda..926166528cd43a690e1feed056f53c15a4a5174f 100644 (file)
@@ -800,6 +800,10 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
                if (de->name_len == 0) {
                        bit_pos++;
                        ctx->pos = start_pos + bit_pos;
+                       printk_ratelimited(
+                               "%s, invalid namelen(0), ino:%u, run fsck to fix.",
+                               KERN_WARNING, le32_to_cpu(de->ino));
+                       set_sbi_flag(sbi, SBI_NEED_FSCK);
                        continue;
                }