linux-fscrypt.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] f2fs: fsverity: Truncate cache pages if set verity failed
       [not found]   ` <YDbbGSsd6ibKOpzT@sol.localdomain>
@ 2021-02-24 23:11     ` Eric Biggers
  2021-02-26  1:42       ` heyunlei 00015531
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Biggers @ 2021-02-24 23:11 UTC (permalink / raw)
  To: heyunlei; +Cc: Chao Yu, jaegeuk, linux-f2fs-devel, bintian.wang, linux-fscrypt

On Wed, Feb 24, 2021 at 03:02:52PM -0800, Eric Biggers wrote:
> Hi Yunlei,
> 
> On Wed, Feb 24, 2021 at 09:16:24PM +0800, Chao Yu wrote:
> > Hi Yunlei,
> > 
> > On 2021/2/23 19:24, heyunlei wrote:
> > > If file enable verity failed, should truncate anything wrote
> > > past i_size, including cache pages.
> > 
> > +Cc Eric,
> > 
> > After failure of enabling verity, we will see verity metadata if we truncate
> > file to larger size later?
> > 
> > Thanks,
> > 
> > > 
> > > Signed-off-by: heyunlei <heyunlei@hihonor.com>
> > > ---
> > >   fs/f2fs/verity.c | 4 +++-
> > >   1 file changed, 3 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/fs/f2fs/verity.c b/fs/f2fs/verity.c
> > > index 054ec852b5ea..f1f9b9361a71 100644
> > > --- a/fs/f2fs/verity.c
> > > +++ b/fs/f2fs/verity.c
> > > @@ -170,8 +170,10 @@ static int f2fs_end_enable_verity(struct file *filp, const void *desc,
> > >   	}
> > >   	/* If we failed, truncate anything we wrote past i_size. */
> > > -	if (desc == NULL || err)
> > > +	if (desc == NULL || err) {
> > > +		truncate_inode_pages(inode->i_mapping, inode->i_size);
> > >   		f2fs_truncate(inode);
> > > +	}
> > >   	clear_inode_flag(inode, FI_VERITY_IN_PROGRESS);
> > > 
> 
> This looks good; thanks for finding this.  You can add:
> 
> 	Reviewed-by: Eric Biggers <ebiggers@google.com>
> 
> I thought that f2fs_truncate() would truncate pagecache pages too, but in fact
> that's not the case.
> 
> ext4_end_enable_verity() has the same bug too.  Can you please send a patch for
> that too (to linux-ext4)?
> 

Also please include the following tags in the f2fs patch:

	Fixes: 95ae251fe828 ("f2fs: add fs-verity support")
	Cc: <stable@vger.kernel.org> # v5.4+

and in the ext4 patch:

	Fixes: c93d8f885809 ("ext4: add basic fs-verity support")
	Cc: <stable@vger.kernel.org> # v5.4+

- Eric

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] f2fs: fsverity: Truncate cache pages if set verity failed
  2021-02-24 23:11     ` [PATCH] f2fs: fsverity: Truncate cache pages if set verity failed Eric Biggers
@ 2021-02-26  1:42       ` heyunlei 00015531
  2021-02-26  2:15         ` Eric Biggers
  0 siblings, 1 reply; 4+ messages in thread
From: heyunlei 00015531 @ 2021-02-26  1:42 UTC (permalink / raw)
  To: Eric Biggers
  Cc: Chao Yu, jaegeuk, linux-f2fs-devel, bintian.wang, linux-fscrypt


