History

ima: add the ability to query the cached hash of a given file

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

Florent Revest committed 6 years ago

Commit 6beea7a1 parent 5350ceb2 files · +55 −0Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/ima.h+6−0
@@ -23,6 +23,7 @@ extern int ima_read_file(struct file *file, enum kernel_read_file_id id); · 22 unmodified lines
2323 extern int ima_post_read_file(struct file *file, void *buf, loff_t size,
2424 enum kernel_read_file_id id);
2525 extern void ima_post_path_mknod(struct dentry *dentry);
26+extern int ima_file_hash(struct file *file, char *buf, size_t buf_size);
2627 extern void ima_kexec_cmdline(const void *buf, int size);
2728
2829 #ifdef CONFIG_IMA_KEXEC
@@ -91,6 +92,11 @@ static inline void ima_post_path_mknod(struct dentry *dentry) · 62 unmodified lines
9192 return;
9293 }
9394
95+static inline int ima_file_hash(struct file *file, char *buf, size_t buf_size)
96+{
97+ return -EOPNOTSUPP;
98+}
99+
94100 static inline void ima_kexec_cmdline(const void *buf, int size) {}
95101 #endif /* CONFIG_IMA */
96102