blob: 8fa7bcfb2da2c0e3d98ca6e03abed1f26193bcf4 [file] [log] [blame]
Thomas Gleixnerb886d83c2019-06-01 10:08:55 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Mimi Zohar6146f0d2009-02-04 09:06:57 -05002/*
3 * Copyright (C) 2008 IBM Corporation
4 * Author: Mimi Zohar <zohar@us.ibm.com>
Mimi Zohar6146f0d2009-02-04 09:06:57 -05005 */
6
Mimi Zohar6146f0d2009-02-04 09:06:57 -05007#ifndef _LINUX_IMA_H
8#define _LINUX_IMA_H
9
Scott Brandenb89999d02020-10-02 10:38:15 -070010#include <linux/kernel_read_file.h>
Mimi Zohared850a52009-02-10 23:01:19 -050011#include <linux/fs.h>
Mimi Zohar16c267a2018-07-13 14:05:58 -040012#include <linux/security.h>
Mimi Zohar7b8589c2016-12-19 16:22:48 -080013#include <linux/kexec.h>
Mimi Zohared850a52009-02-10 23:01:19 -050014struct linux_binprm;
15
Mimi Zohar3323eec2009-02-04 09:06:58 -050016#ifdef CONFIG_IMA
17extern int ima_bprm_check(struct linux_binprm *bprm);
Al Viro6035a272018-06-08 13:40:10 -040018extern int ima_file_check(struct file *file, int mask);
Mimi Zoharfdb24102019-01-22 14:06:49 -060019extern void ima_post_create_tmpfile(struct inode *inode);
Mimi Zohar3323eec2009-02-04 09:06:58 -050020extern void ima_file_free(struct file *file);
21extern int ima_file_mmap(struct file *file, unsigned long prot);
Mimi Zohar8eb613c2020-05-03 01:00:02 -040022extern int ima_file_mprotect(struct vm_area_struct *vma, unsigned long prot);
Kees Cookb64fcae2020-10-02 10:38:20 -070023extern int ima_load_data(enum kernel_load_data_id id, bool contents);
24extern int ima_post_load_data(char *buf, loff_t size,
25 enum kernel_load_data_id id, char *description);
Kees Cook2039bda2020-10-02 10:38:23 -070026extern int ima_read_file(struct file *file, enum kernel_read_file_id id,
27 bool contents);
Mimi Zoharcf222212016-01-14 17:57:47 -050028extern int ima_post_read_file(struct file *file, void *buf, loff_t size,
29 enum kernel_read_file_id id);
Mimi Zohar05d1a712016-02-29 19:52:05 -050030extern void ima_post_path_mknod(struct dentry *dentry);
Florent Revest6beea7a2020-01-13 10:42:44 +010031extern int ima_file_hash(struct file *file, char *buf, size_t buf_size);
Tyler Hicks48341772020-07-09 01:19:11 -050032extern void ima_kexec_cmdline(int kernel_fd, const void *buf, int size);
Mimi Zohar3323eec2009-02-04 09:06:58 -050033
Mimi Zohar7b8589c2016-12-19 16:22:48 -080034#ifdef CONFIG_IMA_KEXEC
35extern void ima_add_kexec_buffer(struct kimage *image);
36#endif
37
Nayna Jain9e2b4be2020-03-08 20:57:51 -040038#ifdef CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT
Nayna Jain0914ade2018-10-09 23:00:33 +053039extern bool arch_ima_get_secureboot(void);
Eric Richterd9580832018-10-09 23:00:37 +053040extern const char * const *arch_get_ima_policy(void);
Nayna Jain0914ade2018-10-09 23:00:33 +053041#else
42static inline bool arch_ima_get_secureboot(void)
43{
44 return false;
45}
Nayna Jain0914ade2018-10-09 23:00:33 +053046
Nayna Jain61917062018-10-09 23:00:36 +053047static inline const char * const *arch_get_ima_policy(void)
48{
49 return NULL;
50}
Eric Richterd9580832018-10-09 23:00:37 +053051#endif
Nayna Jain61917062018-10-09 23:00:36 +053052
Mimi Zohar3323eec2009-02-04 09:06:58 -050053#else
Mimi Zohar6146f0d2009-02-04 09:06:57 -050054static inline int ima_bprm_check(struct linux_binprm *bprm)
55{
56 return 0;
57}
58
Al Viro6035a272018-06-08 13:40:10 -040059static inline int ima_file_check(struct file *file, int mask)
Mimi Zohar6146f0d2009-02-04 09:06:57 -050060{
61 return 0;
62}
63
Mimi Zoharfdb24102019-01-22 14:06:49 -060064static inline void ima_post_create_tmpfile(struct inode *inode)
65{
66}
67
Mimi Zohar6146f0d2009-02-04 09:06:57 -050068static inline void ima_file_free(struct file *file)
69{
70 return;
71}
72
73static inline int ima_file_mmap(struct file *file, unsigned long prot)
74{
75 return 0;
76}
Mimi Zohar9957a502011-03-09 22:57:53 -050077
Mimi Zohar8eb613c2020-05-03 01:00:02 -040078static inline int ima_file_mprotect(struct vm_area_struct *vma,
79 unsigned long prot)
80{
81 return 0;
82}
83
Kees Cookb64fcae2020-10-02 10:38:20 -070084static inline int ima_load_data(enum kernel_load_data_id id, bool contents)
85{
86 return 0;
87}
88
89static inline int ima_post_load_data(char *buf, loff_t size,
90 enum kernel_load_data_id id,
91 char *description)
Mimi Zohar16c267a2018-07-13 14:05:58 -040092{
93 return 0;
94}
95
Kees Cook2039bda2020-10-02 10:38:23 -070096static inline int ima_read_file(struct file *file, enum kernel_read_file_id id,
97 bool contents)
Mimi Zohar39eeb4f2016-01-30 22:23:26 -050098{
99 return 0;
100}
101
Mimi Zoharcf222212016-01-14 17:57:47 -0500102static inline int ima_post_read_file(struct file *file, void *buf, loff_t size,
103 enum kernel_read_file_id id)
104{
105 return 0;
106}
107
Mimi Zohar05d1a712016-02-29 19:52:05 -0500108static inline void ima_post_path_mknod(struct dentry *dentry)
109{
110 return;
111}
112
Florent Revest6beea7a2020-01-13 10:42:44 +0100113static inline int ima_file_hash(struct file *file, char *buf, size_t buf_size)
114{
115 return -EOPNOTSUPP;
116}
117
Tyler Hicks48341772020-07-09 01:19:11 -0500118static inline void ima_kexec_cmdline(int kernel_fd, const void *buf, int size) {}
Paul Bollee05a4f42013-03-25 21:12:27 +0100119#endif /* CONFIG_IMA */
Mimi Zohar9957a502011-03-09 22:57:53 -0500120
Mimi Zohar7b8589c2016-12-19 16:22:48 -0800121#ifndef CONFIG_IMA_KEXEC
122struct kimage;
123
124static inline void ima_add_kexec_buffer(struct kimage *image)
125{}
126#endif
127
Lakshmi Ramasubramanianea789792020-01-08 08:05:08 -0800128#ifdef CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS
Lakshmi Ramasubramaniancb1aa382019-12-11 08:47:05 -0800129extern void ima_post_key_create_or_update(struct key *keyring,
130 struct key *key,
131 const void *payload, size_t plen,
132 unsigned long flags, bool create);
133#else
134static inline void ima_post_key_create_or_update(struct key *keyring,
135 struct key *key,
136 const void *payload,
137 size_t plen,
138 unsigned long flags,
139 bool create) {}
Lakshmi Ramasubramanianea789792020-01-08 08:05:08 -0800140#endif /* CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS */
Lakshmi Ramasubramaniancb1aa382019-12-11 08:47:05 -0800141
Mimi Zohar9957a502011-03-09 22:57:53 -0500142#ifdef CONFIG_IMA_APPRAISE
Mimi Zohar6f6723e2017-04-24 22:43:52 -0400143extern bool is_ima_appraise_enabled(void);
Mimi Zohar9957a502011-03-09 22:57:53 -0500144extern void ima_inode_post_setattr(struct dentry *dentry);
Mimi Zohar42c63332011-03-10 18:54:15 -0500145extern int ima_inode_setxattr(struct dentry *dentry, const char *xattr_name,
146 const void *xattr_value, size_t xattr_value_len);
147extern int ima_inode_removexattr(struct dentry *dentry, const char *xattr_name);
Mimi Zohar9957a502011-03-09 22:57:53 -0500148#else
Mimi Zohar6f6723e2017-04-24 22:43:52 -0400149static inline bool is_ima_appraise_enabled(void)
150{
151 return 0;
152}
153
Mimi Zohar9957a502011-03-09 22:57:53 -0500154static inline void ima_inode_post_setattr(struct dentry *dentry)
155{
156 return;
157}
Mimi Zohar42c63332011-03-10 18:54:15 -0500158
159static inline int ima_inode_setxattr(struct dentry *dentry,
160 const char *xattr_name,
161 const void *xattr_value,
162 size_t xattr_value_len)
163{
164 return 0;
165}
166
167static inline int ima_inode_removexattr(struct dentry *dentry,
168 const char *xattr_name)
169{
170 return 0;
171}
Paul Bollee05a4f42013-03-25 21:12:27 +0100172#endif /* CONFIG_IMA_APPRAISE */
Matthew Garrett29d3c1c2019-08-19 17:18:01 -0700173
174#if defined(CONFIG_IMA_APPRAISE) && defined(CONFIG_INTEGRITY_TRUSTED_KEYRING)
175extern bool ima_appraise_signature(enum kernel_read_file_id func);
176#else
177static inline bool ima_appraise_signature(enum kernel_read_file_id func)
178{
179 return false;
180}
181#endif /* CONFIG_IMA_APPRAISE && CONFIG_INTEGRITY_TRUSTED_KEYRING */
Mimi Zohar6146f0d2009-02-04 09:06:57 -0500182#endif /* _LINUX_IMA_H */