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