History

bpf: Add a BPF helper for getting the IMA hash of an inode

Provide a wrapper function to get the IMA hash of an inode. This helper is useful in fingerprinting files (e.g executables on execution) and using these fingerprints in detections like an executable unlinking itself. Since the ima_inode_hash can sleep, it's only allowed for sleepable LSM hooks.

KP Singh committed 5 years ago

Commit 27672f01 parent 403319b4 files · +50 −0Browse files

Showing the changes to include/uapi (1 of 4 files). Show all

Unified · Split

include/uapi/linux/bpf.h+11−0
@@ -3807,6 +3807,16 @@ union bpf_attr { · 3806 unmodified lines
38073807 * See: **clock_gettime**\ (**CLOCK_MONOTONIC_COARSE**)
38083808 * Return
38093809 * Current *ktime*.
3810+ *
3811+ * long bpf_ima_inode_hash(struct inode *inode, void *dst, u32 size)
3812+ * Description
3813+ * Returns the stored IMA hash of the *inode* (if it's avaialable).
3814+ * If the hash is larger than *size*, then only *size*
3815+ * bytes will be copied to *dst*
3816+ * Return
3817+ * The **hash_algo** is returned on success,
3818+ * **-EOPNOTSUP** if IMA is disabled or **-EINVAL** if
3819+ * invalid arguments are passed.
38103820 */
38113821 #define __BPF_FUNC_MAPPER(FN) \
38123822 FN(unspec), \
@@ -3970,6 +3980,7 @@ union bpf_attr { · 157 unmodified lines
39703980 FN(get_current_task_btf), \
39713981 FN(bprm_opts_set), \
39723982 FN(ktime_get_coarse_ns), \
3983+ FN(ima_inode_hash), \
39733984 /* */
39743985
39753986 /* integer value in 'imm' field of BPF_CALL instruction selects which helper