Merge tag 'f2fs-for-5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk...
[muen/linux.git] / fs / f2fs / dir.c
index 713b36a..59bc460 100644 (file)
@@ -728,7 +728,7 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
                !f2fs_truncate_hole(dir, page->index, page->index + 1)) {
                f2fs_clear_page_cache_dirty_tag(page);
                clear_page_dirty_for_io(page);
-               ClearPagePrivate(page);
+               f2fs_clear_page_private(page);
                ClearPageUptodate(page);
                clear_cold_data(page);
                inode_dec_dirty_pages(dir);
@@ -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;
                }
 
@@ -810,7 +814,8 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
 
                /* check memory boundary before moving forward */
                bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
-               if (unlikely(bit_pos > d->max)) {
+               if (unlikely(bit_pos > d->max ||
+                               le16_to_cpu(de->name_len) > F2FS_NAME_LEN)) {
                        f2fs_msg(sbi->sb, KERN_WARNING,
                                "%s: corrupted namelen=%d, run fsck to fix.",
                                __func__, le16_to_cpu(de->name_len));
@@ -891,7 +896,7 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
                        page_cache_sync_readahead(inode->i_mapping, ra, file, n,
                                min(npages - n, (pgoff_t)MAX_DIR_RA_PAGES));
 
-               dentry_page = f2fs_get_lock_data_page(inode, n, false);
+               dentry_page = f2fs_find_data_page(inode, n);
                if (IS_ERR(dentry_page)) {
                        err = PTR_ERR(dentry_page);
                        if (err == -ENOENT) {
@@ -909,11 +914,11 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
                err = f2fs_fill_dentries(ctx, &d,
                                n * NR_DENTRY_IN_BLOCK, &fstr);
                if (err) {
-                       f2fs_put_page(dentry_page, 1);
+                       f2fs_put_page(dentry_page, 0);
                        break;
                }
 
-               f2fs_put_page(dentry_page, 1);
+               f2fs_put_page(dentry_page, 0);
        }
 out_free:
        fscrypt_fname_free_buffer(&fstr);