Skip to content

Commit 77fa6f3

Browse files
robertosassupcmoore
authored andcommitted
security: Introduce inode_post_setattr hook
In preparation for moving IMA and EVM to the LSM infrastructure, introduce the inode_post_setattr hook. At inode_setattr hook, EVM verifies the file's existing HMAC value. At inode_post_setattr, EVM re-calculates the file's HMAC based on the modified file attributes and other file metadata. Other LSMs could similarly take some action after successful file attribute change. The new hook cannot return an error and cannot cause the operation to be reverted. Signed-off-by: Roberto Sassu <[email protected]> Reviewed-by: Stefan Berger <[email protected]> Reviewed-by: Mimi Zohar <[email protected]> Acked-by: Casey Schaufler <[email protected]> Acked-by: Christian Brauner <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 314a8dc commit 77fa6f3

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

fs/attr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ int notify_change(struct mnt_idmap *idmap, struct dentry *dentry,
502502

503503
if (!error) {
504504
fsnotify_change(dentry, ia_valid);
505+
security_inode_post_setattr(idmap, dentry, ia_valid);
505506
ima_inode_post_setattr(idmap, dentry, ia_valid);
506507
evm_inode_post_setattr(idmap, dentry, ia_valid);
507508
}

include/linux/lsm_hook_defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ LSM_HOOK(int, 0, inode_follow_link, struct dentry *dentry, struct inode *inode,
137137
LSM_HOOK(int, 0, inode_permission, struct inode *inode, int mask)
138138
LSM_HOOK(int, 0, inode_setattr, struct mnt_idmap *idmap, struct dentry *dentry,
139139
struct iattr *attr)
140+
LSM_HOOK(void, LSM_RET_VOID, inode_post_setattr, struct mnt_idmap *idmap,
141+
struct dentry *dentry, int ia_valid)
140142
LSM_HOOK(int, 0, inode_getattr, const struct path *path)
141143
LSM_HOOK(int, 0, inode_setxattr, struct mnt_idmap *idmap,
142144
struct dentry *dentry, const char *name, const void *value,

include/linux/security.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
361361
int security_inode_permission(struct inode *inode, int mask);
362362
int security_inode_setattr(struct mnt_idmap *idmap,
363363
struct dentry *dentry, struct iattr *attr);
364+
void security_inode_post_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
365+
int ia_valid);
364366
int security_inode_getattr(const struct path *path);
365367
int security_inode_setxattr(struct mnt_idmap *idmap,
366368
struct dentry *dentry, const char *name,
@@ -879,6 +881,11 @@ static inline int security_inode_setattr(struct mnt_idmap *idmap,
879881
return 0;
880882
}
881883

884+
static inline void
885+
security_inode_post_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
886+
int ia_valid)
887+
{ }
888+
882889
static inline int security_inode_getattr(const struct path *path)
883890
{
884891
return 0;

security/security.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,6 +2222,22 @@ int security_inode_setattr(struct mnt_idmap *idmap,
22222222
}
22232223
EXPORT_SYMBOL_GPL(security_inode_setattr);
22242224

2225+
/**
2226+
* security_inode_post_setattr() - Update the inode after a setattr operation
2227+
* @idmap: idmap of the mount
2228+
* @dentry: file
2229+
* @ia_valid: file attributes set
2230+
*
2231+
* Update inode security field after successful setting file attributes.
2232+
*/
2233+
void security_inode_post_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
2234+
int ia_valid)
2235+
{
2236+
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
2237+
return;
2238+
call_void_hook(inode_post_setattr, idmap, dentry, ia_valid);
2239+
}
2240+
22252241
/**
22262242
* security_inode_getattr() - Check if getting file attributes is allowed
22272243
* @path: file

0 commit comments

Comments
 (0)