Skip to contentSkip to conversation

f2fs: don't keep META_MAPPING pages used for moving verity file blocks

PATCH In review Eric Biggers 3 participants 7 messages Dec 9, 2019 – Dec 10, 2019

Subsystems (2)
lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

PATCH 1/1 f2fs: don't keep META_MAPPING pages used for moving verity file blocks

From: Eric Biggers <[email protected]>

META_MAPPING is used to move blocks for both encrypted and verity files. So the META_MAPPING invalidation condition in do_checkpoint() should consider verity too, not just encrypt.

---
 fs/f2fs/checkpoint.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/f2fs/checkpoint.c +3 -3
index ffdaba0c55d29..44e84ac5c9411 100644
@@ -1509,10 +1509,10 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	f2fs_wait_on_all_pages_writeback(sbi);
 
 	/*
-	 * invalidate intermediate page cache borrowed from meta inode
-	 * which are used for migration of encrypted inode's blocks.
+	 * invalidate intermediate page cache borrowed from meta inode which are
+	 * used for migration of encrypted or verity inode's blocks.
 	 */
-	if (f2fs_sb_has_encrypt(sbi))
+	if (f2fs_sb_has_encrypt(sbi) || f2fs_sb_has_verity(sbi))
 		invalidate_mapping_pages(META_MAPPING(sbi),
 				MAIN_BLKADDR(sbi), MAX_BLKADDR(sbi) - 1);
 
Signature · 1 line
2.24.0.393.g34dc348eaf-goog
maintainer
#1 lore raw
Quoted 16 lines · Eric Biggers

From: Eric Biggers <[email protected]>

META_MAPPING is used to move blocks for both encrypted and verity files. So the META_MAPPING invalidation condition in do_checkpoint() should consider verity too, not just encrypt.

---
 fs/f2fs/checkpoint.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/f2fs/checkpoint.c +0 -0
index ffdaba0c55d29..44e84ac5c9411 100644

fs/f2fs/checkpoint.c static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) · line 1515

Quoted 10 lines
fs/f2fs/checkpoint.c +3 -3
@@ -1509,10 +1509,10 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	f2fs_wait_on_all_pages_writeback(sbi);
 
 	/*
-	 * invalidate intermediate page cache borrowed from meta inode
-	 * which are used for migration of encrypted inode's blocks.
+	 * invalidate intermediate page cache borrowed from meta inode which are
+	 * used for migration of encrypted or verity inode's blocks.
 	 */
-	if (f2fs_sb_has_encrypt(sbi))
+	if (f2fs_sb_has_encrypt(sbi) || f2fs_sb_has_verity(sbi))

Do we need f2fs_post_read_required() aligned to the condition of move_data_block()?

Quoted 5 lines
fs/f2fs/checkpoint.c +0 -0
 		invalidate_mapping_pages(META_MAPPING(sbi),
 				MAIN_BLKADDR(sbi), MAX_BLKADDR(sbi) - 1);
 
Signature · 1 line
2.24.0.393.g34dc348eaf-goog
author maintainer
#2 lore raw
Quoted 19 lines · Jaegeuk Kim
Quoted 18 lines · Eric Biggers

From: Eric Biggers <[email protected]>

META_MAPPING is used to move blocks for both encrypted and verity files. So the META_MAPPING invalidation condition in do_checkpoint() should consider verity too, not just encrypt.

---
 fs/f2fs/checkpoint.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/f2fs/checkpoint.c +0 -0
index ffdaba0c55d29..44e84ac5c9411 100644
@@ -1509,10 +1509,10 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	f2fs_wait_on_all_pages_writeback(sbi);
 
Quoted 12 lines

fs/f2fs/checkpoint.c static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) · line 1515

Quoted 8 lines
fs/f2fs/checkpoint.c +3 -3
 	/*
-	 * invalidate intermediate page cache borrowed from meta inode
-	 * which are used for migration of encrypted inode's blocks.
+	 * invalidate intermediate page cache borrowed from meta inode which are
+	 * used for migration of encrypted or verity inode's blocks.
 	 */
-	if (f2fs_sb_has_encrypt(sbi))
+	if (f2fs_sb_has_encrypt(sbi) || f2fs_sb_has_verity(sbi))

Do we need f2fs_post_read_required() aligned to the condition of move_data_block()?

I think you're asking why verity files have to be moved via META_MAPPING? The reason is that we have to be super careful not to read pages of a verity file into its own address_space without doing the fs-verity data verification, as then unverified data would be available to userspace.

In theory, F2FS's garbage collector could do the data verification. But it's tricky because ->i_verity_info may not have been set up yet. So it might be easiest to continue to treat verity files like encrypted files.

- Eric

maintainer
#3 lore raw
Quoted 33 lines · Eric Biggers
Quoted 19 lines · Jaegeuk Kim
Quoted 18 lines · Eric Biggers

From: Eric Biggers <[email protected]>

META_MAPPING is used to move blocks for both encrypted and verity files. So the META_MAPPING invalidation condition in do_checkpoint() should consider verity too, not just encrypt.

---
 fs/f2fs/checkpoint.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/f2fs/checkpoint.c +0 -0
index ffdaba0c55d29..44e84ac5c9411 100644
@@ -1509,10 +1509,10 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	f2fs_wait_on_all_pages_writeback(sbi);
 
Quoted 12 lines

fs/f2fs/checkpoint.c static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) · line 1515

