diff options
Diffstat (limited to 'security/integrity/ima/ima.h')
| -rw-r--r-- | security/integrity/ima/ima.h | 79 |
1 files changed, 23 insertions, 56 deletions
diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index 079a85dc37b..08408bd7146 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h | |||
| @@ -24,23 +24,21 @@ | |||
| 24 | #include <linux/tpm.h> | 24 | #include <linux/tpm.h> |
| 25 | #include <linux/audit.h> | 25 | #include <linux/audit.h> |
| 26 | 26 | ||
| 27 | #include "../integrity.h" | ||
| 28 | |||
| 29 | enum ima_show_type { IMA_SHOW_BINARY, IMA_SHOW_ASCII }; | 27 | enum ima_show_type { IMA_SHOW_BINARY, IMA_SHOW_ASCII }; |
| 30 | enum tpm_pcrs { TPM_PCR0 = 0, TPM_PCR8 = 8 }; | 28 | enum tpm_pcrs { TPM_PCR0 = 0, TPM_PCR8 = 8 }; |
| 31 | 29 | ||
| 32 | /* digest size for IMA, fits SHA1 or MD5 */ | 30 | /* digest size for IMA, fits SHA1 or MD5 */ |
| 33 | #define IMA_DIGEST_SIZE SHA1_DIGEST_SIZE | 31 | #define IMA_DIGEST_SIZE 20 |
| 34 | #define IMA_EVENT_NAME_LEN_MAX 255 | 32 | #define IMA_EVENT_NAME_LEN_MAX 255 |
| 35 | 33 | ||
| 36 | #define IMA_HASH_BITS 9 | 34 | #define IMA_HASH_BITS 9 |
| 37 | #define IMA_MEASURE_HTABLE_SIZE (1 << IMA_HASH_BITS) | 35 | #define IMA_MEASURE_HTABLE_SIZE (1 << IMA_HASH_BITS) |
| 38 | 36 | ||
| 39 | /* set during initialization */ | 37 | /* set during initialization */ |
| 38 | extern int iint_initialized; | ||
| 40 | extern int ima_initialized; | 39 | extern int ima_initialized; |
| 41 | extern int ima_used_chip; | 40 | extern int ima_used_chip; |
| 42 | extern char *ima_hash; | 41 | extern char *ima_hash; |
| 43 | extern int ima_appraise; | ||
| 44 | 42 | ||
| 45 | /* IMA inode template definition */ | 43 | /* IMA inode template definition */ |
| 46 | struct ima_template_data { | 44 | struct ima_template_data { |
| @@ -62,19 +60,10 @@ struct ima_queue_entry { | |||
| 62 | }; | 60 | }; |
| 63 | extern struct list_head ima_measurements; /* list of all measurements */ | 61 | extern struct list_head ima_measurements; /* list of all measurements */ |
| 64 | 62 | ||
| 65 | #ifdef CONFIG_IMA_AUDIT | ||
| 66 | /* declarations */ | 63 | /* declarations */ |
| 67 | void integrity_audit_msg(int audit_msgno, struct inode *inode, | 64 | void integrity_audit_msg(int audit_msgno, struct inode *inode, |
| 68 | const unsigned char *fname, const char *op, | 65 | const unsigned char *fname, const char *op, |
| 69 | const char *cause, int result, int info); | 66 | const char *cause, int result, int info); |
| 70 | #else | ||
| 71 | static inline void integrity_audit_msg(int audit_msgno, struct inode *inode, | ||
| 72 | const unsigned char *fname, | ||
| 73 | const char *op, const char *cause, | ||
| 74 | int result, int info) | ||
| 75 | { | ||
| 76 | } | ||
| 77 | #endif | ||
| 78 | 67 | ||
| 79 | /* Internal IMA function definitions */ | 68 | /* Internal IMA function definitions */ |
| 80 | int ima_init(void); | 69 | int ima_init(void); |
| @@ -107,66 +96,44 @@ static inline unsigned long ima_hash_key(u8 *digest) | |||
| 107 | return hash_long(*digest, IMA_HASH_BITS); | 96 | return hash_long(*digest, IMA_HASH_BITS); |
| 108 | } | 97 | } |
| 109 | 98 | ||
| 99 | /* iint cache flags */ | ||
| 100 | #define IMA_MEASURED 0x01 | ||
| 101 | |||
| 102 | /* integrity data associated with an inode */ | ||
| 103 | struct ima_iint_cache { | ||
| 104 | struct rb_node rb_node; /* rooted in ima_iint_tree */ | ||
| 105 | struct inode *inode; /* back pointer to inode in question */ | ||
| 106 | u64 version; /* track inode changes */ | ||
| 107 | unsigned char flags; | ||
| 108 | u8 digest[IMA_DIGEST_SIZE]; | ||
| 109 | struct mutex mutex; /* protects: version, flags, digest */ | ||
| 110 | }; | ||
| 111 | |||
| 110 | /* LIM API function definitions */ | 112 | /* LIM API function definitions */ |
| 111 | int ima_get_action(struct inode *inode, int mask, int function); | ||
| 112 | int ima_must_measure(struct inode *inode, int mask, int function); | 113 | int ima_must_measure(struct inode *inode, int mask, int function); |
| 113 | int ima_collect_measurement(struct integrity_iint_cache *iint, | 114 | int ima_collect_measurement(struct ima_iint_cache *iint, struct file *file); |
| 114 | struct file *file); | 115 | void ima_store_measurement(struct ima_iint_cache *iint, struct file *file, |
| 115 | void ima_store_measurement(struct integrity_iint_cache *iint, struct file *file, | ||
| 116 | const unsigned char *filename); | ||
| 117 | void ima_audit_measurement(struct integrity_iint_cache *iint, | ||
| 118 | const unsigned char *filename); | 116 | const unsigned char *filename); |
| 119 | int ima_store_template(struct ima_template_entry *entry, int violation, | 117 | int ima_store_template(struct ima_template_entry *entry, int violation, |
| 120 | struct inode *inode); | 118 | struct inode *inode); |
| 121 | void ima_template_show(struct seq_file *m, void *e, enum ima_show_type show); | 119 | void ima_template_show(struct seq_file *m, void *e, |
| 120 | enum ima_show_type show); | ||
| 122 | 121 | ||
| 123 | /* rbtree tree calls to lookup, insert, delete | 122 | /* rbtree tree calls to lookup, insert, delete |
| 124 | * integrity data associated with an inode. | 123 | * integrity data associated with an inode. |
| 125 | */ | 124 | */ |
| 126 | struct integrity_iint_cache *integrity_iint_insert(struct inode *inode); | 125 | struct ima_iint_cache *ima_iint_insert(struct inode *inode); |
| 127 | struct integrity_iint_cache *integrity_iint_find(struct inode *inode); | 126 | struct ima_iint_cache *ima_iint_find(struct inode *inode); |
| 128 | 127 | ||
| 129 | /* IMA policy related functions */ | 128 | /* IMA policy related functions */ |
| 130 | enum ima_hooks { FILE_CHECK = 1, FILE_MMAP, BPRM_CHECK, MODULE_CHECK, POST_SETATTR }; | 129 | enum ima_hooks { FILE_CHECK = 1, FILE_MMAP, BPRM_CHECK }; |
| 131 | 130 | ||
| 132 | int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask, | 131 | int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask); |
| 133 | int flags); | ||
| 134 | void ima_init_policy(void); | 132 | void ima_init_policy(void); |
| 135 | void ima_update_policy(void); | 133 | void ima_update_policy(void); |
| 136 | ssize_t ima_parse_add_rule(char *); | 134 | ssize_t ima_parse_add_rule(char *); |
| 137 | void ima_delete_rules(void); | 135 | void ima_delete_rules(void); |
| 138 | 136 | ||
| 139 | /* Appraise integrity measurements */ | ||
| 140 | #define IMA_APPRAISE_ENFORCE 0x01 | ||
| 141 | #define IMA_APPRAISE_FIX 0x02 | ||
| 142 | #define IMA_APPRAISE_MODULES 0x04 | ||
| 143 | |||
| 144 | #ifdef CONFIG_IMA_APPRAISE | ||
| 145 | int ima_appraise_measurement(struct integrity_iint_cache *iint, | ||
| 146 | struct file *file, const unsigned char *filename); | ||
| 147 | int ima_must_appraise(struct inode *inode, int mask, enum ima_hooks func); | ||
| 148 | void ima_update_xattr(struct integrity_iint_cache *iint, struct file *file); | ||
| 149 | |||
| 150 | #else | ||
| 151 | static inline int ima_appraise_measurement(struct integrity_iint_cache *iint, | ||
| 152 | struct file *file, | ||
| 153 | const unsigned char *filename) | ||
| 154 | { | ||
| 155 | return INTEGRITY_UNKNOWN; | ||
| 156 | } | ||
| 157 | |||
| 158 | static inline int ima_must_appraise(struct inode *inode, int mask, | ||
| 159 | enum ima_hooks func) | ||
| 160 | { | ||
| 161 | return 0; | ||
| 162 | } | ||
| 163 | |||
| 164 | static inline void ima_update_xattr(struct integrity_iint_cache *iint, | ||
| 165 | struct file *file) | ||
| 166 | { | ||
| 167 | } | ||
| 168 | #endif | ||
| 169 | |||
| 170 | /* LSM based policy rules require audit */ | 137 | /* LSM based policy rules require audit */ |
| 171 | #ifdef CONFIG_IMA_LSM_RULES | 138 | #ifdef CONFIG_IMA_LSM_RULES |
| 172 | 139 | ||
