Skip to content

Commit 2d705d8

Browse files
robertosassupcmoore
authored andcommitted
security: Introduce inode_post_remove_acl hook
In preparation for moving IMA and EVM to the LSM infrastructure, introduce the inode_post_remove_acl hook. At inode_remove_acl hook, EVM verifies the file's existing HMAC value. At inode_post_remove_acl, EVM re-calculates the file's HMAC with the passed POSIX ACL removed and other file metadata. Other LSMs could similarly take some action after successful POSIX ACL removal. 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 8b9d0b8 commit 2d705d8

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

fs/posix_acl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,7 @@ int vfs_remove_acl(struct mnt_idmap *idmap, struct dentry *dentry,
12461246
error = -EIO;
12471247
if (!error) {
12481248
fsnotify_xattr(dentry);
1249+
security_inode_post_remove_acl(idmap, dentry, acl_name);
12491250
evm_inode_post_remove_acl(idmap, dentry, acl_name);
12501251
}
12511252

include/linux/lsm_hook_defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ LSM_HOOK(int, 0, inode_get_acl, struct mnt_idmap *idmap,
163163
struct dentry *dentry, const char *acl_name)
164164
LSM_HOOK(int, 0, inode_remove_acl, struct mnt_idmap *idmap,
165165
struct dentry *dentry, const char *acl_name)
166+
LSM_HOOK(void, LSM_RET_VOID, inode_post_remove_acl, struct mnt_idmap *idmap,
167+
struct dentry *dentry, const char *acl_name)
166168
LSM_HOOK(int, 0, inode_need_killpriv, struct dentry *dentry)
167169
LSM_HOOK(int, 0, inode_killpriv, struct mnt_idmap *idmap,
168170
struct dentry *dentry)

include/linux/security.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ int security_inode_get_acl(struct mnt_idmap *idmap,
378378
struct dentry *dentry, const char *acl_name);
379379
int security_inode_remove_acl(struct mnt_idmap *idmap,
380380
struct dentry *dentry, const char *acl_name);
381+
void security_inode_post_remove_acl(struct mnt_idmap *idmap,
382+
struct dentry *dentry,
383+
const char *acl_name);
381384
void security_inode_post_setxattr(struct dentry *dentry, const char *name,
382385
const void *value, size_t size, int flags);
383386
int security_inode_getxattr(struct dentry *dentry, const char *name);
@@ -936,6 +939,11 @@ static inline int security_inode_remove_acl(struct mnt_idmap *idmap,
936939
return 0;
937940
}
938941

942+
static inline void security_inode_post_remove_acl(struct mnt_idmap *idmap,
943+
struct dentry *dentry,
944+
const char *acl_name)
945+
{ }
946+
939947
static inline void security_inode_post_setxattr(struct dentry *dentry,
940948
const char *name, const void *value, size_t size, int flags)
941949
{ }

security/security.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,23 @@ int security_inode_remove_acl(struct mnt_idmap *idmap,
24132413
return evm_inode_remove_acl(idmap, dentry, acl_name);
24142414
}
24152415

2416+
/**
2417+
* security_inode_post_remove_acl() - Update inode security after rm posix acls
2418+
* @idmap: idmap of the mount
2419+
* @dentry: file
2420+
* @acl_name: acl name
2421+
*
2422+
* Update inode security data after successfully removing posix acls on
2423+
* @dentry in @idmap. The posix acls are identified by @acl_name.
2424+
*/
2425+
void security_inode_post_remove_acl(struct mnt_idmap *idmap,
2426+
struct dentry *dentry, const char *acl_name)
2427+
{
2428+
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
2429+
return;
2430+
call_void_hook(inode_post_remove_acl, idmap, dentry, acl_name);
2431+
}
2432+
24162433
/**
24172434
* security_inode_post_setxattr() - Update the inode after a setxattr operation
24182435
* @dentry: file

0 commit comments

Comments
 (0)