Helper to pre-fill folio with hashes of empty blocks. This will be used by XFS to synthesize blocks full of zero hashes on the fly. Signed-off-by: Andrey Albershteyn --- fs/verity/pagecache.c | 22 ++++++++++++++++++++++ include/linux/fsverity.h | 9 +++++++++ 2 files changed, 31 insertions(+) diff --git a/fs/verity/pagecache.c b/fs/verity/pagecache.c index 73f03b48d42d..7642a7a09dfb 100644 --- a/fs/verity/pagecache.c +++ b/fs/verity/pagecache.c @@ -2,6 +2,7 @@ /* * Copyright 2019 Google LLC */ +#include "fsverity_private.h" #include #include @@ -62,3 +63,24 @@ loff_t fsverity_metadata_offset(const struct inode *inode) return roundup(i_size_read(inode), mapping_max_folio_size_supported()); } EXPORT_SYMBOL_GPL(fsverity_metadata_offset); + +/** + * fsverity_folio_zero_hash() - fill folio with hashes of zero data block + * @folio: folio to fill + * @poff: offset in the folio to start + * @plen: length of the range to fill with hashes + * @vi: fsverity info + */ +void fsverity_folio_zero_hash(struct folio *folio, size_t poff, size_t plen, + struct fsverity_info *vi) +{ + size_t offset = poff; + + WARN_ON_ONCE(!IS_ALIGNED(poff, vi->tree_params.digest_size)); + WARN_ON_ONCE(!IS_ALIGNED(plen, vi->tree_params.digest_size)); + + for (; offset < (poff + plen); offset += vi->tree_params.digest_size) + memcpy_to_folio(folio, offset, vi->tree_params.zero_digest, + vi->tree_params.digest_size); +} +EXPORT_SYMBOL_GPL(fsverity_folio_zero_hash); diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h index 278c6340849f..addee462dcc2 100644 --- a/include/linux/fsverity.h +++ b/include/linux/fsverity.h @@ -215,6 +215,8 @@ bool fsverity_verify_blocks(struct fsverity_info *vi, struct folio *folio, void fsverity_verify_bio(struct fsverity_info *vi, struct bio *bio); void fsverity_enqueue_verify_work(struct work_struct *work); loff_t fsverity_metadata_offset(const struct inode *inode); +void fsverity_folio_zero_hash(struct folio *folio, size_t poff, size_t plen, + struct fsverity_info *vi); #else /* !CONFIG_FS_VERITY */ @@ -302,6 +304,13 @@ static inline loff_t fsverity_metadata_offset(const struct inode *inode) return ULLONG_MAX; } +static inline void fsverity_folio_zero_hash(struct folio *folio, size_t poff, + size_t plen, + struct fsverity_info *vi) +{ + WARN_ON_ONCE(1); +} + #endif /* !CONFIG_FS_VERITY */ static inline bool fsverity_verify_folio(struct fsverity_info *vi, -- 2.51.2