[PATCH v5 10/23] security: Introduce inode_post_setattr hook
Paul Moore
paul at paul-moore.com
Thu Nov 16 04:33:45 UTC 2023
On Nov 7, 2023 Roberto Sassu <roberto.sassu at huaweicloud.com> wrote:
>
> 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 <roberto.sassu at huawei.com>
> Reviewed-by: Stefan Berger <stefanb at linux.ibm.com>
> Reviewed-by: Mimi Zohar <zohar at linux.ibm.com>
> Acked-by: Casey Schaufler <casey at schaufler-ca.com>
> ---
> fs/attr.c | 1 +
> include/linux/lsm_hook_defs.h | 2 ++
> include/linux/security.h | 7 +++++++
> security/security.c | 16 ++++++++++++++++
> 4 files changed, 26 insertions(+)
...
> diff --git a/security/security.c b/security/security.c
> index 7935d11d58b5..ce3bc7642e18 100644
> --- a/security/security.c
> +++ b/security/security.c
> @@ -2222,6 +2222,22 @@ int security_inode_setattr(struct mnt_idmap *idmap,
> }
> EXPORT_SYMBOL_GPL(security_inode_setattr);
>
> +/**
> + * security_inode_post_setattr() - Update the inode after a setattr operation
> + * @idmap: idmap of the mount
> + * @dentry: file
> + * @ia_valid: file attributes set
> + *
> + * Update inode security field after successful setting file attributes.
> + */
> +void security_inode_post_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
> + int ia_valid)
> +{
> + if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
> + return;
I may be missing it, but I don't see the S_PRIVATE flag check in the
existing IMA or EVM hooks so I'm curious as to why it is added here?
Please don't misunderstand me, I think it makes sense to return early
on private dentrys/inodes, but why aren't we doing that now?
> + call_void_hook(inode_post_setattr, idmap, dentry, ia_valid);
> +}
> +
> /**
> * security_inode_getattr() - Check if getting file attributes is allowed
> * @path: file
> --
> 2.34.1
--
paul-moore.com
More information about the Linux-security-module-archive
mailing list