Skip to contentSkip to conversation

public key: IMA signer logging: Add a new template ima-sigkey to store/read the public, key of ima signature signer

PATCH In review Lakshmi 1 participant 1 message May 14, 2019

Subsystems (5)
lore
Share & tools
lore

Lakshmi

author
#0 lore raw

PATCH 2/2 public key: IMA signer logging: Add a new template ima-sigkey to store/read the public, key of ima signature signer

IMA signer log (created using ima-sig template) contains the IMA signature of the file. The IMA signature includes the key identifier of the key that was used to generate the IMA signature.

Outside the client machine this key id is not sufficient to uniquely determine which key the IMA signature corresponds to. Providing the public key of the signer in the IMA log would allow, for example, an attestation service to uniquely and securely verify if the key used to generate the IMA signature is a valid and trusted one, and that the key has not been revoked or expired.

To attest that the system files loaded on the client were signed by valid and trusted keys, an attestation service would just have to maintain a list of valid public keys. Using the data in the IMA log the service can attest the system files loaded on the client machine.

This patch set depends on another patch
([PATCH 1/2] public key: IMA signer logging: Add support for querying public key from a given key) that includes a new interface method namely query_public_key in asymmetric_key_subtype interface. query_public_key method returns the public key part of the given key.

IMA will verify the IMA signature of the file, invoke the above method to query the public key of the IMA signature signer and add that to the IMA signer log.

Defined a new template namely ima-sigkey to store\read the public key of the IMA signature signer. This template extends the existing template ima-sig.

Added integrity_get_signer_key that returns the public key of the IMA signature signer by calling the newly added method asymmetric_signer_public_key in digsig_asymmetric.c.

Added ima_eventsigkey_init to initialize the data for ima-sigkey template and ima_show_template_sigkey to display the ima-sigkey template data.

---
 .../admin-guide/kernel-parameters.txt         |  2 +-
 Documentation/security/IMA-templates.rst      |  5 +-
 security/integrity/digsig.c                   | 54 +++++++++++++++++--
 security/integrity/digsig_asymmetric.c        | 44 +++++++++++++++
 security/integrity/ima/Kconfig                |  3 ++
 security/integrity/ima/ima_template.c         |  3 ++
 security/integrity/ima/ima_template_lib.c     | 43 +++++++++++++++
 security/integrity/ima/ima_template_lib.h     |  4 ++
 security/integrity/integrity.h                | 29 +++++++++-
 9 files changed, 180 insertions(+), 7 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +1 -1
index 2b8ee90bb644..d51375caadce 100644
@@ -1632,7 +1632,7 @@
 
 	ima_template=	[IMA]
 			Select one of defined IMA measurements template formats.
-			Formats: { "ima" | "ima-ng" | "ima-sig" }
+            Formats: { "ima" | "ima-ng" | "ima-sig" | "ima-sigkey" }
 			Default: "ima-ng"
 
 	ima_template_fmt=
Documentation/security/IMA-templates.rst +3 -2
index 2cd0e273cc9a..3082e0f73313 100644
@@ -70,14 +70,15 @@ descriptors by adding their identifier to the format string
    prefix is shown only if the hash algorithm is not SHA1 or MD5);
  - 'n-ng': the name of the event, without size limitations;
  - 'sig': the file signature.
+ - 'sigkey': public key corresponding to the file signature
 
 
 Below, there is the list of defined template descriptors:
 
  - "ima": its format is ``d|n``;
  - "ima-ng" (default): its format is ``d-ng|n-ng``;
- - "ima-sig": its format is ``d-ng|n-ng|sig``.
-
+ - "ima-sig": its format is ``d-ng|n-ng|sig``;
+ - "ima-sigkey": its format is ``d-ng|n-ng|sig|sigkey``.
 
 
 Use
security/integrity/digsig.c +48 -0

52 lines not on this page · raw message

int siglen,
const char *digest, int digestlen)
{
@@ -60,12 +108,12 @@ int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
}
}

