Skip to content

Commit 5d1ef2c

Browse files
robertosassumimizohar
authored andcommitted
ima: Introduce ima_get_current_hash_algo()
Buffer measurements, unlike file measurements, are not accessible after the measurement is done, as buffers are not suitable for use with the integrity_iint_cache structure (there is no index, for files it is the inode number). In the subsequent patches, the measurement (digest) will be returned directly by the functions that perform the buffer measurement, ima_measure_critical_data() and process_buffer_measurement(). A caller of those functions also needs to know the algorithm used to calculate the digest. Instead of adding the algorithm as a new parameter to the functions, this patch provides it separately with the new function ima_get_current_hash_algo(). Since the hash algorithm does not change after the IMA setup phase, there is no risk of races (obtaining a digest calculated with a different algorithm than the one returned). Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Reviewed-by: Lakshmi Ramasubramanian <nramas@linux.microsoft.com> [zohar@linux.ibm.com: annotate ima_hash_algo as __ro_after_init] Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent a32ad90 commit 5d1ef2c

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

include/linux/ima.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
#include <linux/fs.h>
1212
#include <linux/security.h>
1313
#include <linux/kexec.h>
14+
#include <crypto/hash_info.h>
1415
struct linux_binprm;
1516

1617
#ifdef CONFIG_IMA
18+
extern enum hash_algo ima_get_current_hash_algo(void);
1719
extern int ima_bprm_check(struct linux_binprm *bprm);
1820
extern int ima_file_check(struct file *file, int mask);
1921
extern void ima_post_create_tmpfile(struct user_namespace *mnt_userns,
@@ -64,6 +66,11 @@ static inline const char * const *arch_get_ima_policy(void)
6466
#endif
6567

6668
#else
69+
static inline enum hash_algo ima_get_current_hash_algo(void)
70+
{
71+
return HASH_ALGO__LAST;
72+
}
73+
6774
static inline int ima_bprm_check(struct linux_binprm *bprm)
6875
{
6976
return 0;

security/integrity/ima/ima_main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int ima_appraise = IMA_APPRAISE_ENFORCE;
3535
int ima_appraise;
3636
#endif
3737

38-
int ima_hash_algo = HASH_ALGO_SHA1;
38+
int __ro_after_init ima_hash_algo = HASH_ALGO_SHA1;
3939
static int hash_setup_done;
4040

4141
static struct notifier_block ima_lsm_policy_notifier = {
@@ -76,6 +76,11 @@ static int __init hash_setup(char *str)
7676
}
7777
__setup("ima_hash=", hash_setup);
7878

79+
enum hash_algo ima_get_current_hash_algo(void)
80+
{
81+
return ima_hash_algo;
82+
}
83+
7984
/* Prevent mmap'ing a file execute that is already mmap'ed write */
8085
static int mmap_violation_check(enum ima_hooks func, struct file *file,
8186
char **pathbuf, const char **pathname,

0 commit comments

Comments
 (0)