1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (C) 2005,2006,2007,2008 IBM Corporation 4 * 5 * Authors: 6 * Reiner Sailer <sailer@watson.ibm.com> 7 * Mimi Zohar <zohar@us.ibm.com> 8 * 9 * File: ima.h 10 * internal Integrity Measurement Architecture (IMA) definitions 11 */ 12 13 #ifndef __LINUX_IMA_H 14 #define __LINUX_IMA_H 15 16 #include <linux/types.h> 17 #include <linux/crypto.h> 18 #include <linux/fs.h> 19 #include <linux/security.h> 20 #include <linux/hash.h> 21 #include <linux/tpm.h> 22 #include <linux/audit.h> 23 #include <crypto/hash_info.h> 24 25 #include "../integrity.h" 26 27 enum ima_show_type { IMA_SHOW_BINARY, IMA_SHOW_BINARY_NO_FIELD_LEN, 28 IMA_SHOW_BINARY_OLD_STRING_FMT, IMA_SHOW_ASCII }; 29 enum tpm_pcrs { TPM_PCR0 = 0, TPM_PCR8 = 8, TPM_PCR10 = 10 }; 30 31 /* 32 * BINARY: current binary measurements list 33 * BINARY_STAGED: staged binary measurements list 34 * BINARY_FULL: binary measurements list since IMA init (lost after kexec) 35 */ 36 enum binary_lists { 37 BINARY, BINARY_STAGED, BINARY_FULL, BINARY__LAST 38 }; 39 40 /* digest size for IMA, fits SHA1 or MD5 */ 41 #define IMA_DIGEST_SIZE SHA1_DIGEST_SIZE 42 #define IMA_EVENT_NAME_LEN_MAX 255 43 44 #define IMA_HASH_BITS 10 45 #define IMA_MEASURE_HTABLE_SIZE (1 << IMA_HASH_BITS) 46 47 #define IMA_TEMPLATE_FIELD_ID_MAX_LEN 16 48 #define IMA_TEMPLATE_NUM_FIELDS_MAX 15 49 50 #define IMA_TEMPLATE_IMA_NAME "ima" 51 #define IMA_TEMPLATE_IMA_FMT "d|n" 52 53 #define NR_BANKS(chip) ((chip != NULL) ? chip->nr_allocated_banks : 0) 54 55 /* current content of the policy */ 56 extern int ima_policy_flag; 57 58 extern struct mutex ima_write_mutex; 59 60 /* bitset of digests algorithms allowed in the setxattr hook */ 61 extern atomic_t ima_setxattr_allowed_hash_algorithms; 62 63 /* IMA hash algorithm description */ 64 struct ima_algo_desc { 65 struct crypto_shash *tfm; 66 enum hash_algo algo; 67 unsigned int digest_size; 68 }; 69 70 /* set during initialization */ 71 extern int ima_hash_algo __ro_after_init; 72 extern int ima_sha1_idx __ro_after_init; 73 extern int ima_hash_algo_idx __ro_after_init; 74 extern int ima_extra_slots __ro_after_init; 75 extern struct ima_algo_desc *ima_algo_array __ro_after_init; 76 77 extern int ima_appraise; 78 extern struct tpm_chip *ima_tpm_chip; 79 extern const char boot_aggregate_name[]; 80 extern const char boot_aggregate_late_name[]; 81 82 /* IMA event related data */ 83 struct ima_event_data { 84 struct ima_iint_cache *iint; 85 struct file *file; 86 const unsigned char *filename; 87 struct evm_ima_xattr_data *xattr_value; 88 int xattr_len; 89 const struct modsig *modsig; 90 const char *violation; 91 const void *buf; 92 int buf_len; 93 }; 94 95 /* IMA template field data definition */ 96 struct ima_field_data { 97 u8 *data; 98 u32 len; 99 }; 100 101 /* IMA template field definition */ 102 struct ima_template_field { 103 const char field_id[IMA_TEMPLATE_FIELD_ID_MAX_LEN]; 104 int (*field_init)(struct ima_event_data *event_data, 105 struct ima_field_data *field_data); 106 void (*field_show)(struct seq_file *m, enum ima_show_type show, 107 struct ima_field_data *field_data); 108 }; 109 110 /* IMA template descriptor definition */ 111 struct ima_template_desc { 112 struct list_head list; 113 char *name; 114 char *fmt; 115 int num_fields; 116 const struct ima_template_field **fields; 117 }; 118 119 struct ima_template_entry { 120 int pcr; 121 struct tpm_digest *digests; 122 struct ima_template_desc *template_desc; /* template descriptor */ 123 u32 template_data_len; 124 struct ima_field_data template_data[]; /* template related data */ 125 }; 126 127 struct ima_queue_entry { 128 struct hlist_node hnext; /* place in hash collision list */ 129 struct list_head later; /* place in ima_measurements list */ 130 struct ima_template_entry *entry; 131 }; 132 extern struct list_head ima_measurements; /* list of all measurements */ 133 extern struct list_head ima_measurements_staged; /* list of staged meas. */ 134 135 /* Some details preceding the binary serialized measurement list */ 136 struct ima_kexec_hdr { 137 u16 version; 138 u16 _reserved0; 139 u32 _reserved1; 140 u64 buffer_size; 141 u64 count; 142 }; 143 144 /* IMA iint action cache flags */ 145 #define IMA_MEASURE 0x00000001 146 #define IMA_MEASURED 0x00000002 147 #define IMA_APPRAISE 0x00000004 148 #define IMA_APPRAISED 0x00000008 149 /*#define IMA_COLLECT 0x00000010 do not use this flag */ 150 #define IMA_COLLECTED 0x00000020 151 #define IMA_AUDIT 0x00000040 152 #define IMA_AUDITED 0x00000080 153 #define IMA_HASH 0x00000100 154 #define IMA_HASHED 0x00000200 155 156 /* IMA iint policy rule cache flags */ 157 #define IMA_NONACTION_FLAGS 0xff000000 158 #define IMA_DIGSIG_REQUIRED 0x01000000 159 #define IMA_PERMIT_DIRECTIO 0x02000000 160 #define IMA_NEW_FILE 0x04000000 161 #define IMA_SIGV3_REQUIRED 0x08000000 162 #define IMA_FAIL_UNVERIFIABLE_SIGS 0x10000000 163 #define IMA_MODSIG_ALLOWED 0x20000000 164 #define IMA_CHECK_BLACKLIST 0x40000000 165 #define IMA_VERITY_REQUIRED 0x80000000 166 167 /* Exclude non-action flags which are not rule-specific. */ 168 #define IMA_NONACTION_RULE_FLAGS (IMA_NONACTION_FLAGS & ~IMA_NEW_FILE) 169 170 #define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT | \ 171 IMA_HASH | IMA_APPRAISE_SUBMASK) 172 #define IMA_DONE_MASK (IMA_MEASURED | IMA_APPRAISED | IMA_AUDITED | \ 173 IMA_HASHED | IMA_COLLECTED | \ 174 IMA_APPRAISED_SUBMASK) 175 176 /* IMA iint subaction appraise cache flags */ 177 #define IMA_FILE_APPRAISE 0x00001000 178 #define IMA_FILE_APPRAISED 0x00002000 179 #define IMA_MMAP_APPRAISE 0x00004000 180 #define IMA_MMAP_APPRAISED 0x00008000 181 #define IMA_BPRM_APPRAISE 0x00010000 182 #define IMA_BPRM_APPRAISED 0x00020000 183 #define IMA_READ_APPRAISE 0x00040000 184 #define IMA_READ_APPRAISED 0x00080000 185 #define IMA_CREDS_APPRAISE 0x00100000 186 #define IMA_CREDS_APPRAISED 0x00200000 187 #define IMA_APPRAISE_SUBMASK (IMA_FILE_APPRAISE | IMA_MMAP_APPRAISE | \ 188 IMA_BPRM_APPRAISE | IMA_READ_APPRAISE | \ 189 IMA_CREDS_APPRAISE) 190 #define IMA_APPRAISED_SUBMASK (IMA_FILE_APPRAISED | IMA_MMAP_APPRAISED | \ 191 IMA_BPRM_APPRAISED | IMA_READ_APPRAISED | \ 192 IMA_CREDS_APPRAISED) 193 194 /* 195 * IMA iint cache atomic_flags 196 * 197 * IMA_CHANGE_ATTR - indicates that chATTR() was called (chmod, chown, chgrp) 198 * and file attributes have changed. On file open, it causes IMA to clear 199 * iint->flags to re-evaluate policy and perform IMA functions again. 200 * 201 * IMA_CHANGE_XATTR - indicates that setxattr or removexattr was called and 202 * extended attributes have changed. On file open, it causes IMA to clear 203 * iint->flags IMA_DONE_MASK to re-appraise. 204 * 205 * IMA_UPDATE_XATTR - indicates that security.ima needs to be updated. It is 206 * cleared if file policy changes and no update is needed. 207 * 208 * IMA_DIGSIG - indicates that file security.ima has signature and file 209 * security.ima must not update on file close. 210 * 211 * IMA_MAY_EMIT_TOMTOU - indicates to add Time-of-Measure-Time-of-Use (ToMToU) 212 * integrity violation (a file that is already opened for read is opened for 213 * write) to the measurement list and to also emit an audit message. 214 * 215 * IMA_EMITTED_OPENWRITERS - indicates to add open-writers integrity violation 216 * (a file that is already opened for write is opened for read) to the 217 * measurement list and to also emit an audit message. 218 * 219 */ 220 #define IMA_CHANGE_XATTR 0 221 #define IMA_UPDATE_XATTR 1 222 #define IMA_CHANGE_ATTR 2 223 #define IMA_DIGSIG 3 224 #define IMA_MAY_EMIT_TOMTOU 4 225 #define IMA_EMITTED_OPENWRITERS 5 226 227 /* IMA integrity metadata associated with an inode */ 228 struct ima_iint_cache { 229 struct mutex mutex; /* protects: version, flags, digest */ 230 struct integrity_inode_attributes real_inode; 231 unsigned long flags; 232 unsigned long measured_pcrs; 233 unsigned long atomic_flags; 234 enum integrity_status ima_file_status:4; 235 enum integrity_status ima_mmap_status:4; 236 enum integrity_status ima_bprm_status:4; 237 enum integrity_status ima_read_status:4; 238 enum integrity_status ima_creds_status:4; 239 struct ima_digest_data *ima_hash; 240 }; 241 242 extern struct lsm_blob_sizes ima_blob_sizes; 243 244 static inline struct ima_iint_cache * 245 ima_inode_get_iint(const struct inode *inode) 246 { 247 struct ima_iint_cache **iint_sec; 248 249 if (unlikely(!inode->i_security)) 250 return NULL; 251 252 iint_sec = inode->i_security + ima_blob_sizes.lbs_inode; 253 return *iint_sec; 254 } 255 256 static inline void ima_inode_set_iint(const struct inode *inode, 257 struct ima_iint_cache *iint) 258 { 259 struct ima_iint_cache **iint_sec; 260 261 if (unlikely(!inode->i_security)) 262 return; 263 264 iint_sec = inode->i_security + ima_blob_sizes.lbs_inode; 265 *iint_sec = iint; 266 } 267 268 struct ima_iint_cache *ima_iint_find(struct inode *inode); 269 struct ima_iint_cache *ima_inode_get(struct inode *inode); 270 void ima_inode_free_rcu(void *inode_security); 271 void __init ima_iintcache_init(void); 272 273 extern const int read_idmap[]; 274 275 #ifdef CONFIG_HAVE_IMA_KEXEC 276 void ima_load_kexec_buffer(void); 277 #else 278 static inline void ima_load_kexec_buffer(void) {} 279 #endif /* CONFIG_HAVE_IMA_KEXEC */ 280 281 #ifdef CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS 282 void ima_post_key_create_or_update(struct key *keyring, struct key *key, 283 const void *payload, size_t plen, 284 unsigned long flags, bool create); 285 #endif 286 287 #ifdef CONFIG_IMA_KEXEC 288 void ima_measure_kexec_event(const char *event_name); 289 #else 290 static inline void ima_measure_kexec_event(const char *event_name) {} 291 #endif 292 293 /* 294 * The default binary_runtime_measurements list format is defined as the 295 * platform native format. The canonical format is defined as little-endian. 296 */ 297 extern bool ima_canonical_fmt; 298 299 /* Internal IMA function definitions */ 300 int ima_init(void); 301 int ima_fs_init(void); 302 int ima_add_template_entry(struct ima_template_entry *entry, int violation, 303 const char *op, struct inode *inode, 304 const unsigned char *filename); 305 int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash); 306 int ima_calc_buffer_hash(const void *buf, loff_t len, 307 struct ima_digest_data *hash); 308 int ima_calc_field_array_hash(struct ima_field_data *field_data, 309 struct ima_template_entry *entry); 310 int ima_calc_boot_aggregate(struct ima_digest_data *hash); 311 void ima_add_violation(struct file *file, const unsigned char *filename, 312 struct ima_iint_cache *iint, const char *op, 313 const char *cause); 314 int ima_init_crypto(void); 315 void ima_putc(struct seq_file *m, void *data, int datalen); 316 void ima_print_digest(struct seq_file *m, u8 *digest, u32 size); 317 int template_desc_init_fields(const char *template_fmt, 318 const struct ima_template_field ***fields, 319 int *num_fields); 320 struct ima_template_desc *ima_template_desc_current(void); 321 struct ima_template_desc *ima_template_desc_buf(void); 322 struct ima_template_desc *lookup_template_desc(const char *name); 323 bool ima_template_has_modsig(const struct ima_template_desc *ima_template); 324 int ima_queue_stage(void); 325 int ima_queue_staged_delete_all(void); 326 int ima_queue_delete_partial(unsigned long req_value); 327 int ima_restore_measurement_entry(struct ima_template_entry *entry); 328 int ima_restore_measurement_list(loff_t bufsize, void *buf); 329 int ima_measurements_show(struct seq_file *m, void *v); 330 int __init ima_init_htable(void); 331 unsigned long ima_get_binary_runtime_size(enum binary_lists binary_list); 332 int ima_init_template(void); 333 void ima_init_template_list(void); 334 int __init ima_init_digests(void); 335 void __init ima_init_reboot_notifier(void); 336 int ima_lsm_policy_change(struct notifier_block *nb, unsigned long event, 337 void *lsm_data); 338 339 /* 340 * used to protect h_table and sha_table 341 */ 342 extern spinlock_t ima_queue_lock; 343 344 /* Total number of measurement list records since hard boot. */ 345 extern atomic_long_t ima_num_records[BINARY__LAST]; 346 /* Total number of violations since hard boot. */ 347 extern atomic_long_t ima_num_violations; 348 extern struct hlist_head __rcu *ima_htable; 349 extern bool ima_flush_htable; 350 351 static inline unsigned int ima_hash_key(u8 *digest) 352 { 353 /* there is no point in taking a hash of part of a digest */ 354 return (digest[0] | digest[1] << 8) % IMA_MEASURE_HTABLE_SIZE; 355 } 356 357 #define __ima_hooks(hook) \ 358 hook(NONE, none) \ 359 hook(FILE_CHECK, file) \ 360 hook(MMAP_CHECK, mmap) \ 361 hook(MMAP_CHECK_REQPROT, mmap_reqprot) \ 362 hook(BPRM_CHECK, bprm) \ 363 hook(CREDS_CHECK, creds) \ 364 hook(POST_SETATTR, post_setattr) \ 365 hook(MODULE_CHECK, module) \ 366 hook(FIRMWARE_CHECK, firmware) \ 367 hook(KEXEC_KERNEL_CHECK, kexec_kernel) \ 368 hook(KEXEC_INITRAMFS_CHECK, kexec_initramfs) \ 369 hook(POLICY_CHECK, policy) \ 370 hook(KEXEC_CMDLINE, kexec_cmdline) \ 371 hook(KEY_CHECK, key) \ 372 hook(CRITICAL_DATA, critical_data) \ 373 hook(SETXATTR_CHECK, setxattr_check) \ 374 hook(MAX_CHECK, none) 375 376 #define __ima_hook_enumify(ENUM, str) ENUM, 377 #define __ima_stringify(arg) (#arg) 378 #define __ima_hook_measuring_stringify(ENUM, str) \ 379 (__ima_stringify(measuring_ ##str)), 380 381 enum ima_hooks { 382 __ima_hooks(__ima_hook_enumify) 383 }; 384 385 static const char * const ima_hooks_measure_str[] = { 386 __ima_hooks(__ima_hook_measuring_stringify) 387 }; 388 389 static inline const char *func_measure_str(enum ima_hooks func) 390 { 391 if (func >= MAX_CHECK) 392 return ima_hooks_measure_str[NONE]; 393 394 return ima_hooks_measure_str[func]; 395 } 396 397 extern const char *const func_tokens[]; 398 399 struct modsig; 400 401 #ifdef CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS 402 /* 403 * To track keys that need to be measured. 404 */ 405 struct ima_key_entry { 406 struct list_head list; 407 void *payload; 408 size_t payload_len; 409 char *keyring_name; 410 }; 411 void ima_init_key_queue(void); 412 bool ima_should_queue_key(void); 413 bool ima_queue_key(struct key *keyring, const void *payload, 414 size_t payload_len); 415 void ima_process_queued_keys(void); 416 #else 417 static inline void ima_init_key_queue(void) {} 418 static inline bool ima_should_queue_key(void) { return false; } 419 static inline bool ima_queue_key(struct key *keyring, 420 const void *payload, 421 size_t payload_len) { return false; } 422 static inline void ima_process_queued_keys(void) {} 423 #endif /* CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS */ 424 425 /* LIM API function definitions */ 426 int ima_get_action(struct mnt_idmap *idmap, struct inode *inode, 427 const struct cred *cred, struct lsm_prop *prop, int mask, 428 enum ima_hooks func, int *pcr, 429 struct ima_template_desc **template_desc, 430 const char *func_data, unsigned int *allowed_algos); 431 int ima_must_measure(struct inode *inode, int mask, enum ima_hooks func); 432 int ima_collect_measurement(struct ima_iint_cache *iint, struct file *file, 433 void *buf, loff_t size, enum hash_algo algo, 434 struct modsig *modsig); 435 void ima_store_measurement(struct ima_iint_cache *iint, struct file *file, 436 const unsigned char *filename, 437 struct evm_ima_xattr_data *xattr_value, 438 int xattr_len, const struct modsig *modsig, int pcr, 439 struct ima_template_desc *template_desc); 440 int process_buffer_measurement(struct mnt_idmap *idmap, 441 struct inode *inode, const void *buf, int size, 442 const char *eventname, enum ima_hooks func, 443 int pcr, const char *func_data, 444 bool buf_hash, u8 *digest, size_t digest_len); 445 void ima_audit_measurement(struct ima_iint_cache *iint, 446 const unsigned char *filename); 447 int ima_alloc_init_template(struct ima_event_data *event_data, 448 struct ima_template_entry **entry, 449 struct ima_template_desc *template_desc); 450 int ima_store_template(struct ima_template_entry *entry, int violation, 451 struct inode *inode, 452 const unsigned char *filename, int pcr); 453 void ima_free_template_entry(struct ima_template_entry *entry); 454 const char *ima_d_path(const struct path *path, char **pathbuf, char *filename); 455 456 /* IMA policy related functions */ 457 int ima_match_policy(struct mnt_idmap *idmap, struct inode *inode, 458 const struct cred *cred, struct lsm_prop *prop, 459 enum ima_hooks func, int mask, int flags, int *pcr, 460 struct ima_template_desc **template_desc, 461 const char *func_data, unsigned int *allowed_algos); 462 void ima_init_policy(void); 463 void ima_update_policy(void); 464 void ima_update_policy_flags(void); 465 ssize_t ima_parse_add_rule(char *); 466 void ima_delete_rules(void); 467 int ima_check_policy(void); 468 void *ima_policy_start(struct seq_file *m, loff_t *pos); 469 void *ima_policy_next(struct seq_file *m, void *v, loff_t *pos); 470 void ima_policy_stop(struct seq_file *m, void *v); 471 int ima_policy_show(struct seq_file *m, void *v); 472 void ima_measure_loaded_policy(void); 473 int ima_measure_raw_policy(const char *buf, size_t buf_len); 474 475 /* Appraise integrity measurements */ 476 #define IMA_APPRAISE_ENFORCE 0x01 477 #define IMA_APPRAISE_FIX 0x02 478 #define IMA_APPRAISE_LOG 0x04 479 #define IMA_APPRAISE_MODULES 0x08 480 #define IMA_APPRAISE_FIRMWARE 0x10 481 #define IMA_APPRAISE_POLICY 0x20 482 #define IMA_APPRAISE_KEXEC 0x40 483 484 #ifdef CONFIG_IMA_APPRAISE 485 int ima_check_blacklist(struct ima_iint_cache *iint, 486 const struct modsig *modsig, int pcr); 487 int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint, 488 struct file *file, const unsigned char *filename, 489 struct evm_ima_xattr_data *xattr_value, 490 int xattr_len, const struct modsig *modsig, 491 bool bprm_is_check); 492 int ima_must_appraise(struct mnt_idmap *idmap, struct inode *inode, 493 int mask, enum ima_hooks func); 494 void ima_update_xattr(struct ima_iint_cache *iint, struct file *file); 495 enum integrity_status ima_get_cache_status(struct ima_iint_cache *iint, 496 enum ima_hooks func); 497 enum hash_algo ima_get_hash_algo(const struct evm_ima_xattr_data *xattr_value, 498 int xattr_len); 499 int ima_read_xattr(struct dentry *dentry, 500 struct evm_ima_xattr_data **xattr_value, int xattr_len); 501 void __init init_ima_appraise_lsm(const struct lsm_id *lsmid); 502 503 #else 504 static inline int ima_check_blacklist(struct ima_iint_cache *iint, 505 const struct modsig *modsig, int pcr) 506 { 507 return 0; 508 } 509 510 static inline int ima_appraise_measurement(enum ima_hooks func, 511 struct ima_iint_cache *iint, 512 struct file *file, 513 const unsigned char *filename, 514 struct evm_ima_xattr_data *xattr_value, 515 int xattr_len, 516 const struct modsig *modsig, 517 bool bprm_is_check) 518 { 519 return INTEGRITY_UNKNOWN; 520 } 521 522 static inline int ima_must_appraise(struct mnt_idmap *idmap, 523 struct inode *inode, int mask, 524 enum ima_hooks func) 525 { 526 return 0; 527 } 528 529 static inline void ima_update_xattr(struct ima_iint_cache *iint, 530 struct file *file) 531 { 532 } 533 534 static inline enum integrity_status 535 ima_get_cache_status(struct ima_iint_cache *iint, enum ima_hooks func) 536 { 537 return INTEGRITY_UNKNOWN; 538 } 539 540 static inline enum hash_algo 541 ima_get_hash_algo(struct evm_ima_xattr_data *xattr_value, int xattr_len) 542 { 543 return ima_hash_algo; 544 } 545 546 static inline int ima_read_xattr(struct dentry *dentry, 547 struct evm_ima_xattr_data **xattr_value, 548 int xattr_len) 549 { 550 return 0; 551 } 552 553 static inline void __init init_ima_appraise_lsm(const struct lsm_id *lsmid) 554 { 555 } 556 557 #endif /* CONFIG_IMA_APPRAISE */ 558 559 #ifdef CONFIG_IMA_APPRAISE_MODSIG 560 int ima_read_modsig(enum ima_hooks func, const void *buf, loff_t buf_len, 561 struct modsig **modsig); 562 void ima_collect_modsig(struct modsig *modsig, const void *buf, loff_t size); 563 int ima_get_modsig_digest(const struct modsig *modsig, enum hash_algo *algo, 564 const u8 **digest, u32 *digest_size); 565 int ima_get_raw_modsig(const struct modsig *modsig, const void **data, 566 u32 *data_len); 567 void ima_free_modsig(struct modsig *modsig); 568 #else 569 static inline int ima_read_modsig(enum ima_hooks func, const void *buf, 570 loff_t buf_len, struct modsig **modsig) 571 { 572 return -EOPNOTSUPP; 573 } 574 575 static inline void ima_collect_modsig(struct modsig *modsig, const void *buf, 576 loff_t size) 577 { 578 } 579 580 static inline int ima_get_modsig_digest(const struct modsig *modsig, 581 enum hash_algo *algo, const u8 **digest, 582 u32 *digest_size) 583 { 584 return -EOPNOTSUPP; 585 } 586 587 static inline int ima_get_raw_modsig(const struct modsig *modsig, 588 const void **data, u32 *data_len) 589 { 590 return -EOPNOTSUPP; 591 } 592 593 static inline void ima_free_modsig(struct modsig *modsig) 594 { 595 } 596 #endif /* CONFIG_IMA_APPRAISE_MODSIG */ 597 598 /* LSM based policy rules require audit */ 599 #ifdef CONFIG_IMA_LSM_RULES 600 601 #define ima_filter_rule_init security_audit_rule_init 602 #define ima_filter_rule_free security_audit_rule_free 603 #define ima_filter_rule_match security_audit_rule_match 604 605 #else 606 607 static inline int ima_filter_rule_init(u32 field, u32 op, char *rulestr, 608 void **lsmrule, gfp_t gfp) 609 { 610 return -EINVAL; 611 } 612 613 static inline void ima_filter_rule_free(void *lsmrule) 614 { 615 } 616 617 static inline int ima_filter_rule_match(struct lsm_prop *prop, u32 field, u32 op, 618 void *lsmrule) 619 { 620 return -EINVAL; 621 } 622 #endif /* CONFIG_IMA_LSM_RULES */ 623 624 #ifdef CONFIG_IMA_READ_POLICY 625 #define POLICY_FILE_FLAGS (S_IWUSR | S_IRUSR) 626 #else 627 #define POLICY_FILE_FLAGS S_IWUSR 628 #endif /* CONFIG_IMA_READ_POLICY */ 629 630 #endif /* __LINUX_IMA_H */ 631