fsverity: support verifying data from large folios
Eric Biggers
maintainerPATCH 1/1 fsverity: support verifying data from large folios
From: Eric Biggers <[email protected]>
Try to make fs/verity/verify.c aware of large folios. This includes making fsverity_verify_bio() support the case where the bio contains large folios, and adding a function fsverity_verify_folio() which is the equivalent of fsverity_verify_page().
There's no way to actually test this with large folios yet, but I've tested that this doesn't cause any regressions.
---
This patch is targeting 6.3, and it applies to
https://git.kernel.org/pub/scm/fs/fsverity/linux.git/log/?h=for-next
Note: to avoid a cross-tree dependency, in fs/buffer.c I used page_folio(bh->b_page) instead of bh->b_folio.
Documentation/filesystems/fsverity.rst | 20 ++++++------ fs/buffer.c | 3 +- fs/verity/verify.c | 43 +++++++++++++------------- include/linux/fsverity.h | 15 ++++++--- 4 files changed, 44 insertions(+), 37 deletions(-)
Documentation/filesystems/fsverity.rst +10 -10
@@ -568,22 +568,22 @@ Pagecache ~~~~~~~~~ For filesystems using Linux's pagecache, the ``->read_folio()`` and -``->readahead()`` methods must be modified to verify pages before they -are marked Uptodate. Merely hooking ``->read_iter()`` would be +``->readahead()`` methods must be modified to verify folios before +they are marked Uptodate. Merely hooking ``->read_iter()`` would be insufficient, since ``->read_iter()`` is not used for memory maps. Therefore, fs/verity/ provides the function fsverity_verify_blocks() which verifies data that has been read into the pagecache of a verity -inode. The containing page must still be locked and not Uptodate, so +inode. The containing folio must still be locked and not Uptodate, so it's not yet readable by userspace. As needed to do the verification, fsverity_verify_blocks() will call back into the filesystem to read hash blocks via fsverity_operations::read_merkle_tree_page(). fsverity_verify_blocks() returns false if verification failed; in this -case, the filesystem must not set the page Uptodate. Following this, +case, the filesystem must not set the folio Uptodate. Following this, as per the usual Linux pagecache behavior, attempts by userspace to -read() from the part of the file containing the page will fail with -EIO, and accesses to the page within a memory map will raise SIGBUS. +read() from the part of the file containing the folio will fail with +EIO, and accesses to the folio within a memory map will raise SIGBUS. In principle, verifying a data block requires verifying the entire path in the Merkle tree from the data block to the root hash.
@@ -624,8 +624,8 @@ each bio and store it in ``->bi_private``:: verity, or both is enabled. After the bio completes, for each needed postprocessing step the filesystem enqueues the bio_post_read_ctx on a workqueue, and then the workqueue work does the decryption or -verification. Finally, pages where no decryption or verity error -occurred are marked Uptodate, and the pages are unlocked. +verification. Finally, folios where no decryption or verity error +occurred are marked Uptodate, and the folios are unlocked. On many filesystems, files can contain holes. Normally, ``->readahead()`` simply zeroes hole blocks and considers the
@@ -791,9 +791,9 @@ weren't already directly answered in other parts of this document. :A: There are many reasons why this is not possible or would be very difficult, including the following: - - To prevent bypassing verification, pages must not be marked + - To prevent bypassing verification, folios must not be marked Uptodate until they've been verified. Currently, each - filesystem is responsible for marking pages Uptodate via + filesystem is responsible for marking folios Uptodate via ``->readahead()``. Therefore, currently it's not possible for the VFS to do the verification on its own. Changing this would require significant changes to the VFS and all filesystems.
fs/buffer.c +2 -1
@@ -308,7 +308,8 @@ static void verify_bh(struct work_struct *work)struct buffer_head *bh = ctx->bh;bool valid; - valid =fsverity_verify_blocks (bh->b_page, bh->b_size,bh_offset (bh)); + valid =fsverity_verify_blocks (page_folio (bh->b_page), bh->b_size, +bh_offset (bh));end_buffer_async_read (bh, valid);kfree (ctx); }
fs/verity/verify.c +22 -21
87 lines not on this page · raw message
include/linux/fsverity.h +10 -5
@@ -12,6 +12,7 @@#define _LINUX_FSVERITY_H#include <linux/fs.h> +#include <linux/mm.h> #include <crypto/hash_info.h> #include <crypto/sha2.h> #include <uapi/linux/fsverity.h>
@@ -169,8 +170,7 @@ int fsverity_ioctl_read_metadata(struct file *filp, const void __user *uarg);/* verify.c */ -bool fsverity_verify_blocks (struct page *page,unsigned int len, -unsigned int offset); +bool fsverity_verify_blocks (struct folio *folio,size_t len,size_t offset);void fsverity_verify_bio (struct bio *bio);void fsverity_enqueue_verify_work (struct work_struct *work);
@@ -230,8 +230,8 @@ static inline int fsverity_ioctl_read_metadata(struct file *filp,/* verify.c */ -static inline bool fsverity_verify_blocks (struct page *page,unsigned int len, -unsigned int offset) +static inline bool fsverity_verify_blocks (struct folio *folio,size_t len, +size_t offset) {WARN_ON (1 );return false;
@@ -249,9 +249,14 @@ static inline void fsverity_enqueue_verify_work(struct work_struct *work)#endif /* !CONFIG_FS_VERITY */ +static inline bool fsverity_verify_folio (struct folio *folio) +{ +return fsverity_verify_blocks (folio,folio_size (folio),0 ); +} +static inline bool fsverity_verify_page (struct page *page) { -return fsverity_verify_blocks (page,PAGE_SIZE ,0 ); +return fsverity_verify_blocks (page_folio (page),PAGE_SIZE ,0 ); }/**
base-commit: 245edf445c3421584f541307cd7a8cd847c3d8d7
Signature · 1 line
2.39.1
Quoted 18 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Try to make
fs/verity/verify.caware of large folios. This includes makingfsverity_verify_bio()support the case where the bio contains large folios, and adding a functionfsverity_verify_folio()which is the equivalent offsverity_verify_page().There's no way to actually test this with large folios yet, but I've tested that this doesn't cause any regressions.
Signed-off-by Eric Biggers <[email protected]>---
This patch is targeting 6.3, and it applies to
https://git.kernel.org/pub/scm/fs/fsverity/linux.git/log/?h=for-next
Note: to avoid a cross-tree dependency, infs/buffer.cI usedpage_folio(bh->b_page)instead ofbh->b_folio.
Quoted 5 lines
Documentation/filesystems/fsverity.rst | 20 ++++++------ fs/buffer.c | 3 +- fs/verity/verify.c | 43 +++++++++++++------------- include/linux/fsverity.h | 15 ++++++--- 4 files changed, 44 insertions(+), 37 deletions(-)
Applied to https://git.kernel.org/pub/scm/fs/fsverity/linux.git/log/?h=for-next
- Eric