Skip to content

Commit f09068b

Browse files
robertosassupcmoore
authored andcommitted
security: Introduce file_release hook
In preparation for moving IMA and EVM to the LSM infrastructure, introduce the file_release 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. The new hook cannot return an error and cannot cause the operation to be reverted. Signed-off-by: Roberto Sassu <[email protected]> Acked-by: Christian Brauner <[email protected]> Reviewed-by: Stefan Berger <[email protected]> Reviewed-by: Mimi Zohar <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 8f46ff5 commit f09068b

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

fs/file_table.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ static void __fput(struct file *file)
367367
eventpoll_release(file);
368368
locks_remove_file(file);
369369

370+
security_file_release(file);
370371
ima_file_free(file);
371372
if (unlikely(file->f_flags & FASYNC)) {
372373
if (file->f_op->fasync)

include/linux/lsm_hook_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ LSM_HOOK(int, 0, kernfs_init_security, struct kernfs_node *kn_dir,
173173
struct kernfs_node *kn)
174174
LSM_HOOK(int, 0, file_permission, struct file *file, int mask)
175175
LSM_HOOK(int, 0, file_alloc_security, struct file *file)
176+
LSM_HOOK(void, LSM_RET_VOID, file_release, struct file *file)
176177
LSM_HOOK(void, LSM_RET_VOID, file_free_security, struct file *file)
177178
LSM_HOOK(int, 0, file_ioctl, struct file *file, unsigned int cmd,
178179
unsigned long arg)

include/linux/security.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ int security_kernfs_init_security(struct kernfs_node *kn_dir,
395395
struct kernfs_node *kn);
396396
int security_file_permission(struct file *file, int mask);
397397
int security_file_alloc(struct file *file);
398+
void security_file_release(struct file *file);
398399
void security_file_free(struct file *file);
399400
int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
400401
int security_file_ioctl_compat(struct file *file, unsigned int cmd,
@@ -1008,6 +1009,9 @@ static inline int security_file_alloc(struct file *file)
10081009
return 0;
10091010
}
10101011

1012+
static inline void security_file_release(struct file *file)
1013+
{ }
1014+
10111015
static inline void security_file_free(struct file *file)
10121016
{ }
10131017

security/security.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,17 @@ int security_file_alloc(struct file *file)
27182718
return rc;
27192719
}
27202720

2721+
/**
2722+
* security_file_release() - Perform actions before releasing the file ref
2723+
* @file: the file
2724+
*
2725+
* Perform actions before releasing the last reference to a file.
2726+
*/
2727+
void security_file_release(struct file *file)
2728+
{
2729+
call_void_hook(file_release, file);
2730+
}
2731+
27212732
/**
27222733
* security_file_free() - Free a file's LSM blob
27232734
* @file: the file

0 commit comments

Comments
 (0)