Skip to content

Commit 4adfa86

Browse files
committed
Merge tag 'integrity-v5.19-fix' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity
Pull integrity fixes from Mimi Zohar: "Here are a number of fixes for recently found bugs. Only 'ima: fix violation measurement list record' was introduced in the current release. The rest address existing bugs" * tag 'integrity-v5.19-fix' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity: ima: Fix potential memory leak in ima_init_crypto() ima: force signature verification when CONFIG_KEXEC_SIG is configured ima: Fix a potential integer overflow in ima_appraise_measurement ima: fix violation measurement list record Revert "evm: Fix memleak in init_desc"
2 parents 2eb5866 + 067d252 commit 4adfa86

7 files changed

Lines changed: 26 additions & 10 deletions

File tree

include/linux/kexec.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ static inline int kexec_crash_loaded(void) { return 0; }
452452
#define kexec_in_progress false
453453
#endif /* CONFIG_KEXEC_CORE */
454454

455+
#ifdef CONFIG_KEXEC_SIG
456+
void set_kexec_sig_enforced(void);
457+
#else
458+
static inline void set_kexec_sig_enforced(void) {}
459+
#endif
460+
455461
#endif /* !defined(__ASSEBMLY__) */
456462

457463
#endif /* LINUX_KEXEC_H */

kernel/kexec_file.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
#include <linux/vmalloc.h>
3030
#include "kexec_internal.h"
3131

32+
#ifdef CONFIG_KEXEC_SIG
33+
static bool sig_enforce = IS_ENABLED(CONFIG_KEXEC_SIG_FORCE);
34+
35+
void set_kexec_sig_enforced(void)
36+
{
37+
sig_enforce = true;
38+
}
39+
#endif
40+
3241
static int kexec_calculate_store_digests(struct kimage *image);
3342

3443
/*
@@ -159,7 +168,7 @@ kimage_validate_signature(struct kimage *image)
159168
image->kernel_buf_len);
160169
if (ret) {
161170

162-
if (IS_ENABLED(CONFIG_KEXEC_SIG_FORCE)) {
171+
if (sig_enforce) {
163172
pr_notice("Enforced kernel signature verification failed (%d).\n", ret);
164173
return ret;
165174
}

security/integrity/evm/evm_crypto.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static struct shash_desc *init_desc(char type, uint8_t hash_algo)
7575
{
7676
long rc;
7777
const char *algo;
78-
struct crypto_shash **tfm, *tmp_tfm = NULL;
78+
struct crypto_shash **tfm, *tmp_tfm;
7979
struct shash_desc *desc;
8080

8181
if (type == EVM_XATTR_HMAC) {
@@ -120,16 +120,13 @@ static struct shash_desc *init_desc(char type, uint8_t hash_algo)
120120
alloc:
121121
desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(*tfm),
122122
GFP_KERNEL);
123-
if (!desc) {
124-
crypto_free_shash(tmp_tfm);
123+
if (!desc)
125124
return ERR_PTR(-ENOMEM);
126-
}
127125

128126
desc->tfm = *tfm;
129127

130128
rc = crypto_shash_init(desc);
131129
if (rc) {
132-
crypto_free_shash(tmp_tfm);
133130
kfree(desc);
134131
return ERR_PTR(rc);
135132
}

security/integrity/ima/ima_appraise.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ int ima_appraise_measurement(enum ima_hooks func,
514514
goto out;
515515
}
516516

517-
status = evm_verifyxattr(dentry, XATTR_NAME_IMA, xattr_value, rc, iint);
517+
status = evm_verifyxattr(dentry, XATTR_NAME_IMA, xattr_value,
518+
rc < 0 ? 0 : rc, iint);
518519
switch (status) {
519520
case INTEGRITY_PASS:
520521
case INTEGRITY_PASS_IMMUTABLE:

security/integrity/ima/ima_crypto.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ int __init ima_init_crypto(void)
205205

206206
crypto_free_shash(ima_algo_array[i].tfm);
207207
}
208+
kfree(ima_algo_array);
208209
out:
209210
crypto_free_shash(ima_shash_tfm);
210211
return rc;

security/integrity/ima/ima_efi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ const char * const *arch_get_ima_policy(void)
6767
if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) {
6868
if (IS_ENABLED(CONFIG_MODULE_SIG))
6969
set_module_sig_enforced();
70+
if (IS_ENABLED(CONFIG_KEXEC_SIG))
71+
set_kexec_sig_enforced();
7072
return sb_arch_rules;
7173
}
7274
return NULL;

security/integrity/ima/ima_template_lib.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ static int ima_eventdigest_init_common(const u8 *digest, u32 digestsize,
323323
else
324324
/*
325325
* If digest is NULL, the event being recorded is a violation.
326-
* Make room for the digest by increasing the offset of
327-
* IMA_DIGEST_SIZE.
326+
* Make room for the digest by increasing the offset by the
327+
* hash algorithm digest size.
328328
*/
329-
offset += IMA_DIGEST_SIZE;
329+
offset += hash_digest_size[hash_algo];
330330

331331
return ima_write_template_field_data(buffer, offset + digestsize,
332332
fmt, field_data);

0 commit comments

Comments
 (0)