Skip to content

Commit fb55e17

Browse files
jxwufanpcmoore
authored andcommitted
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 <[email protected]> [PM: subject line tweak, removed changelog] Signed-off-by: Paul Moore <[email protected]>
1 parent e155858 commit fb55e17

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

include/linux/lsm_hook_defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ LSM_HOOK(void, LSM_RET_VOID, inode_getsecid, struct inode *inode, u32 *secid)
180180
LSM_HOOK(int, 0, inode_copy_up, struct dentry *src, struct cred **new)
181181
LSM_HOOK(int, -EOPNOTSUPP, inode_copy_up_xattr, struct dentry *src,
182182
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)
183185
LSM_HOOK(int, 0, kernfs_init_security, struct kernfs_node *kn_dir,
184186
struct kernfs_node *kn)
185187
LSM_HOOK(int, 0, file_permission, struct file *file, int mask)

include/linux/security.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@ int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer
410410
void security_inode_getsecid(struct inode *inode, u32 *secid);
411411
int security_inode_copy_up(struct dentry *src, struct cred **new);
412412
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);
413416
int security_kernfs_init_security(struct kernfs_node *kn_dir,
414417
struct kernfs_node *kn);
415418
int security_file_permission(struct file *file, int mask);
@@ -1026,6 +1029,13 @@ static inline int security_inode_copy_up(struct dentry *src, struct cred **new)
10261029
return 0;
10271030
}
10281031

1032+
static inline int security_inode_setintegrity(const struct inode *inode,
1033+
enum lsm_integrity_type type,
1034+
const void *value, size_t size)
1035+
{
1036+
return 0;
1037+
}
1038+
10291039
static inline int security_kernfs_init_security(struct kernfs_node *kn_dir,
10301040
struct kernfs_node *kn)
10311041
{

security/security.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,6 +2716,26 @@ int security_inode_copy_up_xattr(struct dentry *src, const char *name)
27162716
}
27172717
EXPORT_SYMBOL(security_inode_copy_up_xattr);
27182718

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+
27192739
/**
27202740
* security_kernfs_init_security() - Init LSM context for a kernfs node
27212741
* @kn_dir: parent kernfs node

0 commit comments

Comments
 (0)