[PATCH v5 13/23] security: Introduce file_pre_free_security hook
Paul Moore
paul at paul-moore.com
Thu Nov 16 04:33:47 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 file_pre_free_security hook.
>
> IMA calculates at file close the new digest of the file content and writes
> it to security.ima, so that appraisal at next file access succeeds.
>
> LSMs could also take some action before the last reference of a file is
> released.
>
> 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>
> Acked-by: Casey Schaufler <casey at schaufler-ca.com>
> Reviewed-by: Mimi Zohar <zohar at linux.ibm.com>
> ---
> fs/file_table.c | 1 +
> include/linux/lsm_hook_defs.h | 1 +
> include/linux/security.h | 4 ++++
> security/security.c | 11 +++++++++++
> 4 files changed, 17 insertions(+)
>
> diff --git a/fs/file_table.c b/fs/file_table.c
> index de4a2915bfd4..64ed74555e64 100644
> --- a/fs/file_table.c
> +++ b/fs/file_table.c
> @@ -385,6 +385,7 @@ static void __fput(struct file *file)
> eventpoll_release(file);
> locks_remove_file(file);
>
> + security_file_pre_free(file);
I worry that security_file_pre_free() is a misleading name as "free"
tends to imply memory management tasks, which isn't the main focus of
this hook. What do you think of security_file_release() or
security_file_put() instead?
> ima_file_free(file);
> if (unlikely(file->f_flags & FASYNC)) {
> if (file->f_op->fasync)
--
paul-moore.com
More information about the Linux-security-module-archive
mailing list