Quoted 8 lines
fs/f2fs/checkpoint.c +3 -3
 	/*
-	 * invalidate intermediate page cache borrowed from meta inode
-	 * which are used for migration of encrypted inode's blocks.
+	 * invalidate intermediate page cache borrowed from meta inode which are
+	 * used for migration of encrypted or verity inode's blocks.
 	 */
-	if (f2fs_sb_has_encrypt(sbi))
+	if (f2fs_sb_has_encrypt(sbi) || f2fs_sb_has_verity(sbi))

Do we need f2fs_post_read_required() aligned to the condition of move_data_block()?

Quoted 8 lines

I think you're asking why verity files have to be moved via META_MAPPING? The reason is that we have to be super careful not to read pages of a verity file into its own address_space without doing the fs-verity data verification, as then unverified data would be available to userspace.

In theory, F2FS's garbage collector could do the data verification. But it's tricky because ->i_verity_info may not have been set up yet. So it might be easiest to continue to treat verity files like encrypted files.

I meant to ask why not just checking f2fs_post_read_required() here so that we could sync the check across multiple places.

Quoted 2 lines

- Eric

author maintainer
#4 lore raw
Quoted 39 lines · Jaegeuk Kim
Quoted 38 lines · Eric Biggers
Quoted 19 lines · Jaegeuk Kim
Quoted 18 lines · Eric Biggers

From: Eric Biggers <[email protected]>

META_MAPPING is used to move blocks for both encrypted and verity files. So the META_MAPPING invalidation condition in do_checkpoint() should consider verity too, not just encrypt.

---
 fs/f2fs/checkpoint.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/f2fs/checkpoint.c +0 -0
index ffdaba0c55d29..44e84ac5c9411 100644
@@ -1509,10 +1509,10 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	f2fs_wait_on_all_pages_writeback(sbi);
 
Quoted 12 lines

fs/f2fs/checkpoint.c static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) · line 1515

Quoted 8 lines
fs/f2fs/checkpoint.c +3 -3
 	/*
-	 * invalidate intermediate page cache borrowed from meta inode
-	 * which are used for migration of encrypted inode's blocks.
+	 * invalidate intermediate page cache borrowed from meta inode which are
+	 * used for migration of encrypted or verity inode's blocks.
 	 */
-	if (f2fs_sb_has_encrypt(sbi))
+	if (f2fs_sb_has_encrypt(sbi) || f2fs_sb_has_verity(sbi))

Do we need f2fs_post_read_required() aligned to the condition of move_data_block()?

I think you're asking why verity files have to be moved via META_MAPPING? The reason is that we have to be super careful not to read pages of a verity file into its own address_space without doing the fs-verity data verification, as then unverified data would be available to userspace.

Quoted 7 lines
Quoted 3 lines

In theory, F2FS's garbage collector could do the data verification. But it's tricky because ->i_verity_info may not have been set up yet. So it might be easiest to continue to treat verity files like encrypted files.

I meant to ask why not just checking f2fs_post_read_required() here so that we could sync the check across multiple places.

We can't use f2fs_post_read_required() here because f2fs_post_read_required() deals with a specific inode, but do_checkpoint() is dealing with the entire filesystem. It's checking whether the filesystem might have *any* files that were moved via META_MAPPING.

- Eric

maintainer
#5 lore raw
Quoted 44 lines · Eric Biggers
Quoted 43 lines · Jaegeuk Kim
Quoted 41 lines · Eric Biggers
Quoted 19 lines · Jaegeuk Kim
Quoted 18 lines · Eric Biggers

From: Eric Biggers <[email protected]>

META_MAPPING is used to move blocks for both encrypted and verity files. So the META_MAPPING invalidation condition in do_checkpoint() should consider verity too, not just encrypt.

---
 fs/f2fs/checkpoint.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/f2fs/checkpoint.c +0 -0
index ffdaba0c55d29..44e84ac5c9411 100644
@@ -1509,10 +1509,10 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	f2fs_wait_on_all_pages_writeback(sbi);
 
Quoted 12 lines

fs/f2fs/checkpoint.c static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) · line 1515

Quoted 8 lines
fs/f2fs/checkpoint.c +3 -3
 	/*
-	 * invalidate intermediate page cache borrowed from meta inode
-	 * which are used for migration of encrypted inode's blocks.
+	 * invalidate intermediate page cache borrowed from meta inode which are
+	 * used for migration of encrypted or verity inode's blocks.
 	 */
-	if (f2fs_sb_has_encrypt(sbi))
+	if (f2fs_sb_has_encrypt(sbi) || f2fs_sb_has_verity(sbi))

Do we need f2fs_post_read_required() aligned to the condition of move_data_block()?

I think you're asking why verity files have to be moved via META_MAPPING? The reason is that we have to be super careful not to read pages of a verity file into its own address_space without doing the fs-verity data verification, as then unverified data would be available to userspace.

In theory, F2FS's garbage collector could do the data verification. But it's tricky because ->i_verity_info may not have been set up yet. So it might be easiest to continue to treat verity files like encrypted files.

Quoted 8 lines
Quoted 3 lines

I meant to ask why not just checking f2fs_post_read_required() here so that we could sync the check across multiple places.

We can't use f2fs_post_read_required() here because f2fs_post_read_required() deals with a specific inode, but do_checkpoint() is dealing with the entire filesystem. It's checking whether the filesystem might have *any* files that were moved via META_MAPPING.

Ah, I misread the code. Thank you for refreshing me.

Quoted 2 lines

- Eric