Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2771501imj; Mon, 11 Feb 2019 08:13:29 -0800 (PST) X-Google-Smtp-Source: AHgI3IZyxQiWKFzDvFkoH9wxcNXRoL8dRlAZvOMduXgGgq2i+xNemmGgroI89FsRBvGNwGaeBG16 X-Received: by 2002:a62:32c4:: with SMTP id y187mr38547346pfy.195.1549901608983; Mon, 11 Feb 2019 08:13:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549901608; cv=none; d=google.com; s=arc-20160816; b=QiA0wdMU89P2FTJqSLFYSJvFWEigiuFdYjPua7zJRM3iZyc1mkjpu6Lha1EBcrjJFW w+XWk7zchGA2715xUxc0wxYdi1ztDC+aMT0xXD1Evh5Q2GkyaR5do4RUmH2LIaadjblU GVEHAopPNzDU4TV6adG39FfBluNgy3ID7o7kKCzdgEMHNd3HTSdxd88vN0lEYknEIG4A OFA+rHG0mOJZYiEp1vFvIaipZblWRyBbQ0DD0RYVWemUvi3t0cQkEmlPxK7xoUY5NpLG 4JUJNJ5YcXepnzfhsRxVn9WHGxu2ZcRzGYMiHTM9l7hYoyRWMf7H4mHnK1kt2ESKoqdB 00eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4CIMsQfNlIKPdOKjx62fi6m727KYIez6dK+q78f18r4=; b=QA2DiLXS05uWY9E0Dgy6vVPhabnZ0RCBZyvqgL/OL4eUe1cXI4voyRQzyZpgcT3Dki 72vyCwEz2vy1HBM4PMDCfWxfb4wKX1sLVfUwUZOlMiro491f/Vs/ugcQcGuH4lHNPlp+ JNH6PSo8FrhjiVSP3ON+EpzWwQ5y4VlheINkg4LwXuALoXE+Xg7QESoPqVExs6LdAvYu jjy6josI3uoEmRjnZOR4T8pu7cCt54QQaYUnrF+i31Ao3mhZ2uZFpNA1lHkj+JvkYT9i gaFfE7DPNCAROOFsMZgdNMz3TML3pmPfvZRSIvXIfCjvERfMzNDjr91mABxYN4CpwUFj a2fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yswSbqLY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4si9048186pgs.492.2019.02.11.08.13.08; Mon, 11 Feb 2019 08:13:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yswSbqLY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727209AbfBKOZs (ORCPT + 99 others); Mon, 11 Feb 2019 09:25:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:59280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727176AbfBKOZm (ORCPT ); Mon, 11 Feb 2019 09:25:42 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4A52B2075C; Mon, 11 Feb 2019 14:25:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895141; bh=FLP7ULt8mik9/HW4EwuiDypxb07f0ft++hOsLH1TkqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yswSbqLYrM3lFj+i/YBbq/YTxC3uTnmHMoT5JU+SX76pJgpdzyvq+/39eqld4Rshu GXTzQNf3jYyNdeFDGKcnPVwnF3WtlLAvH5sXFlSLZlLmzo+Shyyt26CC2QRXWgKLbE FeIy2qwNokNIL+AS9iRdRYlmM+QNn6/zW2EuSZ1s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yunlong Song , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 4.20 079/352] f2fs: avoid GC causing encrypted file corrupted Date: Mon, 11 Feb 2019 15:15:06 +0100 Message-Id: <20190211141851.060068928@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- 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