在 2021/2/25 7:11, Eric Biggers 写道:
> On Wed, Feb 24, 2021 at 03:02:52PM -0800, Eric Biggers wrote:
>> Hi Yunlei,
>>
>> On Wed, Feb 24, 2021 at 09:16:24PM +0800, Chao Yu wrote:
>>> Hi Yunlei,
>>>
>>> On 2021/2/23 19:24, heyunlei wrote:
>>>> If file enable verity failed, should truncate anything wrote
>>>> past i_size, including cache pages.
>>> +Cc Eric,
>>>
>>> After failure of enabling verity, we will see verity metadata if we truncate
>>> file to larger size later?
>>>
>>> Thanks,
Hi Eric,
>>>> Signed-off-by: heyunlei <heyunlei@hihonor.com>
>>>> ---
>>>>    fs/f2fs/verity.c | 4 +++-
>>>>    1 file changed, 3 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/fs/f2fs/verity.c b/fs/f2fs/verity.c
>>>> index 054ec852b5ea..f1f9b9361a71 100644
>>>> --- a/fs/f2fs/verity.c
>>>> +++ b/fs/f2fs/verity.c
>>>> @@ -170,8 +170,10 @@ static int f2fs_end_enable_verity(struct file *filp, const void *desc,
>>>>    	}
>>>>    	/* If we failed, truncate anything we wrote past i_size. */
>>>> -	if (desc == NULL || err)
>>>> +	if (desc == NULL || err) {
>>>> +		truncate_inode_pages(inode->i_mapping, inode->i_size);
>>>>    		f2fs_truncate(inode);
>>>> +	}
>>>>    	clear_inode_flag(inode, FI_VERITY_IN_PROGRESS);
>>>>
By the way,should  we consider  set xattr failed?

Thanks.

>> This looks good; thanks for finding this.  You can add:
>>
>> 	Reviewed-by: Eric Biggers <ebiggers@google.com>
>>
>> I thought that f2fs_truncate() would truncate pagecache pages too, but in fact
>> that's not the case.
>>
>> ext4_end_enable_verity() has the same bug too.  Can you please send a patch for
>> that too (to linux-ext4)?
>>
> Also please include the following tags in the f2fs patch:
>
> 	Fixes: 95ae251fe828 ("f2fs: add fs-verity support")
> 	Cc: <stable@vger.kernel.org> # v5.4+
>
> and in the ext4 patch:
>
> 	Fixes: c93d8f885809 ("ext4: add basic fs-verity support")
> 	Cc: <stable@vger.kernel.org> # v5.4+
>
> - Eric


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] f2fs: fsverity: Truncate cache pages if set verity failed
  2021-02-26  1:42       ` heyunlei 00015531
@ 2021-02-26  2:15         ` Eric Biggers
  2021-02-28  4:52           ` Jaegeuk Kim
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Biggers @ 2021-02-26  2:15 UTC (permalink / raw)
  To: heyunlei 00015531
  Cc: Chao Yu, jaegeuk, linux-f2fs-devel, bintian.wang, linux-fscrypt

On Fri, Feb 26, 2021 at 09:42:33AM +0800, heyunlei 00015531 wrote:
> 
> 在 2021/2/25 7:11, Eric Biggers 写道:
> > On Wed, Feb 24, 2021 at 03:02:52PM -0800, Eric Biggers wrote:
> > > Hi Yunlei,
> > > 
> > > On Wed, Feb 24, 2021 at 09:16:24PM +0800, Chao Yu wrote:
> > > > Hi Yunlei,
> > > > 
> > > > On 2021/2/23 19:24, heyunlei wrote:
> > > > > If file enable verity failed, should truncate anything wrote
> > > > > past i_size, including cache pages.
> > > > +Cc Eric,
> > > > 
> > > > After failure of enabling verity, we will see verity metadata if we truncate
> > > > file to larger size later?
> > > > 
> > > > Thanks,
> Hi Eric,
> > > > > Signed-off-by: heyunlei <heyunlei@hihonor.com>
> > > > > ---
> > > > >    fs/f2fs/verity.c | 4 +++-
> > > > >    1 file changed, 3 insertions(+), 1 deletion(-)
> > > > > 
> > > > > diff --git a/fs/f2fs/verity.c b/fs/f2fs/verity.c
> > > > > index 054ec852b5ea..f1f9b9361a71 100644
> > > > > --- a/fs/f2fs/verity.c
> > > > > +++ b/fs/f2fs/verity.c
> > > > > @@ -170,8 +170,10 @@ static int f2fs_end_enable_verity(struct file *filp, const void *desc,
> > > > >    	}
> > > > >    	/* If we failed, truncate anything we wrote past i_size. */
> > > > > -	if (desc == NULL || err)
> > > > > +	if (desc == NULL || err) {
> > > > > +		truncate_inode_pages(inode->i_mapping, inode->i_size);
> > > > >    		f2fs_truncate(inode);
> > > > > +	}
> > > > >    	clear_inode_flag(inode, FI_VERITY_IN_PROGRESS);
> > > > > 
> By the way,should  we consider  set xattr failed?
> 

Yes, that seems to be another oversight.  Similarly for ext4, if
ext4_journal_start(), ext4_orphan_del(), or ext4_reserve_inode_write() fails.

I think the right fix is to move the truncation to the end of the function.

- Eric

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] f2fs: fsverity: Truncate cache pages if set verity failed
  2021-02-26  2:15         ` Eric Biggers
