Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp272968imm; Wed, 29 Aug 2018 21:05:11 -0700 (PDT) X-Google-Smtp-Source: ANB0VdapmLTnQB0jJQ3zYDKR9Ii/Lr+LlFCDcIZ03Y0uabtP19lagSmuoUnqPmLmNLXOgISuQlMF X-Received: by 2002:a62:ed5:: with SMTP id 82-v6mr8625783pfo.198.1535601911739; Wed, 29 Aug 2018 21:05:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535601911; cv=none; d=google.com; s=arc-20160816; b=x1em6ohgplhuPxq96v0gXHk73yaYV+8G4+FU+hb3LNehXoXM+B45lYA41Jn23If+gd 3UmI9YWv9OHx9Xm/LBsJmvsASTYyCvFzn1sgk9LRqnUYa1qEfBFQGxsveig2iSwq/urI WLYJutMKURqNtG9EXTfcQe0khfQ4vt7/uVTSfm1nGM9jkNcyTjo/hBCqxhzr5TjEd5/4 K4qVmVVpwNcXL1i8nIjEoshtfx3ePMIXm1YbPLO6ZddLs4m1fo4g/AwJFLFOwWTgcUCU SFnh4fiwt1bEN3WsaUneH7VKrkGWz/cyogXz/oDoKm9bYov7X85vlY66kOBZJddmO5t+ G9DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=tbINNQr2S33z2qjYQe7A+iKhknQDmhT7ic1eYW4Vr0M=; b=hhS/WJGbNpEJ165t2EqxsV5OHkPabg4AZJZT3d7dBFXNcHeYPKjp278pArb2Sk1fyr UdUlKVqxPfynhtxoO18vWdNNgyh92m7Jw3XhpLuQTZ0f738fjSyxVtC7JLFANe78X9XP xP3uXLPATfvMHuiVjnLbdesGXpM6Z0vWbsaWmG8gqSCHkYZMS+SH+SofcLwZh9Qz3RpC +VpsmdDA24jTCFBnUKMKqqeQne5HNHdi0Xk97aqzj08Vrah+KE//sjSTtZ6Ar911BQZj Lu2ZLyH3N17swthet+c6AzxZI03r3k4YfBfo98d7xTm+zIxJkG0nIpOGRSqkBEXpmOdk MuAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QGyyrN2I; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x61-v6si5812018plb.216.2018.08.29.21.04.53; Wed, 29 Aug 2018 21:05:11 -0700 (PDT) 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=QGyyrN2I; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727542AbeH3IDk (ORCPT + 99 others); Thu, 30 Aug 2018 04:03:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:49220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727438AbeH3IDk (ORCPT ); Thu, 30 Aug 2018 04:03:40 -0400 Received: from localhost (unknown [104.132.1.88]) (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 2FB9820645; Thu, 30 Aug 2018 04:03:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1535601812; bh=spXq0k/TTztPcElXFts51ibUhTyZgqwDQDyGu/Pfykg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QGyyrN2IQG2nhVxhuPqkxiANmy5z7bCOL+y52VdZwAc2qHAQbz5LpEDBt+mrUFWJc rcav49lK5lsUsQwSEEjxJJ6/dR0eKLyGWm2qHc9y7ufZrZ6TaBrp2q5gFM81wU7GBz fH++ZyFQURqfpRxy/8IfzElBs4swPe/zB9cGB8YM= Date: Wed, 29 Aug 2018 21:03:31 -0700 From: Jaegeuk Kim To: Chao Yu Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [PATCH v2] f2fs: avoid wrong decrypted data from disk Message-ID: <20180830040331.GA97850@jaegeuk-macbookpro.roam.corp.google.com> References: <20180827225226.14272-1-jaegeuk@kernel.org> <20180830014858.GA91444@jaegeuk-macbookpro.roam.corp.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.8.2 (2017-04-18) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/30, Chao Yu wrote: > On 2018/8/30 9:48, Jaegeuk Kim wrote: > > 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 > > > > Signed-off-by: Jaegeuk Kim > > --- > > Change log from v1: > > - move to bio != NULL > > > > fs/f2fs/data.c | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > > index 382c1ef9a9e4..159e411785e9 100644 > > --- a/fs/f2fs/data.c > > +++ b/fs/f2fs/data.c > > @@ -1556,6 +1556,12 @@ static int f2fs_mpage_readpages(struct address_space *mapping, > > bio = NULL; > > goto set_error_page; > > } > > + } else if (unlikely(f2fs_encrypted_file(inode))) { > > For android scenario, encryption becomes a common case now, so I think we can > remove unlikely here. > > > + /* > > + * If the page is under writeback, we need to wait for > > + * its completion to see the correct decrypted data. > > + */ > > + f2fs_wait_on_block_writeback(F2FS_I_SB(inode), block_nr); > > } > > Look at this again, it seems f2fs_wait_on_block_writeback() is not related to > f2fs_grab_read_bio(), so we can move it here to make code logic more clear: > > if (f2fs_encrypted_file(inode)) { > /* */ > f2fs_wait_on_block_writeback(F2FS_I_SB(inode), block_nr); > } > > Also, in f2fs_submit_page_read(), we need to adjust to: > > - f2fs_grab_read_bio() > - f2fs_wait_on_block_writeback() > - bio_add_page() > > How do you think? Oh, yeah! > > Thanks, > > > > > if (bio_add_page(bio, page, blocksize, 0) < blocksize) > >