f2fs: avoid wrong decrypted data from disk MMI-QSAS30.62-24-26-7 MMI-QSAS30.62-24-7
authorJaegeuk Kim <jaegeuk@kernel.org>
Thu, 23 Aug 2018 04:18:00 +0000 (21:18 -0700)
committerchenyt9 <chenyt9@lenovo.com>
Fri, 12 Jun 2020 08:27:32 +0000 (16:27 +0800)
1. Create a file in an encrypted directory
2. Do GC & drop caches
3. Read stale data before its bio for metapage was not issued yet

Mot-CRs-fixed: (CR)

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Git-commit: 0ded69f632bb717be9aeea3ae74e29050fcb060c
Git-repo: https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git/
[stummala@codeaurora.org: Back port the change]
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
Signed-off-by: Jignesh Patel <jignesh@motorola.com>
Change-Id: I6ca2ad656efd230b20caa2240e681dbb9f145394
Reviewed-on: https://gerrit.mot.com/1526092
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Submit-Approved: Jira Key
(cherry picked from commit 150d0b46bfae48f1dc1f8c6cc7706a3fa2db5d09)

fs/f2fs/data.c
fs/f2fs/f2fs.h
fs/f2fs/file.c
fs/f2fs/segment.c

index 770de136e2d948e9fea61796387be3d04305a733..7cebab7389117b4344767445fc7aa178093e3962 100644 (file)
@@ -646,8 +646,6 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr,
                         REQ_NOENCRYPT :
                         0));
 
-               /* wait the page to be moved by cleaning */
-               f2fs_wait_on_block_writeback(sbi, blkaddr);
        }
 
        return bio;
@@ -662,6 +660,9 @@ static int f2fs_submit_page_read(struct inode *inode, struct page *page,
        if (IS_ERR(bio))
                return PTR_ERR(bio);
 
+       /* wait for GCed page writeback via META_MAPPING */
+       f2fs_wait_on_block_writeback(inode, blkaddr);
+
        if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
                bio_put(bio);
                return -EFAULT;
@@ -1632,6 +1633,12 @@ submit_and_realloc:
                                fscrypt_set_bio(inode, bio, dun);
                }
 
+               /*
+                * If the page is under writeback, we need to wait for
+                * its completion to see the correct decrypted data.
+                */
+               f2fs_wait_on_block_writeback(inode, block_nr);
+
                if (bio_add_page(bio, page, blocksize, 0) < blocksize)
                        goto submit_and_realloc;
 
@@ -1698,7 +1705,7 @@ static int encrypt_one_page(struct f2fs_io_info *fio)
                return 0;
 
        /* wait for GCed page writeback via META_MAPPING */
-       f2fs_wait_on_block_writeback(fio->sbi, fio->old_blkaddr);
+       f2fs_wait_on_block_writeback(inode, fio->old_blkaddr);
 
 retry_encrypt:
        if (fscrypt_disk_encrypted(inode))
@@ -2428,10 +2435,6 @@ repeat:
 
        f2fs_wait_on_page_writeback(page, DATA, false);
 
-       /* wait for GCed page writeback via META_MAPPING */
-       if (f2fs_post_read_required(inode))
-               f2fs_wait_on_block_writeback(sbi, blkaddr);
-
        if (len == PAGE_SIZE || PageUptodate(page))
                return 0;
 
index 2ee6d4bdcb0e5a9a47813ba336ca1b58af04e13c..5da0b3a40f84eaa237b360d981d00eff9bd5a749 100644 (file)
@@ -2840,7 +2840,7 @@ void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
                        struct f2fs_io_info *fio, bool add_list);
 void f2fs_wait_on_page_writeback(struct page *page,
                        enum page_type type, bool ordered);
-void f2fs_wait_on_block_writeback(struct f2fs_sb_info *sbi, block_t blkaddr);
+void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr);
 void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk);
 void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk);
 int lookup_journal_in_cursum(struct f2fs_journal *journal, int type,
index 23cbc5019f06f5e76d76895fc65bf6051ee62afe..4edd0d11f25fa920ac1cbd53204893cc0f844fe0 100644 (file)
@@ -111,8 +111,7 @@ mapped:
        f2fs_wait_on_page_writeback(page, DATA, false);
 
        /* wait for GCed page writeback via META_MAPPING */
-       if (f2fs_post_read_required(inode))
-               f2fs_wait_on_block_writeback(sbi, dn.data_blkaddr);
+       f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
 
 out_sem:
        up_read(&F2FS_I(inode)->i_mmap_sem);
index ae37019e88868dff86869df2747ce9872a49d60f..842c29e516d3ba180eb468563fbc9daa1cd2eebb 100644 (file)
@@ -2949,10 +2949,14 @@ void f2fs_wait_on_page_writeback(struct page *page,
        }
 }
 
-void f2fs_wait_on_block_writeback(struct f2fs_sb_info *sbi, block_t blkaddr)
+void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr)
 {
+       struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
        struct page *cpage;
 
+       if (!f2fs_post_read_required(inode))
+               return;
+
        if (!is_valid_data_blkaddr(sbi, blkaddr))
                return;