Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2008 IBM Corporation
4 * Author: Mimi Zohar <zohar@us.ibm.com>
5 */
6
7#ifndef _LINUX_IMA_H
8#define _LINUX_IMA_H
9
10#include <linux/kernel_read_file.h>
11#include <linux/fs.h>
12#include <linux/security.h>
13#include <linux/kexec.h>
14#include <linux/secure_boot.h>
15#include <crypto/hash_info.h>
16struct linux_binprm;
17
18#ifdef CONFIG_IMA
19extern enum hash_algo ima_get_current_hash_algo(void);
20extern int ima_file_hash(struct file *file, char *buf, size_t buf_size);
21extern int ima_inode_hash(struct inode *inode, char *buf, size_t buf_size);
22extern void ima_kexec_cmdline(int kernel_fd, const void *buf, int size);
23extern int ima_measure_critical_data(const char *event_label,
24 const char *event_name,
25 const void *buf, size_t buf_len,
26 bool hash, u8 *digest, size_t digest_len);
27
28#ifdef CONFIG_IMA_APPRAISE_BOOTPARAM
29extern void ima_appraise_parse_cmdline(void);
30#else
31static inline void ima_appraise_parse_cmdline(void) {}
32#endif
33
34#ifdef CONFIG_IMA_KEXEC
35extern void ima_add_kexec_buffer(struct kimage *image);
36extern void ima_kexec_post_load(struct kimage *image);
37#else
38static inline void ima_kexec_post_load(struct kimage *image) {}
39#endif
40
41#else
42static inline enum hash_algo ima_get_current_hash_algo(void)
43{
44 return HASH_ALGO__LAST;
45}
46
47static inline int ima_file_hash(struct file *file, char *buf, size_t buf_size)
48{
49 return -EOPNOTSUPP;
50}
51
52static inline int ima_inode_hash(struct inode *inode, char *buf, size_t buf_size)
53{
54 return -EOPNOTSUPP;
55}
56
57static inline void ima_kexec_cmdline(int kernel_fd, const void *buf, int size) {}
58
59static inline int ima_measure_critical_data(const char *event_label,
60 const char *event_name,
61 const void *buf, size_t buf_len,
62 bool hash, u8 *digest,
63 size_t digest_len)
64{
65 return -ENOENT;
66}
67
68#endif /* CONFIG_IMA */
69
70#ifdef CONFIG_HAVE_IMA_KEXEC
71int __init ima_free_kexec_buffer(void);
72int __init ima_get_kexec_buffer(void **addr, size_t *size);
73int ima_validate_range(phys_addr_t phys, size_t size);
74#endif
75
76#ifdef CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT
77extern const char * const *arch_get_ima_policy(void);
78#else
79static inline const char * const *arch_get_ima_policy(void)
80{
81 return NULL;
82}
83#endif
84
85#ifndef CONFIG_IMA_KEXEC
86struct kimage;
87
88static inline void ima_add_kexec_buffer(struct kimage *image)
89{}
90#endif
91
92#ifdef CONFIG_IMA_APPRAISE
93extern bool is_ima_appraise_enabled(void);
94#else
95static inline bool is_ima_appraise_enabled(void)
96{
97 return 0;
98}
99#endif /* CONFIG_IMA_APPRAISE */
100
101#if defined(CONFIG_IMA_APPRAISE) && defined(CONFIG_INTEGRITY_TRUSTED_KEYRING)
102extern bool ima_appraise_signature(enum kernel_read_file_id func);
103#else
104static inline bool ima_appraise_signature(enum kernel_read_file_id func)
105{
106 return false;
107}
108#endif /* CONFIG_IMA_APPRAISE && CONFIG_INTEGRITY_TRUSTED_KEYRING */
109#endif /* _LINUX_IMA_H */