• Chao Yu's avatar
    f2fs: fix to avoid reading out encrypted data in page cache · 70c35785
    Chao Yu authored
    commit 78682f79 upstream.
    
    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: default avatarChao Yu <yuchao0@huawei.com>
    Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
    [bwh: Backported to 4.4:
     - Keep using f2fs_crypto functions instead of generic fscrypt API
     - Use PAGE_CACHE_SIZE instead of PAGE_SIZE
     - Use submit_bio() instead of __submit_bio()
     - In f2fs_write_begin(), use dn.data_blkaddr instead of blkaddr
     - Adjust context]
    Signed-off-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    70c35785
data.c 39.5 KB