Skip to contentSkip to conversation

ima: define an init_module critical data record

PATCH In review Mimi Zohar 2 participants 4 messages Mar 27, 2024 – Mar 28, 2024

Subsystems (4)
lore
Share & tools
lore

Mimi Zohar

author maintainer
#0 lore raw

PATCH 1/1 ima: define an init_module critical data record

The init_module syscall loads an ELF image into kernel space without measuring the buffer containing the ELF image. To close this kernel module integrity gap, define a new critical-data record which includes the hash of the ELF image.

Instead of including the buffer data in the IMA measurement list, include the hash of the buffer data to avoid large IMA measurement list records. The buffer data hash would be the same value as the finit_module syscall file hash.

To enable measuring the init_module buffer and other critical data from boot, define "ima_policy=critical_data" on the boot command line. Since builtin policies are not persistent, a custom IMA policy must include the rule as well: measure func=CRITICAL_DATA label=modules

To verify the template data hash value, first convert the buffer data hash to binary:

grep "init_module" \
	/sys/kernel/security/integrity/ima/ascii_runtime_measurements | \
	tail -1 | cut -d' ' -f 6 | xxd -r -p | sha256sum
---
 security/integrity/ima/ima_main.c | 7 +++++++
 1 file changed, 7 insertions(+)
security/integrity/ima/ima_main.c +7 -0
index c84e8c55333d..4b4348d681a6 100644
@@ -902,6 +902,13 @@ static int ima_post_load_data(char *buf, loff_t size,
 		return 0;
 	}
 
+	/*
+	 * Measure the init_module syscall buffer containing the ELF image.
+	 */
+	if (load_id == LOADING_MODULE)
+		ima_measure_critical_data("modules", "init_module",
+					  buf, size, true, NULL, 0);
+
 	return 0;
 }
 
Signature · 1 line
2.39.3
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 32 lines · Mimi Zohar

The init_module syscall loads an ELF image into kernel space without measuring the buffer containing the ELF image. To close this kernel module integrity gap, define a new critical-data record which includes the hash of the ELF image.

Instead of including the buffer data in the IMA measurement list, include the hash of the buffer data to avoid large IMA measurement list records. The buffer data hash would be the same value as the finit_module syscall file hash.

To enable measuring the init_module buffer and other critical data from boot, define "ima_policy=critical_data" on the boot command line. Since builtin policies are not persistent, a custom IMA policy must include the rule as well: measure func=CRITICAL_DATA label=modules

To verify the template data hash value, first convert the buffer data hash to binary:

grep "init_module" \
	/sys/kernel/security/integrity/ima/ascii_runtime_measurements | \
	tail -1 | cut -d' ' -f 6 | xxd -r -p | sha256sum
---
 security/integrity/ima/ima_main.c | 7 +++++++
 1 file changed, 7 insertions(+)
security/integrity/ima/ima_main.c +0 -0
index c84e8c55333d..4b4348d681a6 100644

