Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lsm: add security_inode_setintegrity() hook

This patch introduces a new hook to save inode's integrity
data. For example, for fsverity enabled files, LSMs can use this hook to
save the existence of verified fsverity builtin signature into the inode's
security blob, and LSMs can make access decisions based on this data.

Signed-off-by: Fan Wu <wufan@linux.microsoft.com>
[PM: subject line tweak, removed changelog]
Signed-off-by: Paul Moore <paul@paul-moore.com>

authored by

Fan Wu and committed by
Paul Moore
fb55e177 e155858d

+32
+2
include/linux/lsm_hook_defs.h
··· 180 180 LSM_HOOK(int, 0, inode_copy_up, struct dentry *src, struct cred **new) 181 181 LSM_HOOK(int, -EOPNOTSUPP, inode_copy_up_xattr, struct dentry *src, 182 182 const char *name) 183 + LSM_HOOK(int, 0, inode_setintegrity, const struct inode *inode, 184 + enum lsm_integrity_type type, const void *value, size_t size) 183 185 LSM_HOOK(int, 0, kernfs_init_security, struct kernfs_node *kn_dir, 184 186 struct kernfs_node *kn) 185 187 LSM_HOOK(int, 0, file_permission, struct file *file, int mask)
+10
include/linux/security.h
··· 410 410 void security_inode_getsecid(struct inode *inode, u32 *secid); 411 411 int security_inode_copy_up(struct dentry *src, struct cred **new); 412 412 int security_inode_copy_up_xattr(struct dentry *src, const char *name); 413 + int security_inode_setintegrity(const struct inode *inode, 414 + enum lsm_integrity_type type, const void *value, 415 + size_t size); 413 416 int security_kernfs_init_security(struct kernfs_node *kn_dir, 414 417 struct kernfs_node *kn); 415 418 int security_file_permission(struct file *file, int mask); ··· 1025 1022 } 1026 1023 1027 1024 static inline int security_inode_copy_up(struct dentry *src, struct cred **new) 1025 + { 1026 + return 0; 1027 + } 1028 + 1029 + static inline int security_inode_setintegrity(const struct inode *inode, 1030 + enum lsm_integrity_type type, 1031 + const void *value, size_t size) 1028 1032 { 1029 1033 return 0; 1030 1034 }
+20
security/security.c
··· 2717 2717 EXPORT_SYMBOL(security_inode_copy_up_xattr); 2718 2718 2719 2719 /** 2720 + * security_inode_setintegrity() - Set the inode's integrity data 2721 + * @inode: inode 2722 + * @type: type of integrity, e.g. hash digest, signature, etc 2723 + * @value: the integrity value 2724 + * @size: size of the integrity value 2725 + * 2726 + * Register a verified integrity measurement of a inode with LSMs. 2727 + * LSMs should free the previously saved data if @value is NULL. 2728 + * 2729 + * Return: Returns 0 on success, negative values on failure. 2730 + */ 2731 + int security_inode_setintegrity(const struct inode *inode, 2732 + enum lsm_integrity_type type, const void *value, 2733 + size_t size) 2734 + { 2735 + return call_int_hook(inode_setintegrity, inode, type, value, size); 2736 + } 2737 + EXPORT_SYMBOL(security_inode_setintegrity); 2738 + 2739 + /** 2720 2740 * security_kernfs_init_security() - Init LSM context for a kernfs node 2721 2741 * @kn_dir: parent kernfs node 2722 2742 * @kn: the kernfs node to initialize