18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2005,2006,2007,2008 IBM Corporation 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Authors: 68c2ecf20Sopenharmony_ci * Reiner Sailer <sailer@watson.ibm.com> 78c2ecf20Sopenharmony_ci * Mimi Zohar <zohar@us.ibm.com> 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * File: ima.h 108c2ecf20Sopenharmony_ci * internal Integrity Measurement Architecture (IMA) definitions 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#ifndef __LINUX_IMA_H 148c2ecf20Sopenharmony_ci#define __LINUX_IMA_H 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include <linux/types.h> 178c2ecf20Sopenharmony_ci#include <linux/crypto.h> 188c2ecf20Sopenharmony_ci#include <linux/fs.h> 198c2ecf20Sopenharmony_ci#include <linux/security.h> 208c2ecf20Sopenharmony_ci#include <linux/hash.h> 218c2ecf20Sopenharmony_ci#include <linux/tpm.h> 228c2ecf20Sopenharmony_ci#include <linux/audit.h> 238c2ecf20Sopenharmony_ci#include <crypto/hash_info.h> 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#include "../integrity.h" 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#ifdef CONFIG_HAVE_IMA_KEXEC 288c2ecf20Sopenharmony_ci#include <asm/ima.h> 298c2ecf20Sopenharmony_ci#endif 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cienum ima_show_type { IMA_SHOW_BINARY, IMA_SHOW_BINARY_NO_FIELD_LEN, 328c2ecf20Sopenharmony_ci IMA_SHOW_BINARY_OLD_STRING_FMT, IMA_SHOW_ASCII }; 338c2ecf20Sopenharmony_cienum tpm_pcrs { TPM_PCR0 = 0, TPM_PCR8 = 8, TPM_PCR10 = 10 }; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* digest size for IMA, fits SHA1 or MD5 */ 368c2ecf20Sopenharmony_ci#define IMA_DIGEST_SIZE SHA1_DIGEST_SIZE 378c2ecf20Sopenharmony_ci#define IMA_EVENT_NAME_LEN_MAX 255 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define IMA_HASH_BITS 10 408c2ecf20Sopenharmony_ci#define IMA_MEASURE_HTABLE_SIZE (1 << IMA_HASH_BITS) 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define IMA_TEMPLATE_FIELD_ID_MAX_LEN 16 438c2ecf20Sopenharmony_ci#define IMA_TEMPLATE_NUM_FIELDS_MAX 15 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define IMA_TEMPLATE_IMA_NAME "ima" 468c2ecf20Sopenharmony_ci#define IMA_TEMPLATE_IMA_FMT "d|n" 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define NR_BANKS(chip) ((chip != NULL) ? chip->nr_allocated_banks : 0) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* current content of the policy */ 518c2ecf20Sopenharmony_ciextern int ima_policy_flag; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/* set during initialization */ 548c2ecf20Sopenharmony_ciextern int ima_hash_algo; 558c2ecf20Sopenharmony_ciextern int ima_sha1_idx __ro_after_init; 568c2ecf20Sopenharmony_ciextern int ima_hash_algo_idx __ro_after_init; 578c2ecf20Sopenharmony_ciextern int ima_extra_slots __ro_after_init; 588c2ecf20Sopenharmony_ciextern int ima_appraise; 598c2ecf20Sopenharmony_ciextern struct tpm_chip *ima_tpm_chip; 608c2ecf20Sopenharmony_ciextern const char boot_aggregate_name[]; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/* IMA event related data */ 638c2ecf20Sopenharmony_cistruct ima_event_data { 648c2ecf20Sopenharmony_ci struct integrity_iint_cache *iint; 658c2ecf20Sopenharmony_ci struct file *file; 668c2ecf20Sopenharmony_ci const unsigned char *filename; 678c2ecf20Sopenharmony_ci struct evm_ima_xattr_data *xattr_value; 688c2ecf20Sopenharmony_ci int xattr_len; 698c2ecf20Sopenharmony_ci const struct modsig *modsig; 708c2ecf20Sopenharmony_ci const char *violation; 718c2ecf20Sopenharmony_ci const void *buf; 728c2ecf20Sopenharmony_ci int buf_len; 738c2ecf20Sopenharmony_ci}; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci/* IMA template field data definition */ 768c2ecf20Sopenharmony_cistruct ima_field_data { 778c2ecf20Sopenharmony_ci u8 *data; 788c2ecf20Sopenharmony_ci u32 len; 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci/* IMA template field definition */ 828c2ecf20Sopenharmony_cistruct ima_template_field { 838c2ecf20Sopenharmony_ci const char field_id[IMA_TEMPLATE_FIELD_ID_MAX_LEN]; 848c2ecf20Sopenharmony_ci int (*field_init)(struct ima_event_data *event_data, 858c2ecf20Sopenharmony_ci struct ima_field_data *field_data); 868c2ecf20Sopenharmony_ci void (*field_show)(struct seq_file *m, enum ima_show_type show, 878c2ecf20Sopenharmony_ci struct ima_field_data *field_data); 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci/* IMA template descriptor definition */ 918c2ecf20Sopenharmony_cistruct ima_template_desc { 928c2ecf20Sopenharmony_ci struct list_head list; 938c2ecf20Sopenharmony_ci char *name; 948c2ecf20Sopenharmony_ci char *fmt; 958c2ecf20Sopenharmony_ci int num_fields; 968c2ecf20Sopenharmony_ci const struct ima_template_field **fields; 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_cistruct ima_template_entry { 1008c2ecf20Sopenharmony_ci int pcr; 1018c2ecf20Sopenharmony_ci struct tpm_digest *digests; 1028c2ecf20Sopenharmony_ci struct ima_template_desc *template_desc; /* template descriptor */ 1038c2ecf20Sopenharmony_ci u32 template_data_len; 1048c2ecf20Sopenharmony_ci struct ima_field_data template_data[]; /* template related data */ 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistruct ima_queue_entry { 1088c2ecf20Sopenharmony_ci struct hlist_node hnext; /* place in hash collision list */ 1098c2ecf20Sopenharmony_ci struct list_head later; /* place in ima_measurements list */ 1108c2ecf20Sopenharmony_ci struct ima_template_entry *entry; 1118c2ecf20Sopenharmony_ci}; 1128c2ecf20Sopenharmony_ciextern struct list_head ima_measurements; /* list of all measurements */ 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci/* Some details preceding the binary serialized measurement list */ 1158c2ecf20Sopenharmony_cistruct ima_kexec_hdr { 1168c2ecf20Sopenharmony_ci u16 version; 1178c2ecf20Sopenharmony_ci u16 _reserved0; 1188c2ecf20Sopenharmony_ci u32 _reserved1; 1198c2ecf20Sopenharmony_ci u64 buffer_size; 1208c2ecf20Sopenharmony_ci u64 count; 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ciextern const int read_idmap[]; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci#ifdef CONFIG_HAVE_IMA_KEXEC 1268c2ecf20Sopenharmony_civoid ima_load_kexec_buffer(void); 1278c2ecf20Sopenharmony_ci#else 1288c2ecf20Sopenharmony_cistatic inline void ima_load_kexec_buffer(void) {} 1298c2ecf20Sopenharmony_ci#endif /* CONFIG_HAVE_IMA_KEXEC */ 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci/* 1328c2ecf20Sopenharmony_ci * The default binary_runtime_measurements list format is defined as the 1338c2ecf20Sopenharmony_ci * platform native format. The canonical format is defined as little-endian. 1348c2ecf20Sopenharmony_ci */ 1358c2ecf20Sopenharmony_ciextern bool ima_canonical_fmt; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci/* Internal IMA function definitions */ 1388c2ecf20Sopenharmony_ciint ima_init(void); 1398c2ecf20Sopenharmony_ciint ima_fs_init(void); 1408c2ecf20Sopenharmony_ciint ima_add_template_entry(struct ima_template_entry *entry, int violation, 1418c2ecf20Sopenharmony_ci const char *op, struct inode *inode, 1428c2ecf20Sopenharmony_ci const unsigned char *filename); 1438c2ecf20Sopenharmony_ciint ima_calc_file_hash(struct file *file, struct ima_digest_data *hash); 1448c2ecf20Sopenharmony_ciint ima_calc_buffer_hash(const void *buf, loff_t len, 1458c2ecf20Sopenharmony_ci struct ima_digest_data *hash); 1468c2ecf20Sopenharmony_ciint ima_calc_field_array_hash(struct ima_field_data *field_data, 1478c2ecf20Sopenharmony_ci struct ima_template_entry *entry); 1488c2ecf20Sopenharmony_ciint ima_calc_boot_aggregate(struct ima_digest_data *hash); 1498c2ecf20Sopenharmony_civoid ima_add_violation(struct file *file, const unsigned char *filename, 1508c2ecf20Sopenharmony_ci struct integrity_iint_cache *iint, 1518c2ecf20Sopenharmony_ci const char *op, const char *cause); 1528c2ecf20Sopenharmony_ciint ima_init_crypto(void); 1538c2ecf20Sopenharmony_civoid ima_putc(struct seq_file *m, void *data, int datalen); 1548c2ecf20Sopenharmony_civoid ima_print_digest(struct seq_file *m, u8 *digest, u32 size); 1558c2ecf20Sopenharmony_ciint template_desc_init_fields(const char *template_fmt, 1568c2ecf20Sopenharmony_ci const struct ima_template_field ***fields, 1578c2ecf20Sopenharmony_ci int *num_fields); 1588c2ecf20Sopenharmony_cistruct ima_template_desc *ima_template_desc_current(void); 1598c2ecf20Sopenharmony_cistruct ima_template_desc *lookup_template_desc(const char *name); 1608c2ecf20Sopenharmony_cibool ima_template_has_modsig(const struct ima_template_desc *ima_template); 1618c2ecf20Sopenharmony_ciint ima_restore_measurement_entry(struct ima_template_entry *entry); 1628c2ecf20Sopenharmony_ciint ima_restore_measurement_list(loff_t bufsize, void *buf); 1638c2ecf20Sopenharmony_ciint ima_measurements_show(struct seq_file *m, void *v); 1648c2ecf20Sopenharmony_ciunsigned long ima_get_binary_runtime_size(void); 1658c2ecf20Sopenharmony_ciint ima_init_template(void); 1668c2ecf20Sopenharmony_civoid ima_init_template_list(void); 1678c2ecf20Sopenharmony_ciint __init ima_init_digests(void); 1688c2ecf20Sopenharmony_ciint ima_lsm_policy_change(struct notifier_block *nb, unsigned long event, 1698c2ecf20Sopenharmony_ci void *lsm_data); 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci/* 1728c2ecf20Sopenharmony_ci * used to protect h_table and sha_table 1738c2ecf20Sopenharmony_ci */ 1748c2ecf20Sopenharmony_ciextern spinlock_t ima_queue_lock; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_cistruct ima_h_table { 1778c2ecf20Sopenharmony_ci atomic_long_t len; /* number of stored measurements in the list */ 1788c2ecf20Sopenharmony_ci atomic_long_t violations; 1798c2ecf20Sopenharmony_ci struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE]; 1808c2ecf20Sopenharmony_ci}; 1818c2ecf20Sopenharmony_ciextern struct ima_h_table ima_htable; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_cistatic inline unsigned int ima_hash_key(u8 *digest) 1848c2ecf20Sopenharmony_ci{ 1858c2ecf20Sopenharmony_ci /* there is no point in taking a hash of part of a digest */ 1868c2ecf20Sopenharmony_ci return (digest[0] | digest[1] << 8) % IMA_MEASURE_HTABLE_SIZE; 1878c2ecf20Sopenharmony_ci} 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci#define __ima_hooks(hook) \ 1908c2ecf20Sopenharmony_ci hook(NONE, none) \ 1918c2ecf20Sopenharmony_ci hook(FILE_CHECK, file) \ 1928c2ecf20Sopenharmony_ci hook(MMAP_CHECK, mmap) \ 1938c2ecf20Sopenharmony_ci hook(BPRM_CHECK, bprm) \ 1948c2ecf20Sopenharmony_ci hook(CREDS_CHECK, creds) \ 1958c2ecf20Sopenharmony_ci hook(POST_SETATTR, post_setattr) \ 1968c2ecf20Sopenharmony_ci hook(MODULE_CHECK, module) \ 1978c2ecf20Sopenharmony_ci hook(FIRMWARE_CHECK, firmware) \ 1988c2ecf20Sopenharmony_ci hook(KEXEC_KERNEL_CHECK, kexec_kernel) \ 1998c2ecf20Sopenharmony_ci hook(KEXEC_INITRAMFS_CHECK, kexec_initramfs) \ 2008c2ecf20Sopenharmony_ci hook(POLICY_CHECK, policy) \ 2018c2ecf20Sopenharmony_ci hook(KEXEC_CMDLINE, kexec_cmdline) \ 2028c2ecf20Sopenharmony_ci hook(KEY_CHECK, key) \ 2038c2ecf20Sopenharmony_ci hook(MAX_CHECK, none) 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci#define __ima_hook_enumify(ENUM, str) ENUM, 2068c2ecf20Sopenharmony_ci#define __ima_stringify(arg) (#arg) 2078c2ecf20Sopenharmony_ci#define __ima_hook_measuring_stringify(ENUM, str) \ 2088c2ecf20Sopenharmony_ci (__ima_stringify(measuring_ ##str)), 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_cienum ima_hooks { 2118c2ecf20Sopenharmony_ci __ima_hooks(__ima_hook_enumify) 2128c2ecf20Sopenharmony_ci}; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_cistatic const char * const ima_hooks_measure_str[] = { 2158c2ecf20Sopenharmony_ci __ima_hooks(__ima_hook_measuring_stringify) 2168c2ecf20Sopenharmony_ci}; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_cistatic inline const char *func_measure_str(enum ima_hooks func) 2198c2ecf20Sopenharmony_ci{ 2208c2ecf20Sopenharmony_ci if (func >= MAX_CHECK) 2218c2ecf20Sopenharmony_ci return ima_hooks_measure_str[NONE]; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci return ima_hooks_measure_str[func]; 2248c2ecf20Sopenharmony_ci} 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ciextern const char *const func_tokens[]; 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_cistruct modsig; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci#ifdef CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS 2318c2ecf20Sopenharmony_ci/* 2328c2ecf20Sopenharmony_ci * To track keys that need to be measured. 2338c2ecf20Sopenharmony_ci */ 2348c2ecf20Sopenharmony_cistruct ima_key_entry { 2358c2ecf20Sopenharmony_ci struct list_head list; 2368c2ecf20Sopenharmony_ci void *payload; 2378c2ecf20Sopenharmony_ci size_t payload_len; 2388c2ecf20Sopenharmony_ci char *keyring_name; 2398c2ecf20Sopenharmony_ci}; 2408c2ecf20Sopenharmony_civoid ima_init_key_queue(void); 2418c2ecf20Sopenharmony_cibool ima_should_queue_key(void); 2428c2ecf20Sopenharmony_cibool ima_queue_key(struct key *keyring, const void *payload, 2438c2ecf20Sopenharmony_ci size_t payload_len); 2448c2ecf20Sopenharmony_civoid ima_process_queued_keys(void); 2458c2ecf20Sopenharmony_ci#else 2468c2ecf20Sopenharmony_cistatic inline void ima_init_key_queue(void) {} 2478c2ecf20Sopenharmony_cistatic inline bool ima_should_queue_key(void) { return false; } 2488c2ecf20Sopenharmony_cistatic inline bool ima_queue_key(struct key *keyring, 2498c2ecf20Sopenharmony_ci const void *payload, 2508c2ecf20Sopenharmony_ci size_t payload_len) { return false; } 2518c2ecf20Sopenharmony_cistatic inline void ima_process_queued_keys(void) {} 2528c2ecf20Sopenharmony_ci#endif /* CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS */ 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci/* LIM API function definitions */ 2558c2ecf20Sopenharmony_ciint ima_get_action(struct inode *inode, const struct cred *cred, u32 secid, 2568c2ecf20Sopenharmony_ci int mask, enum ima_hooks func, int *pcr, 2578c2ecf20Sopenharmony_ci struct ima_template_desc **template_desc, 2588c2ecf20Sopenharmony_ci const char *keyring); 2598c2ecf20Sopenharmony_ciint ima_must_measure(struct inode *inode, int mask, enum ima_hooks func); 2608c2ecf20Sopenharmony_ciint ima_collect_measurement(struct integrity_iint_cache *iint, 2618c2ecf20Sopenharmony_ci struct file *file, void *buf, loff_t size, 2628c2ecf20Sopenharmony_ci enum hash_algo algo, struct modsig *modsig); 2638c2ecf20Sopenharmony_civoid ima_store_measurement(struct integrity_iint_cache *iint, struct file *file, 2648c2ecf20Sopenharmony_ci const unsigned char *filename, 2658c2ecf20Sopenharmony_ci struct evm_ima_xattr_data *xattr_value, 2668c2ecf20Sopenharmony_ci int xattr_len, const struct modsig *modsig, int pcr, 2678c2ecf20Sopenharmony_ci struct ima_template_desc *template_desc); 2688c2ecf20Sopenharmony_civoid process_buffer_measurement(struct inode *inode, const void *buf, int size, 2698c2ecf20Sopenharmony_ci const char *eventname, enum ima_hooks func, 2708c2ecf20Sopenharmony_ci int pcr, const char *keyring); 2718c2ecf20Sopenharmony_civoid ima_audit_measurement(struct integrity_iint_cache *iint, 2728c2ecf20Sopenharmony_ci const unsigned char *filename); 2738c2ecf20Sopenharmony_ciint ima_alloc_init_template(struct ima_event_data *event_data, 2748c2ecf20Sopenharmony_ci struct ima_template_entry **entry, 2758c2ecf20Sopenharmony_ci struct ima_template_desc *template_desc); 2768c2ecf20Sopenharmony_ciint ima_store_template(struct ima_template_entry *entry, int violation, 2778c2ecf20Sopenharmony_ci struct inode *inode, 2788c2ecf20Sopenharmony_ci const unsigned char *filename, int pcr); 2798c2ecf20Sopenharmony_civoid ima_free_template_entry(struct ima_template_entry *entry); 2808c2ecf20Sopenharmony_ciconst char *ima_d_path(const struct path *path, char **pathbuf, char *filename); 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci/* IMA policy related functions */ 2838c2ecf20Sopenharmony_ciint ima_match_policy(struct inode *inode, const struct cred *cred, u32 secid, 2848c2ecf20Sopenharmony_ci enum ima_hooks func, int mask, int flags, int *pcr, 2858c2ecf20Sopenharmony_ci struct ima_template_desc **template_desc, 2868c2ecf20Sopenharmony_ci const char *keyring); 2878c2ecf20Sopenharmony_civoid ima_init_policy(void); 2888c2ecf20Sopenharmony_civoid ima_update_policy(void); 2898c2ecf20Sopenharmony_civoid ima_update_policy_flag(void); 2908c2ecf20Sopenharmony_cissize_t ima_parse_add_rule(char *); 2918c2ecf20Sopenharmony_civoid ima_delete_rules(void); 2928c2ecf20Sopenharmony_ciint ima_check_policy(void); 2938c2ecf20Sopenharmony_civoid *ima_policy_start(struct seq_file *m, loff_t *pos); 2948c2ecf20Sopenharmony_civoid *ima_policy_next(struct seq_file *m, void *v, loff_t *pos); 2958c2ecf20Sopenharmony_civoid ima_policy_stop(struct seq_file *m, void *v); 2968c2ecf20Sopenharmony_ciint ima_policy_show(struct seq_file *m, void *v); 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci/* Appraise integrity measurements */ 2998c2ecf20Sopenharmony_ci#define IMA_APPRAISE_ENFORCE 0x01 3008c2ecf20Sopenharmony_ci#define IMA_APPRAISE_FIX 0x02 3018c2ecf20Sopenharmony_ci#define IMA_APPRAISE_LOG 0x04 3028c2ecf20Sopenharmony_ci#define IMA_APPRAISE_MODULES 0x08 3038c2ecf20Sopenharmony_ci#define IMA_APPRAISE_FIRMWARE 0x10 3048c2ecf20Sopenharmony_ci#define IMA_APPRAISE_POLICY 0x20 3058c2ecf20Sopenharmony_ci#define IMA_APPRAISE_KEXEC 0x40 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci#ifdef CONFIG_IMA_APPRAISE 3088c2ecf20Sopenharmony_ciint ima_check_blacklist(struct integrity_iint_cache *iint, 3098c2ecf20Sopenharmony_ci const struct modsig *modsig, int pcr); 3108c2ecf20Sopenharmony_ciint ima_appraise_measurement(enum ima_hooks func, 3118c2ecf20Sopenharmony_ci struct integrity_iint_cache *iint, 3128c2ecf20Sopenharmony_ci struct file *file, const unsigned char *filename, 3138c2ecf20Sopenharmony_ci struct evm_ima_xattr_data *xattr_value, 3148c2ecf20Sopenharmony_ci int xattr_len, const struct modsig *modsig); 3158c2ecf20Sopenharmony_ciint ima_must_appraise(struct inode *inode, int mask, enum ima_hooks func); 3168c2ecf20Sopenharmony_civoid ima_update_xattr(struct integrity_iint_cache *iint, struct file *file); 3178c2ecf20Sopenharmony_cienum integrity_status ima_get_cache_status(struct integrity_iint_cache *iint, 3188c2ecf20Sopenharmony_ci enum ima_hooks func); 3198c2ecf20Sopenharmony_cienum hash_algo ima_get_hash_algo(struct evm_ima_xattr_data *xattr_value, 3208c2ecf20Sopenharmony_ci int xattr_len); 3218c2ecf20Sopenharmony_ciint ima_read_xattr(struct dentry *dentry, 3228c2ecf20Sopenharmony_ci struct evm_ima_xattr_data **xattr_value); 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci#else 3258c2ecf20Sopenharmony_cistatic inline int ima_check_blacklist(struct integrity_iint_cache *iint, 3268c2ecf20Sopenharmony_ci const struct modsig *modsig, int pcr) 3278c2ecf20Sopenharmony_ci{ 3288c2ecf20Sopenharmony_ci return 0; 3298c2ecf20Sopenharmony_ci} 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_cistatic inline int ima_appraise_measurement(enum ima_hooks func, 3328c2ecf20Sopenharmony_ci struct integrity_iint_cache *iint, 3338c2ecf20Sopenharmony_ci struct file *file, 3348c2ecf20Sopenharmony_ci const unsigned char *filename, 3358c2ecf20Sopenharmony_ci struct evm_ima_xattr_data *xattr_value, 3368c2ecf20Sopenharmony_ci int xattr_len, 3378c2ecf20Sopenharmony_ci const struct modsig *modsig) 3388c2ecf20Sopenharmony_ci{ 3398c2ecf20Sopenharmony_ci return INTEGRITY_UNKNOWN; 3408c2ecf20Sopenharmony_ci} 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_cistatic inline int ima_must_appraise(struct inode *inode, int mask, 3438c2ecf20Sopenharmony_ci enum ima_hooks func) 3448c2ecf20Sopenharmony_ci{ 3458c2ecf20Sopenharmony_ci return 0; 3468c2ecf20Sopenharmony_ci} 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_cistatic inline void ima_update_xattr(struct integrity_iint_cache *iint, 3498c2ecf20Sopenharmony_ci struct file *file) 3508c2ecf20Sopenharmony_ci{ 3518c2ecf20Sopenharmony_ci} 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_cistatic inline enum integrity_status ima_get_cache_status(struct integrity_iint_cache 3548c2ecf20Sopenharmony_ci *iint, 3558c2ecf20Sopenharmony_ci enum ima_hooks func) 3568c2ecf20Sopenharmony_ci{ 3578c2ecf20Sopenharmony_ci return INTEGRITY_UNKNOWN; 3588c2ecf20Sopenharmony_ci} 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_cistatic inline enum hash_algo 3618c2ecf20Sopenharmony_ciima_get_hash_algo(struct evm_ima_xattr_data *xattr_value, int xattr_len) 3628c2ecf20Sopenharmony_ci{ 3638c2ecf20Sopenharmony_ci return ima_hash_algo; 3648c2ecf20Sopenharmony_ci} 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_cistatic inline int ima_read_xattr(struct dentry *dentry, 3678c2ecf20Sopenharmony_ci struct evm_ima_xattr_data **xattr_value) 3688c2ecf20Sopenharmony_ci{ 3698c2ecf20Sopenharmony_ci return 0; 3708c2ecf20Sopenharmony_ci} 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci#endif /* CONFIG_IMA_APPRAISE */ 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci#ifdef CONFIG_IMA_APPRAISE_MODSIG 3758c2ecf20Sopenharmony_ciint ima_read_modsig(enum ima_hooks func, const void *buf, loff_t buf_len, 3768c2ecf20Sopenharmony_ci struct modsig **modsig); 3778c2ecf20Sopenharmony_civoid ima_collect_modsig(struct modsig *modsig, const void *buf, loff_t size); 3788c2ecf20Sopenharmony_ciint ima_get_modsig_digest(const struct modsig *modsig, enum hash_algo *algo, 3798c2ecf20Sopenharmony_ci const u8 **digest, u32 *digest_size); 3808c2ecf20Sopenharmony_ciint ima_get_raw_modsig(const struct modsig *modsig, const void **data, 3818c2ecf20Sopenharmony_ci u32 *data_len); 3828c2ecf20Sopenharmony_civoid ima_free_modsig(struct modsig *modsig); 3838c2ecf20Sopenharmony_ci#else 3848c2ecf20Sopenharmony_cistatic inline int ima_read_modsig(enum ima_hooks func, const void *buf, 3858c2ecf20Sopenharmony_ci loff_t buf_len, struct modsig **modsig) 3868c2ecf20Sopenharmony_ci{ 3878c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 3888c2ecf20Sopenharmony_ci} 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_cistatic inline void ima_collect_modsig(struct modsig *modsig, const void *buf, 3918c2ecf20Sopenharmony_ci loff_t size) 3928c2ecf20Sopenharmony_ci{ 3938c2ecf20Sopenharmony_ci} 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_cistatic inline int ima_get_modsig_digest(const struct modsig *modsig, 3968c2ecf20Sopenharmony_ci enum hash_algo *algo, const u8 **digest, 3978c2ecf20Sopenharmony_ci u32 *digest_size) 3988c2ecf20Sopenharmony_ci{ 3998c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 4008c2ecf20Sopenharmony_ci} 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_cistatic inline int ima_get_raw_modsig(const struct modsig *modsig, 4038c2ecf20Sopenharmony_ci const void **data, u32 *data_len) 4048c2ecf20Sopenharmony_ci{ 4058c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 4068c2ecf20Sopenharmony_ci} 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_cistatic inline void ima_free_modsig(struct modsig *modsig) 4098c2ecf20Sopenharmony_ci{ 4108c2ecf20Sopenharmony_ci} 4118c2ecf20Sopenharmony_ci#endif /* CONFIG_IMA_APPRAISE_MODSIG */ 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci/* LSM based policy rules require audit */ 4148c2ecf20Sopenharmony_ci#ifdef CONFIG_IMA_LSM_RULES 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci#define ima_filter_rule_init security_audit_rule_init 4178c2ecf20Sopenharmony_ci#define ima_filter_rule_free security_audit_rule_free 4188c2ecf20Sopenharmony_ci#define ima_filter_rule_match security_audit_rule_match 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci#else 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_cistatic inline int ima_filter_rule_init(u32 field, u32 op, char *rulestr, 4238c2ecf20Sopenharmony_ci void **lsmrule) 4248c2ecf20Sopenharmony_ci{ 4258c2ecf20Sopenharmony_ci return -EINVAL; 4268c2ecf20Sopenharmony_ci} 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_cistatic inline void ima_filter_rule_free(void *lsmrule) 4298c2ecf20Sopenharmony_ci{ 4308c2ecf20Sopenharmony_ci} 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_cistatic inline int ima_filter_rule_match(u32 secid, u32 field, u32 op, 4338c2ecf20Sopenharmony_ci void *lsmrule) 4348c2ecf20Sopenharmony_ci{ 4358c2ecf20Sopenharmony_ci return -EINVAL; 4368c2ecf20Sopenharmony_ci} 4378c2ecf20Sopenharmony_ci#endif /* CONFIG_IMA_LSM_RULES */ 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci#ifdef CONFIG_IMA_READ_POLICY 4408c2ecf20Sopenharmony_ci#define POLICY_FILE_FLAGS (S_IWUSR | S_IRUSR) 4418c2ecf20Sopenharmony_ci#else 4428c2ecf20Sopenharmony_ci#define POLICY_FILE_FLAGS S_IWUSR 4438c2ecf20Sopenharmony_ci#endif /* CONFIG_IMA_READ_POLICY */ 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci#endif /* __LINUX_IMA_H */ 446