kernel: backport fix for non-regular inodes on f2fs
[librecmc/librecmc.git] / target / linux / generic / backport-4.14 / 050-v4.19-f2fs-skip-verifying-block-address-non-regular-inode.patch
1 From dda9f4b9cac6bdd2a96253b4444d7a6ce5132edb Mon Sep 17 00:00:00 2001
2 From: Chao Yu <yuchao0@huawei.com>
3 Date: Sat, 11 Aug 2018 23:42:09 +0800
4 Subject: f2fs: fix to skip verifying block address for non-regular inode
5
6 generic/184 1s ... [failed, exit status 1]- output mismatch
7     --- tests/generic/184.out   2015-01-11 16:52:27.643681072 +0800
8      QA output created by 184 - silence is golden
9     +rm: cannot remove '/mnt/f2fs/null': Bad address
10     +mknod: '/mnt/f2fs/null': Bad address
11     +chmod: cannot access '/mnt/f2fs/null': Bad address
12     +./tests/generic/184: line 36: /mnt/f2fs/null: Bad address
13     ...
14
15 F2FS-fs (zram0): access invalid blkaddr:259
16 EIP: f2fs_is_valid_blkaddr+0x14b/0x1b0 [f2fs]
17  f2fs_iget+0x927/0x1010 [f2fs]
18  f2fs_lookup+0x26e/0x630 [f2fs]
19  __lookup_slow+0xb3/0x140
20  lookup_slow+0x31/0x50
21  walk_component+0x185/0x1f0
22  path_lookupat+0x51/0x190
23  filename_lookup+0x7f/0x140
24  user_path_at_empty+0x36/0x40
25  vfs_statx+0x61/0xc0
26  __do_sys_stat64+0x29/0x40
27  sys_stat64+0x13/0x20
28  do_fast_syscall_32+0xaa/0x22c
29  entry_SYSENTER_32+0x53/0x86
30
31 In f2fs_iget(), we will check inode's first block address, if it is valid,
32 we will set FI_FIRST_BLOCK_WRITTEN flag in inode.
33
34 But we should only do this for regular inode, otherwise, like special
35 inode, i_addr[0] is used for storing device info instead of block address,
36 it will fail checking flow obviously.
37
38 So for non-regular inode, let's skip verifying address and setting flag.
39
40 Signed-off-by: Chao Yu <yuchao0@huawei.com>
41 Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
42 ---
43  fs/f2fs/inode.c | 14 ++++++++------
44  1 file changed, 8 insertions(+), 6 deletions(-)
45
46 --- a/fs/f2fs/inode.c
47 +++ b/fs/f2fs/inode.c
48 @@ -310,13 +310,15 @@ static int do_read_inode(struct inode *i
49         /* get rdev by using inline_info */
50         __get_inode_rdev(inode, ri);
51  
52 -       err = __written_first_block(sbi, ri);
53 -       if (err < 0) {
54 -               f2fs_put_page(node_page, 1);
55 -               return err;
56 +       if (S_ISREG(inode->i_mode)) {
57 +               err = __written_first_block(sbi, ri);
58 +               if (err < 0) {
59 +                       f2fs_put_page(node_page, 1);
60 +                       return err;
61 +               }
62 +               if (!err)
63 +                       set_inode_flag(inode, FI_FIRST_BLOCK_WRITTEN);
64         }
65 -       if (!err)
66 -               set_inode_flag(inode, FI_FIRST_BLOCK_WRITTEN);
67  
68         if (!need_inode_block_update(sbi, inode->i_ino))
69                 fi->last_disk_size = inode->i_size;