Skip to contentSkip to conversation

IMA: Handle early boot data measurement

PATCH Superseded Lakshmi Ramasubramanian 2 participants 8 messages Aug 21, 2020 – Aug 25, 2020

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IMA: Handle early boot data measurement

The current implementation of early boot measurement in
the IMA subsystem is very specific to asymmetric keys. It does not handle early boot measurement of data from other subsystems such as Linux Security Module (LSM), Device-Mapper, etc. As a result data, provided by these subsystems during system boot are not measured by IMA.

Update the early boot key measurement to handle any early boot data. Refactor the code from ima_queue_keys.c to a new file ima_queue_data.c. Rename the kernel configuration CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS to CONFIG_IMA_QUEUE_EARLY_BOOT_DATA so it can be used for enabling any early boot data measurement. Since measurement of asymmetric keys is the first consumer of early boot measurement, this kernel configuration is enabled if IMA_MEASURE_ASYMMETRIC_KEYS and SYSTEM_TRUSTED_KEYRING are both enabled.

Update the IMA hook ima_measure_critical_data() to utilize early boot measurement support.

This patch is dependent on the following patch series:

	https://patchwork.kernel.org/patch/11709527/
	https://patchwork.kernel.org/patch/11730193/
---
 security/integrity/ima/Kconfig               |   2 +-
 security/integrity/ima/Makefile              |   2 +-
 security/integrity/ima/ima.h                 |  37 ++--
 security/integrity/ima/ima_asymmetric_keys.c |   7 +-
 security/integrity/ima/ima_init.c            |   2 +-
 security/integrity/ima/ima_main.c            |  10 +
 security/integrity/ima/ima_policy.c          |   2 +-
 security/integrity/ima/ima_queue_data.c      | 191 +++++++++++++++++++
 security/integrity/ima/ima_queue_keys.c      | 175 -----------------
 9 files changed, 231 insertions(+), 197 deletions(-)
 create mode 100644 security/integrity/ima/ima_queue_data.c
 delete mode 100644 security/integrity/ima/ima_queue_keys.c
security/integrity/ima/Kconfig +1 -1
index 080c53545ff0..bc2adab7bae2 100644
@@ -322,7 +322,7 @@ config IMA_MEASURE_ASYMMETRIC_KEYS
 	depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE=y
 	default y
 
-config IMA_QUEUE_EARLY_BOOT_KEYS
+config IMA_QUEUE_EARLY_BOOT_DATA
 	bool
 	depends on IMA_MEASURE_ASYMMETRIC_KEYS
 	depends on SYSTEM_TRUSTED_KEYRING
security/integrity/ima/Makefile +1 -1
index 67dabca670e2..6a0f9ef93bf0 100644
@@ -13,4 +13,4 @@ ima-$(CONFIG_IMA_APPRAISE_MODSIG) += ima_modsig.o
 ima-$(CONFIG_HAVE_IMA_KEXEC) += ima_kexec.o
 ima-$(CONFIG_IMA_BLACKLIST_KEYRING) += ima_mok.o
 ima-$(CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS) += ima_asymmetric_keys.o
-ima-$(CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS) += ima_queue_keys.o
+ima-$(CONFIG_IMA_QUEUE_EARLY_BOOT_DATA) += ima_queue_data.o
\ No newline at end of file
security/integrity/ima/ima.h +22 -15
index 00b84052c8f1..366d7cb5c22e 100644
@@ -228,29 +228,36 @@ extern const char *const func_tokens[];
 
 struct modsig;
 
-#ifdef CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS
+#ifdef CONFIG_IMA_QUEUE_EARLY_BOOT_DATA
 /*
  * To track keys that need to be measured.
  */