- switch (sig[1]) {
- case 1:
+ switch (integrity_digsig_version(sig, siglen)) {
+ case INTEGRITY_SIGNATURE_VERSION_1:
/* v1 API expect signature without xattr type */ return digsig_verify(keyring[id], sig + 1, siglen - 1,
digest, digestlen);
- case 2:
+ case INTEGRITY_SIGNATURE_VERSION_2:
return asymmetric_verify(keyring[id], sig, siglen,
digest, digestlen);
}

security/integrity/digsig_asymmetric.c +44 -0

55 lines not on this page · raw message

requests
* @kmod_name: kernel module name

security/integrity/ima/Kconfig +3 -0
index a18f8c6d13b5..1a0bd266e869 100644
@@ -77,6 +77,8 @@ choice
 		bool "ima-ng (default)"
 	config IMA_SIG_TEMPLATE
 		bool "ima-sig"
+	config IMA_SIGKEY_TEMPLATE
+		bool "ima-sigkey"
 endchoice
 
 config IMA_DEFAULT_TEMPLATE
@@ -85,6 +87,7 @@ config IMA_DEFAULT_TEMPLATE
 	default "ima" if IMA_TEMPLATE
 	default "ima-ng" if IMA_NG_TEMPLATE
 	default "ima-sig" if IMA_SIG_TEMPLATE
+	default "ima-sigkey" if IMA_SIGKEY_TEMPLATE
 
 choice
 	prompt "Default integrity hash algorithm"
security/integrity/ima/ima_template.c +3 -0
index b631b8bc7624..4a92d80df96f 100644
@@ -26,6 +26,7 @@ static struct ima_template_desc builtin_templates[] = {
 	{.name = IMA_TEMPLATE_IMA_NAME, .fmt = IMA_TEMPLATE_IMA_FMT},
 	{.name = "ima-ng", .fmt = "d-ng|n-ng"},
 	{.name = "ima-sig", .fmt = "d-ng|n-ng|sig"},
+    {.name = "ima-sigkey", .fmt = "d-ng|n-ng|sig|sigkey"},
 	{.name = "", .fmt = ""},	/* placeholder for a custom format */
 };
 
@@ -43,6 +44,8 @@ static const struct ima_template_field supported_fields[] = {
 	 .field_show = ima_show_template_string},
 	{.field_id = "sig", .field_init = ima_eventsig_init,
 	 .field_show = ima_show_template_sig},
+    {.field_id = "sigkey", .field_init = ima_eventsigkey_init,
+     .field_show = ima_show_template_sigkey},
 };
 #define MAX_TEMPLATE_NAME_LEN 15
 
security/integrity/ima/ima_template_lib.c +43 -0

52 lines not on this page · raw message

security/integrity/ima/ima_template_lib.h +4 -0
index 6a3d8b831deb..db3328d0146b 100644
@@ -29,6 +29,8 @@ void ima_show_template_string(struct seq_file *m, enum ima_show_type show,
 			      struct ima_field_data *field_data);
 void ima_show_template_sig(struct seq_file *m, enum ima_show_type show,
 			   struct ima_field_data *field_data);
+void ima_show_template_sigkey(struct seq_file *m, enum ima_show_type show,
+               struct ima_field_data *field_data);
 int ima_parse_buf(void *bufstartp, void *bufendp, void **bufcurp,
 		  int maxfields, struct ima_field_data *fields, int *curfields,
 		  unsigned long *len_mask, int enforce_mask, char *bufname);
@@ -42,4 +44,6 @@ int ima_eventname_ng_init(struct ima_event_data *event_data,
 			  struct ima_field_data *field_data);
 int ima_eventsig_init(struct ima_event_data *event_data,
 		      struct ima_field_data *field_data);
+int ima_eventsigkey_init(struct ima_event_data *event_data,
+              struct ima_field_data *field_data);
 #endif /* __LINUX_IMA_TEMPLATE_LIB_H */
security/integrity/integrity.h +5 -0
index 7de59f44cba3..bd1bbd8d6b8e 100644
@@ -144,19 +144,38 @@ int integrity_kernel_read(struct file *file, loff_t offset,
 #define INTEGRITY_KEYRING_PLATFORM	2
 #define INTEGRITY_KEYRING_MAX		3
 
+/* Digital signature version number */
+#define INTEGRITY_SIGNATURE_VERSION_1 1
+#define INTEGRITY_SIGNATURE_VERSION_2 2
+
 extern struct dentry *integrity_dir;
 
 #ifdef CONFIG_INTEGRITY_SIGNATURE
 
+int integrity_digsig_version(const char *sig, int siglen);
 int integrity_digsig_verify(const unsigned int id, const char *sig, 

int siglen,
const char *digest, int digestlen);
-
+int integrity_get_signer_key(const unsigned int id,
+ const char *sig, int siglen,
+ void **signer_key, u32 *signer_keylen);
int __init integrity_init_keyring(const unsigned int id);
int __init integrity_load_x509(const unsigned int id, const char *path); int __init integrity_load_cert(const unsigned int id, const char *source,
const void *data, size_t len, key_perm_t perm);
#else

+static inline int integrity_digsig_version(const char *sig, int siglen)
+{
+ return -EOPNOTSUPP;
+}
+
+static inline int integrity_get_signer_key(const unsigned int id,
+ const char *sig, int siglen,
+ void **signer_key, u32 *signer_keylen)
+{
+ return -EOPNOTSUPP;
+}
+
static inline int integrity_digsig_verify(const unsigned int id,
const char *sig, int siglen, const char *digest, int digestlen)
@@ -181,12 +200,20 @@ static inline int __init integrity_load_cert(const unsigned int id,
#ifdef CONFIG_INTEGRITY_ASYMMETRIC_KEYS
int asymmetric_verify(struct key *keyring, const char *sig,
int siglen, const char *data, int datalen);
+int asymmetric_signer_public_key(struct key *keyring, const char *sig,
+ int siglen, void **signer_key, u32 *signer_keylen);
#else
static inline int asymmetric_verify(struct key *keyring, const char *sig,
int siglen, const char *data, int datalen)
{
return -EOPNOTSUPP;
}
+static inline int asymmetric_signer_public_key(struct key *keyring,
+ const char *sig, int siglen,
+ void **signer_key, u32 *signer_keylen)
+{
+ return -EOPNOTSUPP;
+}
#endif

#ifdef CONFIG_IMA_LOAD_X509

Signature · 1 line
2.17.1