Skip to content

Commit 88e70da

Browse files
nramasmimizohar
authored andcommitted
IMA: Define an IMA hook to measure keys
Measure asymmetric keys used for verifying file signatures, certificates, etc. This patch defines a new IMA hook namely ima_post_key_create_or_update() to measure the payload used to create a new asymmetric key or update an existing asymmetric key. Asymmetric key structure is defined only when CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE is defined. Since the IMA hook measures asymmetric keys, the IMA hook is defined in a new file namely ima_asymmetric_keys.c which is built only if CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE is defined. Signed-off-by: Lakshmi Ramasubramanian <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent 5808611 commit 88e70da

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

security/integrity/ima/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ ima-$(CONFIG_IMA_APPRAISE) += ima_appraise.o
1212
ima-$(CONFIG_IMA_APPRAISE_MODSIG) += ima_modsig.o
1313
ima-$(CONFIG_HAVE_IMA_KEXEC) += ima_kexec.o
1414
obj-$(CONFIG_IMA_BLACKLIST_KEYRING) += ima_mok.o
15+
obj-$(CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += ima_asymmetric_keys.o
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* Copyright (C) 2019 Microsoft Corporation
4+
*
5+
* Author: Lakshmi Ramasubramanian ([email protected])
6+
*
7+
* File: ima_asymmetric_keys.c
8+
* Defines an IMA hook to measure asymmetric keys on key
9+
* create or update.
10+
*/
11+
12+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13+
14+
#include <keys/asymmetric-type.h>
15+
#include "ima.h"
16+
17+
/**
18+
* ima_post_key_create_or_update - measure asymmetric keys
19+
* @keyring: keyring to which the key is linked to
20+
* @key: created or updated key
21+
* @payload: The data used to instantiate or update the key.
22+
* @payload_len: The length of @payload.
23+
* @flags: key flags
24+
* @create: flag indicating whether the key was created or updated
25+
*
26+
* Keys can only be measured, not appraised.
27+
* The payload data used to instantiate or update the key is measured.
28+
*/
29+
void ima_post_key_create_or_update(struct key *keyring, struct key *key,
30+
const void *payload, size_t payload_len,
31+
unsigned long flags, bool create)
32+
{
33+
/* Only asymmetric keys are handled by this hook. */
34+
if (key->type != &key_type_asymmetric)
35+
return;
36+
37+
if (!payload || (payload_len == 0))
38+
return;
39+
40+
/*
41+
* keyring->description points to the name of the keyring
42+
* (such as ".builtin_trusted_keys", ".ima", etc.) to
43+
* which the given key is linked to.
44+
*
45+
* The name of the keyring is passed in the "eventname"
46+
* parameter to process_buffer_measurement() and is set
47+
* in the "eventname" field in ima_event_data for
48+
* the key measurement IMA event.
49+
*/
50+
process_buffer_measurement(payload, payload_len,
51+
keyring->description, KEY_CHECK, 0);
52+
}

0 commit comments

Comments
 (0)