1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2008 IBM Corporation
10 #include <linux/kernel_read_file.h>
12 #include <linux/security.h>
13 #include <linux/kexec.h>
14 #include <crypto/hash_info.h>
18 extern enum hash_algo ima_get_current_hash_algo(void);
19 extern int ima_bprm_check(struct linux_binprm *bprm);
20 extern int ima_file_check(struct file *file, int mask);
21 extern void ima_post_create_tmpfile(struct mnt_idmap *idmap,
23 extern void ima_file_free(struct file *file);
24 extern int ima_file_mmap(struct file *file, unsigned long reqprot,
25 unsigned long prot, unsigned long flags);
26 extern int ima_file_mprotect(struct vm_area_struct *vma, unsigned long prot);
27 extern int ima_load_data(enum kernel_load_data_id id, bool contents);
28 extern int ima_post_load_data(char *buf, loff_t size,
29 enum kernel_load_data_id id, char *description);
30 extern int ima_read_file(struct file *file, enum kernel_read_file_id id,
32 extern int ima_post_read_file(struct file *file, void *buf, loff_t size,
33 enum kernel_read_file_id id);
34 extern void ima_post_path_mknod(struct mnt_idmap *idmap,
35 struct dentry *dentry);
36 extern int ima_file_hash(struct file *file, char *buf, size_t buf_size);
37 extern int ima_inode_hash(struct inode *inode, char *buf, size_t buf_size);
38 extern void ima_kexec_cmdline(int kernel_fd, const void *buf, int size);
39 extern int ima_measure_critical_data(const char *event_label,
40 const char *event_name,
41 const void *buf, size_t buf_len,
42 bool hash, u8 *digest, size_t digest_len);
44 #ifdef CONFIG_IMA_APPRAISE_BOOTPARAM
45 extern void ima_appraise_parse_cmdline(void);
47 static inline void ima_appraise_parse_cmdline(void) {}
50 #ifdef CONFIG_IMA_KEXEC
51 extern void ima_add_kexec_buffer(struct kimage *image);
55 static inline enum hash_algo ima_get_current_hash_algo(void)
57 return HASH_ALGO__LAST;
60 static inline int ima_bprm_check(struct linux_binprm *bprm)
65 static inline int ima_file_check(struct file *file, int mask)
70 static inline void ima_post_create_tmpfile(struct mnt_idmap *idmap,
75 static inline void ima_file_free(struct file *file)
80 static inline int ima_file_mmap(struct file *file, unsigned long reqprot,
81 unsigned long prot, unsigned long flags)
86 static inline int ima_file_mprotect(struct vm_area_struct *vma,
92 static inline int ima_load_data(enum kernel_load_data_id id, bool contents)
97 static inline int ima_post_load_data(char *buf, loff_t size,
98 enum kernel_load_data_id id,
104 static inline int ima_read_file(struct file *file, enum kernel_read_file_id id,
110 static inline int ima_post_read_file(struct file *file, void *buf, loff_t size,
111 enum kernel_read_file_id id)
116 static inline void ima_post_path_mknod(struct mnt_idmap *idmap,
117 struct dentry *dentry)
122 static inline int ima_file_hash(struct file *file, char *buf, size_t buf_size)
127 static inline int ima_inode_hash(struct inode *inode, char *buf, size_t buf_size)
132 static inline void ima_kexec_cmdline(int kernel_fd, const void *buf, int size) {}
134 static inline int ima_measure_critical_data(const char *event_label,
135 const char *event_name,
136 const void *buf, size_t buf_len,
137 bool hash, u8 *digest,
143 #endif /* CONFIG_IMA */
145 #ifdef CONFIG_HAVE_IMA_KEXEC
146 int __init ima_free_kexec_buffer(void);
147 int __init ima_get_kexec_buffer(void **addr, size_t *size);
150 #ifdef CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT
151 extern bool arch_ima_get_secureboot(void);
152 extern const char * const *arch_get_ima_policy(void);
154 static inline bool arch_ima_get_secureboot(void)
159 static inline const char * const *arch_get_ima_policy(void)
165 #ifndef CONFIG_IMA_KEXEC
168 static inline void ima_add_kexec_buffer(struct kimage *image)
172 #ifdef CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS
173 extern void ima_post_key_create_or_update(struct key *keyring,
175 const void *payload, size_t plen,
176 unsigned long flags, bool create);
178 static inline void ima_post_key_create_or_update(struct key *keyring,
184 #endif /* CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS */
186 #ifdef CONFIG_IMA_APPRAISE
187 extern bool is_ima_appraise_enabled(void);
188 extern void ima_inode_post_setattr(struct mnt_idmap *idmap,
189 struct dentry *dentry);
190 extern int ima_inode_setxattr(struct dentry *dentry, const char *xattr_name,
191 const void *xattr_value, size_t xattr_value_len);
192 extern int ima_inode_set_acl(struct mnt_idmap *idmap,
193 struct dentry *dentry, const char *acl_name,
194 struct posix_acl *kacl);
195 static inline int ima_inode_remove_acl(struct mnt_idmap *idmap,
196 struct dentry *dentry,
197 const char *acl_name)
199 return ima_inode_set_acl(idmap, dentry, acl_name, NULL);
201 extern int ima_inode_removexattr(struct dentry *dentry, const char *xattr_name);
203 static inline bool is_ima_appraise_enabled(void)
208 static inline void ima_inode_post_setattr(struct mnt_idmap *idmap,
209 struct dentry *dentry)
214 static inline int ima_inode_setxattr(struct dentry *dentry,
215 const char *xattr_name,
216 const void *xattr_value,
217 size_t xattr_value_len)
222 static inline int ima_inode_set_acl(struct mnt_idmap *idmap,
223 struct dentry *dentry, const char *acl_name,
224 struct posix_acl *kacl)
230 static inline int ima_inode_removexattr(struct dentry *dentry,
231 const char *xattr_name)
236 static inline int ima_inode_remove_acl(struct mnt_idmap *idmap,
237 struct dentry *dentry,
238 const char *acl_name)
242 #endif /* CONFIG_IMA_APPRAISE */
244 #if defined(CONFIG_IMA_APPRAISE) && defined(CONFIG_INTEGRITY_TRUSTED_KEYRING)
245 extern bool ima_appraise_signature(enum kernel_read_file_id func);
247 static inline bool ima_appraise_signature(enum kernel_read_file_id func)
251 #endif /* CONFIG_IMA_APPRAISE && CONFIG_INTEGRITY_TRUSTED_KEYRING */
252 #endif /* _LINUX_IMA_H */