security/integrity/ima/ima_main.c static int ima_post_load_data(char *buf, loff_t size, · line 910

Quoted 9 lines
security/integrity/ima/ima_main.c +6 -0
@@ -902,6 +902,13 @@ static int ima_post_load_data(char *buf, loff_t size,
 		return 0;
 	}
 
+	/*
+	 * Measure the init_module syscall buffer containing the ELF image.
+	 */
+	if (load_id == LOADING_MODULE)
+		ima_measure_critical_data("modules", "init_module",
+					  buf, size, true, NULL, 0);

No reason not to ack but could be just as well (passing checkpatch):

	if (load_id == LOADING_MODULE)
		ima_measure_critical_data("modules", "init_module", buf, size, true, NULL, 0);

< 100 characters

security/integrity/ima/ima_main.c static int ima_post_load_data(char *buf, loff_t size, · line 914

Quoted 4 lines
security/integrity/ima/ima_main.c +1 -0
+
 	return 0;
 }
 

BR, Jarkko

author maintainer
#2 lore raw
Quoted 37 lines · Jarkko Sakkinen
Quoted 36 lines · Mimi Zohar

The init_module syscall loads an ELF image into kernel space without measuring the buffer containing the ELF image. To close this kernel module integrity gap, define a new critical-data record which includes the hash of the ELF image.

Instead of including the buffer data in the IMA measurement list, include the hash of the buffer data to avoid large IMA measurement list records. The buffer data hash would be the same value as the finit_module syscall file hash.

To enable measuring the init_module buffer and other critical data from boot, define "ima_policy=critical_data" on the boot command line. Since builtin policies are not persistent, a custom IMA policy must include the rule as well: measure func=CRITICAL_DATA label=modules

To verify the template data hash value, first convert the buffer data hash to binary:

grep "init_module" \
	/sys/kernel/security/integrity/ima/ascii_runtime_measurements | \
	tail -1 | cut -d' ' -f 6 | xxd -r -p | sha256sum
---
 security/integrity/ima/ima_main.c | 7 +++++++
 1 file changed, 7 insertions(+)
security/integrity/ima/ima_main.c +0 -0
index c84e8c55333d..4b4348d681a6 100644
@@ -902,6 +902,13 @@ static int ima_post_load_data(char *buf, loff_t size,
 		return 0;
 	}
 
Quoted 8 lines

security/integrity/ima/ima_main.c static int ima_post_load_data(char *buf, loff_t size, · line 910

Quoted 6 lines
security/integrity/ima/ima_main.c +6 -0
+	/*
+	 * Measure the init_module syscall buffer containing the ELF image.
+	 */
+	if (load_id == LOADING_MODULE)
+		ima_measure_critical_data("modules", "init_module",
+					  buf, size, true, NULL, 0);

No reason not to ack but could be just as well (passing checkpatch):

Please review the tag usage as defined in
https://docs.kernel.org/process/submitting-patches.html.

Quoted 6 lines
	if (load_id == LOADING_MODULE)
		ima_measure_critical_data("modules", "init_module", buf, size,

true, NULL, 0);

< 100 characters

From what I understand, it's still preferable to stay under the 80 character limit, but checkpatch.pl will not complain. From
https://www.kernel.org/doc/Documentation/process/maintainer-tip.rst:

"The 80 character rule is not a strict rule, so please use common sense when breaking lines. Especially format strings should never be broken up."

Quoted 7 lines

security/integrity/ima/ima_main.c static int ima_post_load_data(char *buf, loff_t size, · line 914

Quoted 5 lines
security/integrity/ima/ima_main.c +1 -0
+
 	return 0;
 }
 

Thanks!

Mimi

maintainer
#3 lore raw
Quoted 55 lines · Mimi Zohar
Quoted 37 lines · Jarkko Sakkinen
Quoted 36 lines · Mimi Zohar

The init_module syscall loads an ELF image into kernel space without measuring the buffer containing the ELF image. To close this kernel module integrity gap, define a new critical-data record which includes the hash of the ELF image.

Instead of including the buffer data in the IMA measurement list, include the hash of the buffer data to avoid large IMA measurement list records. The buffer data hash would be the same value as the finit_module syscall file hash.

To enable measuring the init_module buffer and other critical data from boot, define "ima_policy=critical_data" on the boot command line. Since builtin policies are not persistent, a custom IMA policy must include the rule as well: measure func=CRITICAL_DATA label=modules

To verify the template data hash value, first convert the buffer data hash to binary:

grep "init_module" \
	/sys/kernel/security/integrity/ima/ascii_runtime_measurements | \
	tail -1 | cut -d' ' -f 6 | xxd -r -p | sha256sum
---
 security/integrity/ima/ima_main.c | 7 +++++++
 1 file changed, 7 insertions(+)
security/integrity/ima/ima_main.c +0 -0
index c84e8c55333d..4b4348d681a6 100644
@@ -902,6 +902,13 @@ static int ima_post_load_data(char *buf, loff_t size,
 		return 0;
 	}
 
Quoted 8 lines

security/integrity/ima/ima_main.c static int ima_post_load_data(char *buf, loff_t size, · line 910

Quoted 6 lines
security/integrity/ima/ima_main.c +6 -0
+	/*
+	 * Measure the init_module syscall buffer containing the ELF image.
+	 */
+	if (load_id == LOADING_MODULE)
+		ima_measure_critical_data("modules", "init_module",
+					  buf, size, true, NULL, 0);

No reason not to ack but could be just as well (passing checkpatch):

Please review the tag usage as defined in
https://docs.kernel.org/process/submitting-patches.html.

Quoted 5 lines
	if (load_id == LOADING_MODULE)
		ima_measure_critical_data("modules", "init_module", buf, size,

true, NULL, 0);

Quoted 8 lines
Quoted 1 line

< 100 characters

From what I understand, it's still preferable to stay under the 80 character limit, but checkpatch.pl will not complain. From
https://www.kernel.org/doc/Documentation/process/maintainer-tip.rst:

"The 80 character rule is not a strict rule, so please use common sense when breaking lines. Especially format strings should never be broken up."

I agree with that is your decision to make (as maintainer of IMA)!

BTW, I guess process/coding-style.rst would be better ref here because maintainer-tip.rst is meant only for arch/x86 tree (aka tip.git).

That said, both maintainer-tip.rst and coding-style.rst recommend the same 80 character length. I have no idea whether 80 or 100 character should be considered as "recommended".

The formatted string example is somewhat weird too because you should not break that even if it was 150 characters so it does not have any relation to 100 character limit...

R, Jarkko