This allows other parts of the kernel (perhaps a stacked LSM allowing system monitoring, eg. the proposed KRSI LSM [1]) to retrieve the hash of a given file from IMA if it's present in the iint cache. It's true that the existence of the hash means that it's also in the audit logs or in /sys/kernel/security/ima/ascii_runtime_measurements, but it can be difficult to pull that information out for every subsequent exec. This is especially true if a given host has been up for a long time and the file was first measured a long time ago. It should be kept in mind that this function gives access to cached entries which can be removed, for instance on security_inode_free(). This is based on Peter Moody's patch: https://sourceforge.net/p/linux-ima/mailman/message/33036180/ [1] https://lkml.org/lkml/2019/9/10/393
Showing the changes to include/linux (1 of 2 files). Show all
Unified · Split
| @@ -23,6 +23,7 @@ extern int ima_read_file(struct file *file, enum kernel_read_file_id id); · 22 unmodified lines | ||
| 23 | 23 | extern int ima_post_read_file(struct file *file, void *buf, loff_t size, |
| 24 | 24 | enum kernel_read_file_id id); |
| 25 | 25 | extern void ima_post_path_mknod(struct dentry *dentry); |
| 26 | +extern int ima_file_hash(struct file *file, char *buf, size_t buf_size); | |
| 26 | 27 | extern void ima_kexec_cmdline(const void *buf, int size); |
| 27 | 28 | |
| 28 | 29 | #ifdef CONFIG_IMA_KEXEC |
| @@ -91,6 +92,11 @@ static inline void ima_post_path_mknod(struct dentry *dentry) · 62 unmodified lines | ||
| 91 | 92 | return; |
| 92 | 93 | } |
| 93 | 94 | |
| 95 | +static inline int ima_file_hash(struct file *file, char *buf, size_t buf_size) | |
| 96 | +{ | |
| 97 | + return -EOPNOTSUPP; | |
| 98 | +} | |
| 99 | + | |
| 94 | 100 | static inline void ima_kexec_cmdline(const void *buf, int size) {} |
| 95 | 101 | #endif /* CONFIG_IMA */ |
| 96 | 102 | |