Skip to content

Commit 8b9d0b8

Browse files
robertosassupcmoore
authored andcommitted
security: Introduce inode_post_set_acl hook
In preparation for moving IMA and EVM to the LSM infrastructure, introduce the inode_post_set_acl hook. At inode_set_acl hook, EVM verifies the file's existing HMAC value. At inode_post_set_acl, EVM re-calculates the file's HMAC based on the modified POSIX ACL and other file metadata. Other LSMs could similarly take some action after successful POSIX ACL 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]> Acked-by: Casey Schaufler <[email protected]> Reviewed-by: Mimi Zohar <[email protected]> Acked-by: Christian Brauner <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent a7811e3 commit 8b9d0b8

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

fs/posix_acl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,7 @@ int vfs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
11371137
error = -EIO;
11381138
if (!error) {
11391139
fsnotify_xattr(dentry);
1140+
security_inode_post_set_acl(dentry, acl_name, kacl);
11401141
evm_inode_post_set_acl(dentry, acl_name, kacl);
11411142
}
11421143

include/linux/lsm_hook_defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry,
157157
const char *name)
158158
LSM_HOOK(int, 0, inode_set_acl, struct mnt_idmap *idmap,
159159
struct dentry *dentry, const char *acl_name, struct posix_acl *kacl)
160+
LSM_HOOK(void, LSM_RET_VOID, inode_post_set_acl, struct dentry *dentry,
161+
const char *acl_name, struct posix_acl *kacl)
160162
LSM_HOOK(int, 0, inode_get_acl, struct mnt_idmap *idmap,
161163
struct dentry *dentry, const char *acl_name)
162164
LSM_HOOK(int, 0, inode_remove_acl, struct mnt_idmap *idmap,

include/linux/security.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ int security_inode_setxattr(struct mnt_idmap *idmap,
372372
int security_inode_set_acl(struct mnt_idmap *idmap,
373373
struct dentry *dentry, const char *acl_name,
374374
struct posix_acl *kacl);
375+
void security_inode_post_set_acl(struct dentry *dentry, const char *acl_name,
376+
struct posix_acl *kacl);
375377
int security_inode_get_acl(struct mnt_idmap *idmap,
376378
struct dentry *dentry, const char *acl_name);
377379
int security_inode_remove_acl(struct mnt_idmap *idmap,
@@ -915,6 +917,11 @@ static inline int security_inode_set_acl(struct mnt_idmap *idmap,
915917
return 0;
916918
}
917919

920+
static inline void security_inode_post_set_acl(struct dentry *dentry,
921+
const char *acl_name,
922+
struct posix_acl *kacl)
923+
{ }
924+
918925
static inline int security_inode_get_acl(struct mnt_idmap *idmap,
919926
struct dentry *dentry,
920927
const char *acl_name)

security/security.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,23 @@ int security_inode_set_acl(struct mnt_idmap *idmap,
23502350
return evm_inode_set_acl(idmap, dentry, acl_name, kacl);
23512351
}
23522352

2353+
/**
2354+
* security_inode_post_set_acl() - Update inode security from posix acls set
2355+
* @dentry: file
2356+
* @acl_name: acl name
2357+
* @kacl: acl struct
2358+
*
2359+
* Update inode security data after successfully setting posix acls on @dentry.
2360+
* The posix acls in @kacl are identified by @acl_name.
2361+
*/
2362+
void security_inode_post_set_acl(struct dentry *dentry, const char *acl_name,
2363+
struct posix_acl *kacl)
2364+
{
2365+
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
2366+
return;
2367+
call_void_hook(inode_post_set_acl, dentry, acl_name, kacl);
2368+
}
2369+
23532370
/**
23542371
* security_inode_get_acl() - Check if reading posix acls is allowed
23552372
* @idmap: idmap of the mount

0 commit comments

Comments
 (0)