@ 2021-02-28  4:52           ` Jaegeuk Kim
  0 siblings, 0 replies; 4+ messages in thread
From: Jaegeuk Kim @ 2021-02-28  4:52 UTC (permalink / raw)
  To: Eric Biggers
  Cc: heyunlei 00015531, Chao Yu, linux-f2fs-devel, bintian.wang,
	linux-fscrypt

Hi Yunlei,

Could you please post another version to have all the suggestions? :)

Thanks,

On 02/25, Eric Biggers wrote:
> On Fri, Feb 26, 2021 at 09:42:33AM +0800, heyunlei 00015531 wrote:
> > 
> > 在 2021/2/25 7:11, Eric Biggers 写道:
> > > On Wed, Feb 24, 2021 at 03:02:52PM -0800, Eric Biggers wrote:
> > > > Hi Yunlei,
> > > > 
> > > > On Wed, Feb 24, 2021 at 09:16:24PM +0800, Chao Yu wrote:
> > > > > Hi Yunlei,
> > > > > 
> > > > > On 2021/2/23 19:24, heyunlei wrote:
> > > > > > If file enable verity failed, should truncate anything wrote
> > > > > > past i_size, including cache pages.
> > > > > +Cc Eric,
> > > > > 
> > > > > After failure of enabling verity, we will see verity metadata if we truncate
> > > > > file to larger size later?
> > > > > 
> > > > > Thanks,
> > Hi Eric,
> > > > > > Signed-off-by: heyunlei <heyunlei@hihonor.com>
> > > > > > ---
> > > > > >    fs/f2fs/verity.c | 4 +++-
> > > > > >    1 file changed, 3 insertions(+), 1 deletion(-)
> > > > > > 
> > > > > > diff --git a/fs/f2fs/verity.c b/fs/f2fs/verity.c
> > > > > > index 054ec852b5ea..f1f9b9361a71 100644
> > > > > > --- a/fs/f2fs/verity.c
> > > > > > +++ b/fs/f2fs/verity.c
> > > > > > @@ -170,8 +170,10 @@ static int f2fs_end_enable_verity(struct file *filp, const void *desc,
> > > > > >    	}
> > > > > >    	/* If we failed, truncate anything we wrote past i_size. */
> > > > > > -	if (desc == NULL || err)
> > > > > > +	if (desc == NULL || err) {
> > > > > > +		truncate_inode_pages(inode->i_mapping, inode->i_size);
> > > > > >    		f2fs_truncate(inode);
> > > > > > +	}
> > > > > >    	clear_inode_flag(inode, FI_VERITY_IN_PROGRESS);
> > > > > > 
> > By the way,should  we consider  set xattr failed?
> > 
> 
> Yes, that seems to be another oversight.  Similarly for ext4, if
> ext4_journal_start(), ext4_orphan_del(), or ext4_reserve_inode_write() fails.
> 
> I think the right fix is to move the truncation to the end of the function.
> 
> - Eric

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-28  4:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20210223112425.19180-1-heyunlei@hihonor.com>
     [not found] ` <c1ce1421-2576-5b48-322c-fa682c7510d7@kernel.org>
     [not found]   ` <YDbbGSsd6ibKOpzT@sol.localdomain>
2021-02-24 23:11     ` [PATCH] f2fs: fsverity: Truncate cache pages if set verity failed Eric Biggers
2021-02-26  1:42       ` heyunlei 00015531
2021-02-26  2:15         ` Eric Biggers
2021-02-28  4:52           ` Jaegeuk Kim

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).