]> git.baikalelectronics.ru Git - kernel.git/commit
f2fs: reposition unlock_new_inode to prevent accessing invalid inode
authorChao Yu <chao2.yu@samsung.com>
Sat, 30 Aug 2014 01:52:34 +0000 (09:52 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 2 Sep 2014 07:22:24 +0000 (00:22 -0700)
commit3b23840ed31218e7874fda366381241449ca9583
tree9f3d869cb4e7cb96b6992da333e9daec987ca86b
parenta06a9dcfc8d5216885caff1c0f4224b946d1086b
f2fs: reposition unlock_new_inode to prevent accessing invalid inode

As the race condition on the inode cache, following scenario can appear:
[Thread a] [Thread b]
->f2fs_mkdir
  ->f2fs_add_link
    ->__f2fs_add_link
      ->init_inode_metadata failed here
->gc_thread_func
  ->f2fs_gc
    ->do_garbage_collect
      ->gc_data_segment
        ->f2fs_iget
          ->iget_locked
            ->wait_on_inode
  ->unlock_new_inode
        ->move_data_page
  ->make_bad_inode
  ->iput

When we fail in create/symlink/mkdir/mknod/tmpfile, the new allocated inode
should be set as bad to avoid being accessed by other thread. But in above
scenario, it allows f2fs to access the invalid inode before this inode was set
as bad.
This patch fix the potential problem, and this issue was found by code review.

change log from v1:
 o Add condition judgment in gc_data_segment() suggested by Changman Lee.
 o use iget_failed to simplify code.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/gc.c
fs/f2fs/namei.c