Use accessor to get and set the verity info from the filesystem. They can be removed once all filesystems have been converted to make room for verity info in their own inodes.
Signed-off-by: Christian Brauner <brau...@kernel.org> --- fs/verity/open.c | 18 +++++++++++++++--- fs/verity/verify.c | 2 +- include/linux/fsverity.h | 9 ++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/fs/verity/open.c b/fs/verity/open.c index fdeb95eca3af..2b9da08754f3 100644 --- a/fs/verity/open.c +++ b/fs/verity/open.c @@ -250,13 +250,20 @@ struct fsverity_info *fsverity_create_info(const struct inode *inode, void fsverity_set_info(struct inode *inode, struct fsverity_info *vi) { + void *p; + /* * Multiple tasks may race to set ->i_verity_info, so use * cmpxchg_release(). This pairs with the smp_load_acquire() in * fsverity_get_info(). I.e., here we publish ->i_verity_info with a * RELEASE barrier so that other tasks can ACQUIRE it. */ - if (cmpxchg_release(&inode->i_verity_info, NULL, vi) != NULL) { + + if (inode->i_op->i_fsverity) + p = cmpxchg_release(fsverity_addr(inode), NULL, vi); + else + p = cmpxchg_release(&inode->i_verity_info, NULL, vi); + if (p != NULL) { /* Lost the race, so free the fsverity_info we allocated. */ fsverity_free_info(vi); /* @@ -402,8 +409,13 @@ EXPORT_SYMBOL_GPL(__fsverity_prepare_setattr); void __fsverity_cleanup_inode(struct inode *inode) { - fsverity_free_info(inode->i_verity_info); - inode->i_verity_info = NULL; + struct fsverity_info **vi; + + vi = fsverity_addr(inode); + if (!*vi) + vi = &inode->i_verity_info; + fsverity_free_info(*vi); + *vi = NULL; } EXPORT_SYMBOL_GPL(__fsverity_cleanup_inode); diff --git a/fs/verity/verify.c b/fs/verity/verify.c index 4fcad0825a12..a9c2f5c86991 100644 --- a/fs/verity/verify.c +++ b/fs/verity/verify.c @@ -247,7 +247,7 @@ verify_data_blocks(struct folio *data_folio, size_t len, size_t offset, unsigned long max_ra_pages) { struct inode *inode = data_folio->mapping->host; - struct fsverity_info *vi = inode->i_verity_info; + struct fsverity_info *vi = fsverity_get_info(inode); const unsigned int block_size = vi->tree_params.block_size; u64 pos = (u64)data_folio->index << PAGE_SHIFT; diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h index 1eb7eae580be..3f15d22c03d6 100644 --- a/include/linux/fsverity.h +++ b/include/linux/fsverity.h @@ -124,6 +124,11 @@ struct fsverity_operations { #ifdef CONFIG_FS_VERITY +static inline struct fsverity_info **fsverity_addr(const struct inode *inode) +{ + return ((void *)inode + inode->i_op->i_fsverity); +} + static inline struct fsverity_info *fsverity_get_info(const struct inode *inode) { /* @@ -132,6 +137,8 @@ static inline struct fsverity_info *fsverity_get_info(const struct inode *inode) * executing a RELEASE barrier. We need to use smp_load_acquire() here * to safely ACQUIRE the memory the other task published. */ + if (inode->i_op->i_fsverity) + return smp_load_acquire(fsverity_addr(inode)); return smp_load_acquire(&inode->i_verity_info); } @@ -160,7 +167,7 @@ void __fsverity_cleanup_inode(struct inode *inode); */ static inline void fsverity_cleanup_inode(struct inode *inode) { - if (inode->i_verity_info) + if (inode->i_verity_info || inode->i_op->i_fsverity) __fsverity_cleanup_inode(inode); } -- 2.47.2