public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] IMA: policy can be updated zero times
@ 2015-12-22 13:51 Sasha Levin
  2015-12-22 19:56 ` Mimi Zohar
  0 siblings, 1 reply; 7+ messages in thread
From: Sasha Levin @ 2015-12-22 13:51 UTC (permalink / raw)
  To: zohar, dmitry.kasatkin, james.l.morris, serge
  Cc: linux-ima-devel, linux-security-module, linux-kernel, petkan,
	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.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
 security/integrity/ima/ima_policy.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
index ba5d2fc..9b958b8 100644
--- a/security/integrity/ima/ima_policy.c
+++ b/security/integrity/ima/ima_policy.c
@@ -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;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] IMA: policy can be updated zero times
  2015-12-22 13:51 [PATCH] IMA: policy can be updated zero times Sasha Levin
@ 2015-12-22 19:56 ` Mimi Zohar
  2015-12-22 21:40   ` Petko Manolov
  0 siblings, 1 reply; 7+ messages in thread
From: Mimi Zohar @ 2015-12-22 19:56 UTC (permalink / raw)
  To: Sasha Levin
  Cc: dmitry.kasatkin, james.l.morris, serge, linux-ima-devel,
	linux-security-module, linux-kernel, petkan

On Tue, 2015-12-22 at 08:51 -0500, Sasha Levin wrote:
> 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.
> 
> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
> ---
>  security/integrity/ima/ima_policy.c |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
> index ba5d2fc..9b958b8 100644
> --- a/security/integrity/ima/ima_policy.c
> +++ b/security/integrity/ima/ima_policy.c
> @@ -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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] IMA: policy can be updated zero times
  2015-12-22 19:56 ` Mimi Zohar
@ 2015-12-22 21:40   ` Petko Manolov
  2015-12-22 21:50     ` Sasha Levin
  0 siblings, 1 reply; 7+ messages in thread
From: Petko Manolov @ 2015-12-22 21:40 UTC (permalink / raw)
  To: Mimi Zohar, Sasha Levin
  Cc: dmitry.kasatkin, james.l.morris, serge, linux-ima-devel,
	linux-security-module, linux-kernel

On December 22, 2015 9:56:28 PM GMT+02:00, Mimi Zohar <zohar@linux.vnet.ibm.com> wrote:
>On Tue, 2015-12-22 at 08:51 -0500, Sasha Levin wrote:
>> 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.
>> 
>> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
>> ---
>>  security/integrity/ima/ima_policy.c |    3 +++
>>  1 file changed, 3 insertions(+)
>> 
>> diff --git a/security/integrity/ima/ima_policy.c
>b/security/integrity/ima/ima_policy.c
>> index ba5d2fc..9b958b8 100644
>> --- a/security/integrity/ima/ima_policy.c
>> +++ b/security/integrity/ima/ima_policy.c
>> @@ -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?


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





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] IMA: policy can be updated zero times
  2015-12-22 21:40   ` Petko Manolov
@ 2015-12-22 21:50     ` Sasha Levin
  2015-12-23 11:47       ` Petko Manolov
  0 siblings, 1 reply; 7+ messages in thread
From: Sasha Levin @ 2015-12-22 21:50 UTC (permalink / raw)
  To: Petko Manolov, Mimi Zohar
  Cc: dmitry.kasatkin, james.l.morris, serge, linux-ima-devel,
	linux-security-module, linux-kernel

On 12/22/2015 04:40 PM, Petko Manolov wrote:
>> 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.

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


Thanks,
Sasha

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] IMA: policy can be updated zero times
  2015-12-22 21:50     ` Sasha Levin
@ 2015-12-23 11:47       ` Petko Manolov
  2015-12-23 12:24         ` Mimi Zohar
  0 siblings, 1 reply; 7+ messages in thread
From: Petko Manolov @ 2015-12-23 11:47 UTC (permalink / raw)
  To: Sasha Levin
  Cc: Mimi Zohar, dmitry.kasatkin, james.l.morris, serge,
	linux-ima-devel, linux-security-module, linux-kernel

On 15-12-22 16:50:01, Sasha Levin wrote:
> On 12/22/2015 04:40 PM, Petko Manolov wrote:
> >> 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.
> 
> 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.

Acked-by: Petko Manolov <petkan@mip-labs.com>

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


cheers,
Petko

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] IMA: policy can be updated zero times
  2015-12-23 11:47       ` Petko Manolov
@ 2015-12-23 12:24         ` Mimi Zohar
  2015-12-23 12:47           ` [Linux-ima-devel] " Mimi Zohar
  0 siblings, 1 reply; 7+ messages in thread
From: Mimi Zohar @ 2015-12-23 12:24 UTC (permalink / raw)
  To: Petko Manolov
  Cc: Sasha Levin, dmitry.kasatkin, james.l.morris, serge,
	linux-ima-devel, linux-security-module, linux-kernel

On Wed, 2015-12-23 at 13:47 +0200, Petko Manolov wrote:

> On 15-12-22 16:50:01, Sasha Levin wrote:
> > On 12/22/2015 04:40 PM, Petko Manolov wrote:
> > >> 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.
> > 
> > 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.
> 
> Acked-by: Petko Manolov <petkan@mip-labs.com>
> 
> 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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Linux-ima-devel] [PATCH] IMA: policy can be updated zero times
  2015-12-23 12:24         ` Mimi Zohar
@ 2015-12-23 12:47           ` Mimi Zohar
  0 siblings, 0 replies; 7+ messages in thread
From: Mimi Zohar @ 2015-12-23 12:47 UTC (permalink / raw)
  To: Petko Manolov, Sasha Levin
  Cc: linux-kernel, linux-security-module, james.l.morris,
	linux-ima-devel

On Wed, 2015-12-23 at 07:24 -0500, Mimi Zohar wrote:
> On Wed, 2015-12-23 at 13:47 +0200, Petko Manolov wrote:
> 
> > On 15-12-22 16:50:01, Sasha Levin wrote:
> > > On 12/22/2015 04:40 PM, Petko Manolov wrote:
> > > >> 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.
> > > 
> > > 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.
> > 
> > Acked-by: Petko Manolov <petkan@mip-labs.com>
> > 
> > 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.

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

Thanks!

Mimi


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-12-23 12:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-22 13:51 [PATCH] IMA: policy can be updated zero times Sasha Levin
2015-12-22 19:56 ` Mimi Zohar
2015-12-22 21:40   ` Petko Manolov
2015-12-22 21:50     ` Sasha Levin
2015-12-23 11:47       ` Petko Manolov
2015-12-23 12:24         ` Mimi Zohar
2015-12-23 12:47           ` [Linux-ima-devel] " Mimi Zohar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox