]> git.karo-electronics.de Git - linux-beck.git/commitdiff
f2fs: fix race conditon on truncation with inline_data
authorJaegeuk Kim <jaegeuk@kernel.org>
Wed, 15 Oct 2014 17:24:34 +0000 (10:24 -0700)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 4 Nov 2014 00:07:29 +0000 (16:07 -0800)
Let's consider the following scenario.

blkaddr[0] inline_data i_size  i_blocks writepage           truncate
  NEW        X        4096        2    dirty page #0
  NEW        X         0                                    change i_size
  NEW        X         0          2    f2fs_write_inline_data
  NEW        X         0          2    get_dnode_of_data
  NEW        X         0          2    truncate_data_blocks_range
  NULL       O         0          1    memcpy(inline_data)
  NULL       O         0          1    f2fs_put_dnode
  NULL       O         0          1                         f2fs_truncate
  NULL       O         0          1                         get_dnode_of_data
  NULL       O         0          1                       *invalid block addr*

This patch adds checking inline_data flag during f2fs_truncate not to refer
corrupted block indices.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/file.c

index 8e68bb64f83598360ffa8fdb31010aa1c33248f5..543d8c6303450ed23a671ab2771a452d7d54af72 100644 (file)
@@ -473,6 +473,12 @@ int truncate_blocks(struct inode *inode, u64 from, bool lock)
                return err;
        }
 
+       /* writepage can convert inline_data under get_donde_of_data */
+       if (f2fs_has_inline_data(inode)) {
+               f2fs_put_dnode(&dn);
+               goto done;
+       }
+
        count = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode));
 
        count -= dn.ofs_in_node;