-struct ima_key_entry {
+struct ima_data_entry {
 	struct list_head list;
 	void *payload;
 	size_t payload_len;
-	char *keyring_name;
+	const char *event_name;
+	const char *event_data;
+	enum ima_hooks func;
+	bool measure_payload_hash;
 };
-void ima_init_key_queue(void);
-bool ima_should_queue_key(void);
-bool ima_queue_key(struct key *keyring, const void *payload,
-		   size_t payload_len);
-void ima_process_queued_keys(void);
+void ima_init_data_queue(void);
+bool ima_should_queue_data(void);
+bool ima_queue_data(const char *event_name, const void *payload,
+		    size_t payload_len, const char *event_data,
+		    enum ima_hooks func, bool measure_payload_hash);
+void ima_process_queued_data(void);
 #else
-static inline void ima_init_key_queue(void) {}
-static inline bool ima_should_queue_key(void) { return false; }
-static inline bool ima_queue_key(struct key *keyring,
-				 const void *payload,
-				 size_t payload_len) { return false; }
-static inline void ima_process_queued_keys(void) {}
-#endif /* CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS */
+static inline void ima_init_data_queue(void) {}
+static inline bool ima_should_queue_data(void) { return false; }
+static inline bool ima_queue_data(const char *event_name,
+				  const void *payload,
+				  size_t payload_len,
+				  const char *event_data,
+				  enum ima_hooks func,
+				  bool measure_payload_hash) { return false; }
+static inline void ima_process_queued_data(void) {}
+#endif /* CONFIG_IMA_QUEUE_EARLY_BOOT_DATA */
 
 /* LIM API function definitions */
 int ima_get_action(struct inode *inode, const struct cred *cred, u32 secid,
security/integrity/ima/ima_asymmetric_keys.c +4 -3
index a74095793936..65423754765f 100644
@@ -37,9 +37,10 @@ void ima_post_key_create_or_update(struct key *keyring, struct key *key,
 	if (!payload || (payload_len == 0))
 		return;
 
-	if (ima_should_queue_key())
-		queued = ima_queue_key(keyring, payload, payload_len);
-
+	if (ima_should_queue_data())
+		queued = ima_queue_data(keyring->description, payload,
+					payload_len, keyring->description,
+					KEY_CHECK, false);
 	if (queued)
 		return;
 
security/integrity/ima/ima_init.c +1 -1
index 4902fe7bd570..892894bf4af3 100644
@@ -145,7 +145,7 @@ int __init ima_init(void)
 	if (rc != 0)
 		return rc;
 
-	ima_init_key_queue();
+	ima_init_data_queue();
 
 	return rc;
 }
security/integrity/ima/ima_main.c +10 -0
index 5db6dc3d45aa..728557662903 100644
@@ -885,9 +885,19 @@ int ima_measure_critical_data(const char *event_name,
 			      const void *buf, int buf_len,
 			      bool measure_buf_hash)
 {
+	bool queued = false;
+
 	if (!event_name || !event_data_source || !buf || !buf_len)
 		return -EINVAL;
 
+	if (ima_should_queue_data())
+		queued = ima_queue_data(event_name, buf, buf_len,
+					event_data_source, CRITICAL_DATA,
+					measure_buf_hash);
+
+	if (queued)
+		return 0;
+
 	return process_buffer_measurement(NULL, buf, buf_len, event_name,
 					  CRITICAL_DATA, 0, event_data_source,
 					  measure_buf_hash);
security/integrity/ima/ima_policy.c +1 -1
index 59058ce7906b..f4f095ae6f8f 100644
@@ -906,7 +906,7 @@ void ima_update_policy(void)
 	ima_update_policy_flag();
 
 	/* Custom IMA policy has been loaded */
-	ima_process_queued_keys();
+	ima_process_queued_data();
 }
 
 /* Keep the enumeration in sync with the policy_tokens! */
security/integrity/ima/ima_queue_data.c new file +191 -0

191 lines not on this page · raw message

security/integrity/ima/ima_queue_keys.c deleted +0 -175

175 lines not on this page · raw message

Signature · 1 line
2.28.0
maintainer
#1 lore raw
Quoted 15 lines · Lakshmi Ramasubramanian

The current implementation of early boot measurement in
the IMA subsystem is very specific to asymmetric keys. It does not handle early boot measurement of data from other subsystems such as Linux Security Module (LSM), Device-Mapper, etc. As a result data, provided by these subsystems during system boot are not measured by IMA.

Update the early boot key measurement to handle any early boot data. Refactor the code from ima_queue_keys.c to a new file ima_queue_data.c. Rename the kernel configuration CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS to CONFIG_IMA_QUEUE_EARLY_BOOT_DATA so it can be used for enabling any early boot data measurement. Since measurement of asymmetric keys is the first consumer of early boot measurement, this kernel configuration is enabled if IMA_MEASURE_ASYMMETRIC_KEYS and SYSTEM_TRUSTED_KEYRING are both enabled.

Quoted 2 lines

Update the IMA hook ima_measure_critical_data() to utilize early boot measurement support.

Please limit the changes in this patch to renaming the functions and/or files. For example, adding "measure_payload_hash" should be a separate patch, not hidden here.

Mimi

#2 lore raw
Quoted 16 lines · Mimi Zohar
Quoted 15 lines · Lakshmi Ramasubramanian

The current implementation of early boot measurement in
the IMA subsystem is very specific to asymmetric keys. It does not handle early boot measurement of data from other subsystems such as Linux Security Module (LSM), Device-Mapper, etc. As a result data, provided by these subsystems during system boot are not measured by IMA.

Update the early boot key measurement to handle any early boot data. Refactor the code from ima_queue_keys.c to a new file ima_queue_data.c. Rename the kernel configuration CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS to CONFIG_IMA_QUEUE_EARLY_BOOT_DATA so it can be used for enabling any early boot data measurement. Since measurement of asymmetric keys is the first consumer of early boot measurement, this kernel configuration is enabled if IMA_MEASURE_ASYMMETRIC_KEYS and SYSTEM_TRUSTED_KEYRING are both enabled.

Quoted 7 lines
Quoted 2 lines

Update the IMA hook ima_measure_critical_data() to utilize early boot measurement support.

Please limit the changes in this patch to renaming the functions and/or files. For example, adding "measure_payload_hash" should be a separate patch, not hidden here.

Thanks for the feedback Mimi.

I'll split this into 2 patches:

PATCH 1: Rename files + rename CONFIG
PATCH 2: Update IMA hook to utilize early boot data measurement.

-lakshmi

maintainer
#3 lore raw
Quoted 25 lines · Lakshmi Ramasubramanian
Quoted 16 lines · Mimi Zohar
Quoted 15 lines · Lakshmi Ramasubramanian

The current implementation of early boot measurement in
the IMA subsystem is very specific to asymmetric keys. It does not handle early boot measurement of data from other subsystems such as Linux Security Module (LSM), Device-Mapper, etc. As a result data, provided by these subsystems during system boot are not measured by IMA.

Update the early boot key measurement to handle any early boot data. Refactor the code from ima_queue_keys.c to a new file ima_queue_data.c. Rename the kernel configuration CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS to CONFIG_IMA_QUEUE_EARLY_BOOT_DATA so it can be used for enabling any early boot data measurement. Since measurement of asymmetric keys is the first consumer of early boot measurement, this kernel configuration is enabled if IMA_MEASURE_ASYMMETRIC_KEYS and SYSTEM_TRUSTED_KEYRING are both enabled.

Quoted 7 lines
Quoted 2 lines

Update the IMA hook ima_measure_critical_data() to utilize early boot measurement support.

Please limit the changes in this patch to renaming the functions and/or files. For example, adding "measure_payload_hash" should be a separate patch, not hidden here.

Quoted 6 lines

Thanks for the feedback Mimi.

I'll split this into 2 patches:

PATCH 1: Rename files + rename CONFIG
PATCH 2: Update IMA hook to utilize early boot data measurement.

I'm referring to introducing the "measure_payload_hash" flag. I assume this is to indicate whether the buffer should be hashed or not.

Example 1: ima_alloc_key_entry() and ima_alloc_data_entry(0 comparison

Review

Quoted 13 lines
(quoted diff) +7 -4
-static struct ima_key_entry *ima_alloc_key_entry(struct key *keyring,
-                                                const void *payload,
-                                                size_t payload_len)
-{
 
 
+static struct ima_data_entry *ima_alloc_data_entry(const char *event_name,
+                                                  const void *payload,
+                                                  size_t payload_len,
+                                                  const char *event_data,
+                                                  enum ima_hooks func,
+                                                  bool measure_payload_hash)  <====
+{

Example 2:

security/integrity/ima/ima_asymmetric_keys.c +4 -3
index a74095793936..65423754765f 100644
@@ -37,9 +37,10 @@ void ima_post_key_create_or_update(struct key *keyring, struct key *key,
        if (!payload || (payload_len == 0))
                return;
 
-       if (ima_should_queue_key())
-               queued = ima_queue_key(keyring, payload, payload_len);
-
+       if (ima_should_queue_data())
+               queued = ima_queue_data(keyring->description, payload,
+                                       payload_len, keyring->description,
+                                       KEY_CHECK, false);   <===
        if (queued)
                return;
 

But in general, as much as possible function and file name changes should be done independently of other changes.

thanks,

Mimi

#4 lore raw
Quoted 53 lines · Mimi Zohar
Quoted 6 lines
Quoted 5 lines

Please limit the changes in this patch to renaming the functions and/or files. For example, adding "measure_payload_hash" should be a separate patch, not hidden here.

Quoted 6 lines

Thanks for the feedback Mimi.

I'll split this into 2 patches:

PATCH 1: Rename files + rename CONFIG
PATCH 2: Update IMA hook to utilize early boot data measurement.

I'm referring to introducing the "measure_payload_hash" flag. I assume this is to indicate whether the buffer should be hashed or not.

Example 1: ima_alloc_key_entry() and ima_alloc_data_entry(0 comparison

Review

Quoted 13 lines
(quoted diff) +7 -4
-static struct ima_key_entry *ima_alloc_key_entry(struct key *keyring,
-                                                const void *payload,
-                                                size_t payload_len)
-{
 
 
+static struct ima_data_entry *ima_alloc_data_entry(const char *event_name,
+                                                  const void *payload,
+                                                  size_t payload_len,
+                                                  const char *event_data,
+                                                  enum ima_hooks func,
+                                                  bool measure_payload_hash)  <====
+{

Example 2:

security/integrity/ima/ima_asymmetric_keys.c +4 -3
index a74095793936..65423754765f 100644
@@ -37,9 +37,10 @@ void ima_post_key_create_or_update(struct key *keyring, struct key *key,
         if (!payload || (payload_len == 0))
                 return;
 
-       if (ima_should_queue_key())
-               queued = ima_queue_key(keyring, payload, payload_len);
-
+       if (ima_should_queue_data())
+               queued = ima_queue_data(keyring->description, payload,
+                                       payload_len, keyring->description,
+                                       KEY_CHECK, false);   <===
         if (queued)
                 return;
 

But in general, as much as possible function and file name changes should be done independently of other changes.

Quoted 1 line

thanks,

I agree - but in this case, Tushar's patch series on adding support for "Critical Data" measurement has already introduced "measure_payload_hash" flag. His patch updates "process_buffer_measurement()" to take this new flag and measure hash of the given data.

My patches extend that to queuing the early boot requests and processing them after a custom IMA policy is loaded.

If you still think "measure_payload_hash" flag should be introduced in the queuing change as a separate patch I'll split the patches further. Please let me know.

thanks,
-lakshmi

maintainer
#5 lore raw
Quoted 60 lines · Lakshmi Ramasubramanian
Quoted 50 lines · Mimi Zohar
Quoted 11 lines
Quoted 4 lines

Please limit the changes in this patch to renaming the functions and/or files. For example, adding "measure_payload_hash" should be a separate patch, not hidden here.

Thanks for the feedback Mimi.

I'll split this into 2 patches:

PATCH 1: Rename files + rename CONFIG
PATCH 2: Update IMA hook to utilize early boot data measurement.

I'm referring to introducing the "measure_payload_hash" flag. I assume this is to indicate whether the buffer should be hashed or not.

Example 1: ima_alloc_key_entry() and ima_alloc_data_entry(0 comparison

Review

Quoted 11 lines
(quoted diff) +7 -4
-static struct ima_key_entry *ima_alloc_key_entry(struct key *keyring,
-                                                const void *payload,
-                                                size_t payload_len)
-{
+static struct ima_data_entry *ima_alloc_data_entry(const char *event_name,
+                                                  const void *payload,
+                                                  size_t payload_len,
+                                                  const char *event_data,
+                                                  enum ima_hooks func,
+                                                  bool measure_payload_hash)  <====
+{

Example 2:

security/integrity/ima/ima_asymmetric_keys.c +4 -3
index a74095793936..65423754765f 100644
@@ -37,9 +37,10 @@ void ima_post_key_create_or_update(struct key *keyring, struct key *key,
         if (!payload || (payload_len == 0))
                 return;
 
-       if (ima_should_queue_key())
-               queued = ima_queue_key(keyring, payload, payload_len);
-
+       if (ima_should_queue_data())
+               queued = ima_queue_data(keyring->description, payload,
+                                       payload_len, keyring->description,
+                                       KEY_CHECK, false);   <===
         if (queued)
                 return;
 

But in general, as much as possible function and file name changes should be done independently of other changes.

Quoted 1 line

thanks,

I agree - but in this case, Tushar's patch series on adding support for "Critical Data" measurement has already introduced "measure_payload_hash" flag. His patch updates "process_buffer_measurement()" to take this new flag and measure hash of the given data.

Quoted 6 lines

My patches extend that to queuing the early boot requests and processing them after a custom IMA policy is loaded.

If you still think "measure_payload_hash" flag should be introduced in the queuing change as a separate patch I'll split the patches further. Please let me know.

There's a major problem if his changes add new function arguments without modifying all the callers of the function. I assume the kernel would fail to compile properly.

Changing the function parameters to include "measure_payload_hash" needs to be a separate patch, whether it is part of his patch set or yours.

Mimi

#6 lore raw
Quoted 64 lines · Mimi Zohar
Quoted 63 lines · Lakshmi Ramasubramanian
Quoted 50 lines · Mimi Zohar
Quoted 11 lines
Quoted 4 lines

Please limit the changes in this patch to renaming the functions and/or files. For example, adding "measure_payload_hash" should be a separate patch, not hidden here.

Thanks for the feedback Mimi.

I'll split this into 2 patches:

PATCH 1: Rename files + rename CONFIG
PATCH 2: Update IMA hook to utilize early boot data measurement.

I'm referring to introducing the "measure_payload_hash" flag. I assume this is to indicate whether the buffer should be hashed or not.

Example 1: ima_alloc_key_entry() and ima_alloc_data_entry(0 comparison

Review

Quoted 11 lines
(quoted diff) +7 -4
-static struct ima_key_entry *ima_alloc_key_entry(struct key *keyring,
-                                                const void *payload,
-                                                size_t payload_len)
-{
+static struct ima_data_entry *ima_alloc_data_entry(const char *event_name,
+                                                  const void *payload,
+                                                  size_t payload_len,
+                                                  const char *event_data,
+                                                  enum ima_hooks func,
+                                                  bool measure_payload_hash)  <====
+{

Example 2:

security/integrity/ima/ima_asymmetric_keys.c +4 -3
index a74095793936..65423754765f 100644
@@ -37,9 +37,10 @@ void ima_post_key_create_or_update(struct key *keyring, struct key *key,
          if (!payload || (payload_len == 0))
                  return;
 
-       if (ima_should_queue_key())
-               queued = ima_queue_key(keyring, payload, payload_len);
-
+       if (ima_should_queue_data())
+               queued = ima_queue_data(keyring->description, payload,
+                                       payload_len, keyring->description,
+                                       KEY_CHECK, false);   <===
          if (queued)
                  return;
 

But in general, as much as possible function and file name changes should be done independently of other changes.

Quoted 1 line

thanks,

I agree - but in this case, Tushar's patch series on adding support for "Critical Data" measurement has already introduced "measure_payload_hash" flag. His patch updates "process_buffer_measurement()" to take this new flag and measure hash of the given data.

My patches extend that to queuing the early boot requests and processing them after a custom IMA policy is loaded.

Quoted 7 lines
Quoted 3 lines

If you still think "measure_payload_hash" flag should be introduced in the queuing change as a separate patch I'll split the patches further. Please let me know.

There's a major problem if his changes add new function arguments without modifying all the callers of the function. I assume the kernel would fail to compile properly.

Tushar's patch series does update all the existing callers of process_buffer_measurement() to handle the new arguments. His patch series is self contained, and builds and works fine.

Quoted 5 lines

Changing the function parameters to include "measure_payload_hash" needs to be a separate patch, whether it is part of his patch set or yours.

ok - I'll split the queuing patch to include "measure_payload_hash" in a separate patch.

thanks,
-lakshmi

maintainer
#7 lore raw
Quoted 69 lines · Lakshmi Ramasubramanian
Quoted 68 lines · Mimi Zohar
Quoted 66 lines · Lakshmi Ramasubramanian
Quoted 50 lines · Mimi Zohar
Quoted 11 lines
Quoted 4 lines

Please limit the changes in this patch to renaming the functions and/or files. For example, adding "measure_payload_hash" should be a separate patch, not hidden here.

Thanks for the feedback Mimi.

I'll split this into 2 patches:

PATCH 1: Rename files + rename CONFIG
PATCH 2: Update IMA hook to utilize early boot data measurement.

I'm referring to introducing the "measure_payload_hash" flag. I assume this is to indicate whether the buffer should be hashed or not.

Example 1: ima_alloc_key_entry() and ima_alloc_data_entry(0 comparison

Review

Quoted 11 lines
(quoted diff) +7 -4
-static struct ima_key_entry *ima_alloc_key_entry(struct key *keyring,
-                                                const void *payload,
-                                                size_t payload_len)
-{
+static struct ima_data_entry *ima_alloc_data_entry(const char *event_name,
+                                                  const void *payload,
+                                                  size_t payload_len,
+                                                  const char *event_data,
+                                                  enum ima_hooks func,
+                                                  bool measure_payload_hash)  <====
+{

Example 2:

security/integrity/ima/ima_asymmetric_keys.c +4 -3
index a74095793936..65423754765f 100644
@@ -37,9 +37,10 @@ void ima_post_key_create_or_update(struct key *keyring, struct key *key,
          if (!payload || (payload_len == 0))
                  return;
 
-       if (ima_should_queue_key())
-               queued = ima_queue_key(keyring, payload, payload_len);
-
+       if (ima_should_queue_data())
+               queued = ima_queue_data(keyring->description, payload,
+                                       payload_len, keyring->description,
+                                       KEY_CHECK, false);   <===
          if (queued)
                  return;
 

But in general, as much as possible function and file name changes should be done independently of other changes.

Quoted 1 line

thanks,

I agree - but in this case, Tushar's patch series on adding support for "Critical Data" measurement has already introduced "measure_payload_hash" flag. His patch updates "process_buffer_measurement()" to take this new flag and measure hash of the given data.

My patches extend that to queuing the early boot requests and processing them after a custom IMA policy is loaded.

If you still think "measure_payload_hash" flag should be introduced in the queuing change as a separate patch I'll split the patches further. Please let me know.

Quoted 7 lines
Quoted 3 lines

There's a major problem if his changes add new function arguments without modifying all the callers of the function. I assume the kernel would fail to compile properly.

Tushar's patch series does update all the existing callers of process_buffer_measurement() to handle the new arguments. His patch series is self contained, and builds and works fine.

Yes, he's added "false" to existing calls. Still, defining a new IMA
hook should be independent of adding this "measure_payload_hash"
parameter. Each with its own patch description.

Quoted 8 lines
Quoted 5 lines

Changing the function parameters to include "measure_payload_hash" needs to be a separate patch, whether it is part of his patch set or yours.

ok - I'll split the queuing patch to include "measure_payload_hash" in a separate patch.

thanks,

Mimi