xref: /linux-6.15/include/linux/ima.h (revision b89999d0)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2008 IBM Corporation
4  * Author: Mimi Zohar <[email protected]>
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 struct linux_binprm;
15 
16 #ifdef CONFIG_IMA
17 extern int ima_bprm_check(struct linux_binprm *bprm);
18 extern int ima_file_check(struct file *file, int mask);
19 extern void ima_post_create_tmpfile(struct inode *inode);
20 extern void ima_file_free(struct file *file);
21 extern int ima_file_mmap(struct file *file, unsigned long prot);
22 extern int ima_file_mprotect(struct vm_area_struct *vma, unsigned long prot);
23 extern int ima_load_data(enum kernel_load_data_id id);
24 extern int ima_read_file(struct file *file, enum kernel_read_file_id id);
25 extern int ima_post_read_file(struct file *file, void *buf, loff_t size,
26 			      enum kernel_read_file_id id);
27 extern void ima_post_path_mknod(struct dentry *dentry);
28 extern int ima_file_hash(struct file *file, char *buf, size_t buf_size);
29 extern void ima_kexec_cmdline(int kernel_fd, const void *buf, int size);
30 
31 #ifdef CONFIG_IMA_KEXEC
32 extern void ima_add_kexec_buffer(struct kimage *image);
33 #endif
34 
35 #ifdef CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT
36 extern bool arch_ima_get_secureboot(void);
37 extern const char * const *arch_get_ima_policy(void);
38 #else
39 static inline bool arch_ima_get_secureboot(void)
40 {
41 	return false;
42 }
43 
44 static inline const char * const *arch_get_ima_policy(void)
45 {
46 	return NULL;
47 }
48 #endif
49 
50 #else
51 static inline int ima_bprm_check(struct linux_binprm *bprm)
52 {
53 	return 0;
54 }
55 
56 static inline int ima_file_check(struct file *file, int mask)
57 {
58 	return 0;
59 }
60 
61 static inline void ima_post_create_tmpfile(struct inode *inode)
62 {
63 }
64 
65 static inline void ima_file_free(struct file *file)
66 {
67 	return;
68 }
69 
70 static inline int ima_file_mmap(struct file *file, unsigned long prot)
71 {
72 	return 0;
73 }
74 
75 static inline int ima_file_mprotect(struct vm_area_struct *vma,
76 				    unsigned long prot)
77 {
78 	return 0;
79 }
80 
81 static inline int ima_load_data(enum kernel_load_data_id id)
82 {
83 	return 0;
84 }
85 
86 static inline int ima_read_file(struct file *file, enum kernel_read_file_id id)
87 {
88 	return 0;
89 }
90 
91 static inline int ima_post_read_file(struct file *file, void *buf, loff_t size,
92 				     enum kernel_read_file_id id)
93 {
94 	return 0;
95 }
96 
97 static inline void ima_post_path_mknod(struct dentry *dentry)
98 {
99 	return;
100 }
101 
102 static inline int ima_file_hash(struct file *file, char *buf, size_t buf_size)
103 {
104 	return -EOPNOTSUPP;
105 }
106 
107 static inline void ima_kexec_cmdline(int kernel_fd, const void *buf, int size) {}
108 #endif /* CONFIG_IMA */
109 
110 #ifndef CONFIG_IMA_KEXEC
111 struct kimage;
112 
113 static inline void ima_add_kexec_buffer(struct kimage *image)
114 {}
115 #endif
116 
117 #ifdef CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS
118 extern void ima_post_key_create_or_update(struct key *keyring,
119 					  struct key *key,
120 					  const void *payload, size_t plen,
121 					  unsigned long flags, bool create);
122 #else
123 static inline void ima_post_key_create_or_update(struct key *keyring,
124 						 struct key *key,
125 						 const void *payload,
126 						 size_t plen,
127 						 unsigned long flags,
128 						 bool create) {}
129 #endif  /* CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS */
130 
131 #ifdef CONFIG_IMA_APPRAISE
132 extern bool is_ima_appraise_enabled(void);
133 extern void ima_inode_post_setattr(struct dentry *dentry);
134 extern int ima_inode_setxattr(struct dentry *dentry, const char *xattr_name,
135 		       const void *xattr_value, size_t xattr_value_len);
136 extern int ima_inode_removexattr(struct dentry *dentry, const char *xattr_name);
137 #else
138 static inline bool is_ima_appraise_enabled(void)
139 {
140 	return 0;
141 }
142 
143 static inline void ima_inode_post_setattr(struct dentry *dentry)
144 {
145 	return;
146 }
147 
148 static inline int ima_inode_setxattr(struct dentry *dentry,
149 				     const char *xattr_name,
150 				     const void *xattr_value,
151 				     size_t xattr_value_len)
152 {
153 	return 0;
154 }
155 
156 static inline int ima_inode_removexattr(struct dentry *dentry,
157 					const char *xattr_name)
158 {
159 	return 0;
160 }
161 #endif /* CONFIG_IMA_APPRAISE */
162 
163 #if defined(CONFIG_IMA_APPRAISE) && defined(CONFIG_INTEGRITY_TRUSTED_KEYRING)
164 extern bool ima_appraise_signature(enum kernel_read_file_id func);
165 #else
166 static inline bool ima_appraise_signature(enum kernel_read_file_id func)
167 {
168 	return false;
169 }
170 #endif /* CONFIG_IMA_APPRAISE && CONFIG_INTEGRITY_TRUSTED_KEYRING */
171 #endif /* _LINUX_IMA_H */
172