f2fs: fix to avoid reading out encrypted data in page cache
authorChao Yu <yuchao0@huawei.com>
Sun, 3 Jul 2016 14:05:11 +0000 (22:05 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Fri, 8 Jul 2016 17:33:24 +0000 (10:33 -0700)
commit78682f79447998369a85f12b6437fa8fdbbdca50
treef318814714638beeda0dcb1ec7c8a3a6d8ea7a4b
parentac6f199984a667eb017897b8528f7687eac8fa45
f2fs: fix to avoid reading out encrypted data in page cache

For encrypted inode, if user overwrites data of the inode, f2fs will read
encrypted data into page cache, and then do the decryption.

However reader can race with overwriter, and it will see encrypted data
which has not been decrypted by overwriter yet. Fix it by moving decrypting
work to background and keep page non-uptodated until data is decrypted.

Thread A Thread B
- f2fs_file_write_iter
 - __generic_file_write_iter
  - generic_perform_write
   - f2fs_write_begin
    - f2fs_submit_page_bio
- generic_file_read_iter
 - do_generic_file_read
  - lock_page_killable
  - unlock_page
  - copy_page_to_iter
  hit the encrypted data in updated page
    - lock_page
    - fscrypt_decrypt_page

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