From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Jaegeuk Kim <jaegeuk@kernel.org>,
linux-f2fs-devel@lists.sourceforge.net,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 4.20 085/304] f2fs: avoid GC causing encrypted file corrupted
Date: Mon, 28 Jan 2019 10:40:02 -0500 [thread overview]
Message-ID: <20190128154341.47195-85-sashal@kernel.org> (raw)
In-Reply-To: <20190128154341.47195-1-sashal@kernel.org>
From: Yunlong Song <yunlong.song@huawei.com>
[ Upstream commit 9bf1a3f73927492c8be127b642197125e9d52be8 ]
The encrypted file may be corrupted by GC in following case:
Time 1: | segment 1 blkaddr = A | GC -> | segment 2 blkaddr = B |
Encrypted block 1 is moved from blkaddr A of segment 1 to blkaddr B of
segment 2,
Time 2: | segment 1 blkaddr = B | GC -> | segment 3 blkaddr = C |
Before page 1 is written back and if segment 2 become a victim, then
page 1 is moved from blkaddr B of segment 2 to blkaddr Cof segment 3,
during the GC process of Time 2, f2fs should wait for page 1 written back
before reading it, or move_data_block will read a garbage block from
blkaddr B since page is not written back to blkaddr B yet.
Commit 6aa58d8a ("f2fs: readahead encrypted block during GC") introduce
ra_data_block to read encrypted block, but it forgets to add
f2fs_wait_on_page_writeback to avoid racing between GC and flush.
Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/f2fs/gc.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index a07241fb8537..c96e7c6354ef 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -658,6 +658,14 @@ got_it:
fio.page = page;
fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr;
+ /*
+ * don't cache encrypted data into meta inode until previous dirty
+ * data were writebacked to avoid racing between GC and flush.
+ */
+ f2fs_wait_on_page_writeback(page, DATA, true);
+
+ f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
+
fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(sbi),
dn.data_blkaddr,
FGP_LOCK | FGP_CREAT, GFP_NOFS);
@@ -745,6 +753,8 @@ static int move_data_block(struct inode *inode, block_t bidx,
*/
f2fs_wait_on_page_writeback(page, DATA, true);
+ f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
+
err = f2fs_get_node_info(fio.sbi, dn.nid, &ni);
if (err)
goto put_out;
--
2.19.1
next parent reply other threads:[~2019-01-28 15:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190128154341.47195-1-sashal@kernel.org>
2019-01-28 15:40 ` Sasha Levin [this message]
2019-01-28 15:40 ` [PATCH AUTOSEL 4.20 086/304] f2fs: move dir data flush to write checkpoint process Sasha Levin
2019-01-28 15:40 ` [PATCH AUTOSEL 4.20 087/304] f2fs: avoid build warn of fall_through Sasha Levin
2019-01-28 15:40 ` [PATCH AUTOSEL 4.20 088/304] f2fs: fix race between write_checkpoint and write_begin Sasha Levin
2019-01-28 15:40 ` [PATCH AUTOSEL 4.20 089/304] f2fs: fix wrong return value of f2fs_acl_create Sasha Levin
2019-01-28 15:41 ` [PATCH AUTOSEL 4.20 178/304] f2fs: fix to reorder set_page_dirty and wait_on_page_writeback Sasha Levin
2019-01-28 15:43 ` [PATCH AUTOSEL 4.20 270/304] f2fs: fix use-after-free issue when accessing sbi->stat_info Sasha Levin
2019-01-28 15:43 ` [PATCH AUTOSEL 4.20 273/304] f2fs: fix sbi->extent_list corruption issue Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190128154341.47195-85-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).