Skip to contentSkip to conversation

IMA: policy can be updated zero times

PATCH In review Sasha Levin 3 participants 7 messages Dec 22, 2015 – Dec 23, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IMA: policy can be updated zero times

Commit "IMA: policy can now be updated multiple times" assumed that the policy would be updated at least once.

If there are zero updates, the temporary list head object will get added to the policy list, and later dereferenced as an IMA policy object, which means that invalid memory will be accessed.

---
 security/integrity/ima/ima_policy.c |    3 +++
 1 file changed, 3 insertions(+)
security/integrity/ima/ima_policy.c +3 -0
index ba5d2fc..9b958b8 100644
@@ -431,6 +431,9 @@ void ima_update_policy(void)
 {
 	struct list_head *first, *last, *policy;
 
+	if (list_empty(&ima_temp_rules))
+		return;
+
 	/* append current policy with the new rules */
 	first = (&ima_temp_rules)->next;
 	last = (&ima_temp_rules)->prev;
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 17 lines · Sasha Levin

Commit "IMA: policy can now be updated multiple times" assumed that the policy would be updated at least once.

If there are zero updates, the temporary list head object will get added to the policy list, and later dereferenced as an IMA policy object, which means that invalid memory will be accessed.

---
 security/integrity/ima/ima_policy.c |    3 +++
 1 file changed, 3 insertions(+)
security/integrity/ima/ima_policy.c +0 -0
index ba5d2fc..9b958b8 100644

security/integrity/ima/ima_policy.c void ima_update_policy(void) · line 439

Quoted 9 lines
security/integrity/ima/ima_policy.c +3 -0
@@ -431,6 +431,9 @@ void ima_update_policy(void)
 {
 	struct list_head *first, *last, *policy;
 
+	if (list_empty(&ima_temp_rules))
+		return;
+
 	/* append current policy with the new rules */
 	first = (&ima_temp_rules)->next;
 	last = (&ima_temp_rules)->prev;

Thanks, Sasha. By the time ima_update_policy() is called ima_release_policy() has already output the policy update status message. I guess an empty policy could be considered a valid policy. Could you add a msg indicating that the new policy was empty?

Mimi

#2 lore raw
Quoted 25 lines · Mimi Zohar
Quoted 1 line · Sasha Levin

Commit "IMA: policy can now be updated multiple times" assumed that

the

Quoted 3 lines

policy would be updated at least once.

If there are zero updates, the temporary list head object will get

added

Quoted 1 line

to the policy list, and later dereferenced as an IMA policy object,

which

Review

Quoted 8 lines

means that invalid memory will be accessed.

---
 security/integrity/ima/ima_policy.c |    3 +++
 1 file changed, 3 insertions(+)
(quoted diff) +0 -0

b/security/integrity/ima/ima_policy.c

Quoted 7 lines

index ba5d2fc..9b958b8 100644

security/integrity/ima/ima_policy.c +0 -0
@@ -431,6 +431,9 @@ void ima_update_policy(void)
 {
 	struct list_head *first, *last, *policy;
 
Quoted 11 lines

security/integrity/ima/ima_policy.c void ima_update_policy(void) · line 439

Quoted 6 lines
security/integrity/ima/ima_policy.c +3 -0
+	if (list_empty(&ima_temp_rules))
+		return;
+
 	/* append current policy with the new rules */
 	first = (&ima_temp_rules)->next;
 	last = (&ima_temp_rules)->prev;

Thanks, Sasha. By the time ima_update_policy() is called ima_release_policy() has already output the policy update status message. I guess an empty policy could be considered a valid policy. Could you add a msg indicating that the new policy was empty?

As far as I can say we can't get to ima_update_policy() with empty ima_temp_rules because ima_write_policy() will set valid_policy to 0 in case of an empty rule. I'll double check it tomorrow, but please you do that too.

cheers,
Petko

#3 lore raw
Quoted 6 lines · Petko Manolov
Quoted 4 lines

Thanks, Sasha. By the time ima_update_policy() is called

Quoted 3 lines

ima_release_policy() has already output the policy update status message. I guess an empty policy could be considered a valid policy. Could you add a msg indicating that the new policy was empty?

As far as I can say we can't get to ima_update_policy() with empty ima_temp_rules because ima_write_policy() will set valid_policy to 0 in case of an empty rule. I'll double check it tomorrow, but please you do that too.

This is based on an actual crash rather than code analysis.

Thanks,
Sasha

Acked-by
#4 lore raw
Quoted 6 lines · Sasha Levin
Quoted 5 lines · Petko Manolov
Quoted 4 lines

Thanks, Sasha. By the time ima_update_policy() is called

Quoted 3 lines

ima_release_policy() has already output the policy update status message. I guess an empty policy could be considered a valid policy. Could you add a msg indicating that the new policy was empty?

Quoted 6 lines
Quoted 4 lines

As far as I can say we can't get to ima_update_policy() with empty ima_temp_rules because ima_write_policy() will set valid_policy to 0 in case of an empty rule. I'll double check it tomorrow, but please you do that too.

This is based on an actual crash rather than code analysis.

I was able to reproduce the crash with: echo "" > /sys/kernel/security/ima/policy

It turns out ima_parse_add_rule() returns 1, even though the string is empty This logic may be part of "empty policy is a valid policy" or something else. As it is more dangerous to change the behavior at this point i assume your patch is the right solution for the problem.

Mimi, shall we change ima_parse_add_rule's behavior in the future or it's too much work?

cheers,
Petko

#5 lore raw
Quoted 21 lines · Petko Manolov
Quoted 6 lines · Sasha Levin
Quoted 5 lines · Petko Manolov
Quoted 4 lines

Thanks, Sasha. By the time ima_update_policy() is called

Quoted 3 lines

ima_release_policy() has already output the policy update status message. I guess an empty policy could be considered a valid policy. Could you add a msg indicating that the new policy was empty?

Quoted 6 lines
Quoted 4 lines

As far as I can say we can't get to ima_update_policy() with empty ima_temp_rules because ima_write_policy() will set valid_policy to 0 in case of an empty rule. I'll double check it tomorrow, but please you do that too.

This is based on an actual crash rather than code analysis.

I was able to reproduce the crash with: echo "" > /sys/kernel/security/ima/policy

It turns out ima_parse_add_rule() returns 1, even though the string is empty This logic may be part of "empty policy is a valid policy" or something else. As it is more dangerous to change the behavior at this point i assume your patch is the right solution for the problem.

Quoted 4 lines

Mimi, shall we change ima_parse_add_rule's behavior in the future or it's too much work?

ima_parse_add_rules() has no way of knowing if the policy as a whole is valid. I would define a new function in ima_policy.c to return the number of rules being added and call it at the beginning of ima_release_policy() before the status message. That way the number of rules added can be included in the status message.

For now, the function could just return have rules or no rules, instead of the number of rules.

Mimi

#6 lore raw
Quoted 28 lines · Mimi Zohar
Quoted 21 lines · Petko Manolov
Quoted 6 lines · Sasha Levin
Quoted 5 lines · Petko Manolov
Quoted 4 lines

Thanks, Sasha. By the time ima_update_policy() is called

Quoted 3 lines

ima_release_policy() has already output the policy update status message. I guess an empty policy could be considered a valid policy. Could you add a msg indicating that the new policy was empty?

Quoted 6 lines
Quoted 4 lines

As far as I can say we can't get to ima_update_policy() with empty ima_temp_rules because ima_write_policy() will set valid_policy to 0 in case of an empty rule. I'll double check it tomorrow, but please you do that too.

This is based on an actual crash rather than code analysis.

I was able to reproduce the crash with: echo "" > /sys/kernel/security/ima/policy

It turns out ima_parse_add_rule() returns 1, even though the string is empty This logic may be part of "empty policy is a valid policy" or something else. As it is more dangerous to change the behavior at this point i assume your patch is the right solution for the problem.

Quoted 4 lines

Mimi, shall we change ima_parse_add_rule's behavior in the future or it's too much work?

Quoted 8 lines

ima_parse_add_rules() has no way of knowing if the policy as a whole is valid. I would define a new function in ima_policy.c to return the number of rules being added and call it at the beginning of ima_release_policy() before the status message. That way the number of rules added can be included in the status message.

For now, the function could just return have rules or no rules, instead of the number of rules.

Sasha, could you make your fix a separate function (above ima_update_policy) and call it from ima_release_policy()?

Thanks!

Mimi