Skip to contentSkip to conversation

IMA: Check for ima-buf template is not required for keys tests

PATCH In review Lakshmi Ramasubramanian 2 participants 5 messages Feb 22, 2021 – Feb 23, 2021 Keys-trusted

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IMA: Check for ima-buf template is not required for keys tests

ima-buf is the default IMA template used for all buffer measurements. Therefore, IMA policy rule for measuring keys need not specify an IMA template.

Update keys tests to not check for ima template in the policy rule.

---
This patch is based
in https://github.com/pevik/ltp/commits/ima/selinux.v2.draft
in branch ima/selinux.v2.draft.

 testcases/kernel/security/integrity/ima/tests/ima_keys.sh | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
testcases/kernel/security/integrity/ima/tests/ima_keys.sh +2 -3
index c9eef4b68..a3a7afbf7 100755
@@ -15,8 +15,7 @@ TST_CLEANUP=cleanup
 . ima_setup.sh
 
 FUNC_KEYCHECK='func=KEY_CHECK'
-TEMPLATE_BUF='template=ima-buf'
-REQUIRED_POLICY="^measure.*($FUNC_KEYCHECK.*$TEMPLATE_BUF|$TEMPLATE_BUF.*$FUNC_KEYCHECK)"
+REQUIRED_POLICY="^measure.*($FUNC_KEYCHECK)"
 
 setup()
 {
@@ -33,7 +32,7 @@ check_keys_policy()
 	local pattern="$1"
 
 	if ! grep -E "$pattern" $TST_TMPDIR/policy.txt; then
-		tst_res TCONF "IMA policy must specify $pattern, $FUNC_KEYCHECK, $TEMPLATE_BUF"
+		tst_res TCONF "IMA policy must specify $pattern, $FUNC_KEYCHECK"
 		return 1
 	fi
 	return 0
Signature · 1 line
2.30.0
#1 lore raw

Hi Lakmasi,

Quoted 3 lines

ima-buf is the default IMA template used for all buffer measurements. Therefore, IMA policy rule for measuring keys need not specify an IMA template.

Good catch. But was it alway?
IMHO ima-buf as default was added in dea87d0889dd ("ima: select ima-buf template for buffer measurement") in v5.11-rc1. But test1() tests 450d0fd51564 ("IMA: Call workqueue functions to measure queued keys") from v5.6-rc1.
Is it safe to ignore it?
BTW template=ima-buf requirement was added in commit b0418c93f ("IMA/ima_keys.sh: Require template=ima-buf, fix grep pattern")

Also, shouldn't we check that there is none of the other templates (e.g. template=ima-ng, ...)?

Quoted 16 lines

Update keys tests to not check for ima template in the policy rule.

---
This patch is based
in https://github.com/pevik/ltp/commits/ima/selinux.v2.draft
in branch ima/selinux.v2.draft.

 testcases/kernel/security/integrity/ima/tests/ima_keys.sh | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
testcases/kernel/security/integrity/ima/tests/ima_keys.sh +0 -0
index c9eef4b68..a3a7afbf7 100755

testcases/kernel/security/integrity/ima/tests/ima_keys.sh TST_CLEANUP=cleanup · line 18

Quoted 6 lines
testcases/kernel/security/integrity/ima/tests/ima_keys.sh +1 -2
@@ -15,8 +15,7 @@ TST_CLEANUP=cleanup
 . ima_setup.sh
 
 FUNC_KEYCHECK='func=KEY_CHECK'
-TEMPLATE_BUF='template=ima-buf'
-REQUIRED_POLICY="^measure.*($FUNC_KEYCHECK.*$TEMPLATE_BUF|$TEMPLATE_BUF.*$FUNC_KEYCHECK)"
+REQUIRED_POLICY="^measure.*($FUNC_KEYCHECK)"

nit: remove brackets:
REQUIRED_POLICY="^measure.*$FUNC_KEYCHECK"

There is testcases/kernel/security/integrity/ima/datafiles/ima_keys/keycheck.policy file, which should be a helper to load proper policy and needs to be updated as well:

-measure func=KEY_CHECK keyrings=.ima|.evm|.builtin_trusted_keys|.blacklist|key_import_test template=ima-buf
+measure func=KEY_CHECK keyrings=.ima|.evm|.builtin_trusted_keys|.blacklist|key_import_test

I was also thinking to move keyrings to REQUIRED_POLICY, e.g.:

KEYRINGS="keyrings=\.[a-z]+" REQUIRED_POLICY="^measure.*($FUNC_KEYCHECK.*$KEYRINGS|$KEYRINGS.*$FUNC_KEYCHECK)"

Kind regards,
Petr

Quoted 11 lines
testcases/kernel/security/integrity/ima/tests/ima_keys.sh +1 -1
 setup()
 {
@@ -33,7 +32,7 @@ check_keys_policy()
 	local pattern="$1"
 
 	if ! grep -E "$pattern" $TST_TMPDIR/policy.txt; then
-		tst_res TCONF "IMA policy must specify $pattern, $FUNC_KEYCHECK, $TEMPLATE_BUF"
+		tst_res TCONF "IMA policy must specify $pattern, $FUNC_KEYCHECK"
 		return 1
 	fi
 	return 0
#2 lore raw

On 2/23/21 1:24 AM, Petr Vorel wrote:

Hi Petr,

Quoted 7 lines
Quoted 4 lines

ima-buf is the default IMA template used for all buffer measurements. Therefore, IMA policy rule for measuring keys need not specify an IMA template.

Good catch. But was it alway?

IMHO ima-buf as default was added in dea87d0889dd ("ima: select ima-buf template for buffer measurement") in v5.11-rc1.

For key measurements ima-buf template was required in the policy rule, but with the above commit (dea87d0889dd) it was changed to ima-buf. So we no longer need to specify the template in the policy.

Quoted 2 lines

But test1() tests 450d0fd51564 ("IMA: Call workqueue functions to measure queued keys") from v5.6-rc1. Is it safe to ignore it?

Even when the key is queued for measurement, ima-buf template will be used when the key is dequeued. Not sure if that answers your question.

Quoted 3 lines

BTW template=ima-buf requirement was added in commit b0418c93f ("IMA/ima_keys.sh: Require template=ima-buf, fix grep pattern")

Also, shouldn't we check that there is none of the other templates (e.g. template=ima-ng, ...)?

This is a good point - yes: we should check if no other template other than ima-buf is specified in the policy rule for measuring keys.

Quoted 19 lines
Quoted 18 lines

Update keys tests to not check for ima template in the policy rule.

---
This patch is based
in https://github.com/pevik/ltp/commits/ima/selinux.v2.draft
in branch ima/selinux.v2.draft.

  testcases/kernel/security/integrity/ima/tests/ima_keys.sh | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
testcases/kernel/security/integrity/ima/tests/ima_keys.sh +0 -0
index c9eef4b68..a3a7afbf7 100755
@@ -15,8 +15,7 @@ TST_CLEANUP=cleanup
  . ima_setup.sh
Quoted 6 lines

testcases/kernel/security/integrity/ima/tests/ima_keys.sh TST_CLEANUP=cleanup · line 18

Quoted 4 lines
testcases/kernel/security/integrity/ima/tests/ima_keys.sh +1 -2
  FUNC_KEYCHECK='func=KEY_CHECK'
-TEMPLATE_BUF='template=ima-buf'
-REQUIRED_POLICY="^measure.*($FUNC_KEYCHECK.*$TEMPLATE_BUF|$TEMPLATE_BUF.*$FUNC_KEYCHECK)"
+REQUIRED_POLICY="^measure.*($FUNC_KEYCHECK)"

nit: remove brackets:
REQUIRED_POLICY="^measure.*$FUNC_KEYCHECK"

Sure - will remove that.

Quoted 11 lines

There is testcases/kernel/security/integrity/ima/datafiles/ima_keys/keycheck.policy file, which should be a helper to load proper policy and needs to be updated as well:

(quoted diff) +1 -1
-measure func=KEY_CHECK keyrings=.ima|.evm|.builtin_trusted_keys|.blacklist|key_import_test template=ima-buf
+measure func=KEY_CHECK keyrings=.ima|.evm|.builtin_trusted_keys|.blacklist|key_import_test

I was also thinking to move keyrings to REQUIRED_POLICY, e.g.:

KEYRINGS="keyrings=\.[a-z]+" REQUIRED_POLICY="^measure.*($FUNC_KEYCHECK.*$KEYRINGS|$KEYRINGS.*$FUNC_KEYCHECK)"

"keyrings=" is optional in the policy. If keyrings is specified it should be checked.

thanks,
-lakshmi

Quoted 12 lines
Quoted 12 lines
testcases/kernel/security/integrity/ima/tests/ima_keys.sh +1 -1
  setup()
  {
@@ -33,7 +32,7 @@ check_keys_policy()
  	local pattern="$1"
 
  	if ! grep -E "$pattern" $TST_TMPDIR/policy.txt; then
-		tst_res TCONF "IMA policy must specify $pattern, $FUNC_KEYCHECK, $TEMPLATE_BUF"
+		tst_res TCONF "IMA policy must specify $pattern, $FUNC_KEYCHECK"
  		return 1
  	fi
  	return 0
#3 lore raw

Hi Lakshmi,

Quoted 11 lines · Petr Vorel

Hi Petr,

Quoted 6 lines
Quoted 3 lines

ima-buf is the default IMA template used for all buffer measurements. Therefore, IMA policy rule for measuring keys need not specify an IMA template.

Good catch. But was it alway?

IMHO ima-buf as default was added in dea87d0889dd ("ima: select ima-buf template for buffer measurement") in v5.11-rc1.

Quoted 8 lines

For key measurements ima-buf template was required in the policy rule, but with the above commit (dea87d0889dd) it was changed to ima-buf. So we no longer need to specify the template in the policy.

Quoted 2 lines

But test1() tests 450d0fd51564 ("IMA: Call workqueue functions to measure queued keys") from v5.6-rc1. Is it safe to ignore it?

Even when the key is queued for measurement, ima-buf template will be used when the key is dequeued. Not sure if that answers your question.

IMHO template=ima-buf is required from v5.6-rc1 to v5.10, right? But maybe it's just enough to check that no other template is used as we discuss below.

Quoted 5 lines
Quoted 3 lines

BTW template=ima-buf requirement was added in commit b0418c93f ("IMA/ima_keys.sh: Require template=ima-buf, fix grep pattern")

Also, shouldn't we check that there is none of the other templates (e.g. template=ima-ng, ...)?

This is a good point - yes: we should check if no other template other than ima-buf is specified in the policy rule for measuring keys.

It'd be great if you include it in v2.

...

Quoted 7 lines
Quoted 6 lines

testcases/kernel/security/integrity/ima/tests/ima_keys.sh TST_CLEANUP=cleanup · line 18

Quoted 4 lines

FUNC_KEYCHECK='func=KEY_CHECK'

testcases/kernel/security/integrity/ima/tests/ima_keys.sh +1 -2
-TEMPLATE_BUF='template=ima-buf'
-REQUIRED_POLICY="^measure.*($FUNC_KEYCHECK.*$TEMPLATE_BUF|$TEMPLATE_BUF.*$FUNC_KEYCHECK)"
+REQUIRED_POLICY="^measure.*($FUNC_KEYCHECK)"

nit: remove brackets:
REQUIRED_POLICY="^measure.*$FUNC_KEYCHECK"

Sure - will remove that.

Thanks!

Quoted 6 lines
Quoted 5 lines

There is testcases/kernel/security/integrity/ima/datafiles/ima_keys/keycheck.policy file, which should be a helper to load proper policy and needs to be updated as well:

(quoted diff) +1 -1
-measure func=KEY_CHECK keyrings=.ima|.evm|.builtin_trusted_keys|.blacklist|key_import_test template=ima-buf
+measure func=KEY_CHECK keyrings=.ima|.evm|.builtin_trusted_keys|.blacklist|key_import_test
Quoted 6 lines
Quoted 4 lines

I was also thinking to move keyrings to REQUIRED_POLICY, e.g.:

KEYRINGS="keyrings=\.[a-z]+" REQUIRED_POLICY="^measure.*($FUNC_KEYCHECK.*$KEYRINGS|$KEYRINGS.*$FUNC_KEYCHECK)"

"keyrings=" is optional in the policy. If keyrings is specified it should be checked.

OK, just optional.

Kind regards,
Petr

Quoted 2 lines

thanks,
-lakshmi

#4 lore raw
Quoted 10 lines · Petr Vorel
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

ima-buf is the default IMA template used for all buffer measurements. Therefore, IMA policy rule for measuring keys need not specify an IMA template.

Good catch. But was it alway?

IMHO ima-buf as default was added in dea87d0889dd ("ima: select ima-buf template for buffer measurement") in v5.11-rc1.

For key measurements ima-buf template was required in the policy rule, but with the above commit (dea87d0889dd) it was changed to ima-buf. So we no longer need to specify the template in the policy.

Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

But test1() tests 450d0fd51564 ("IMA: Call workqueue functions to measure queued keys") from v5.6-rc1. Is it safe to ignore it?

Even when the key is queued for measurement, ima-buf template will be used when the key is dequeued. Not sure if that answers your question.

IMHO template=ima-buf is required from v5.6-rc1 to v5.10, right?

That is correct Petr.

Quoted 2 lines

But maybe it's just enough to check that no other template is used as we discuss below.

I agree.

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

BTW template=ima-buf requirement was added in commit b0418c93f ("IMA/ima_keys.sh: Require template=ima-buf, fix grep pattern")

Also, shouldn't we check that there is none of the other templates (e.g. template=ima-ng, ...)?

This is a good point - yes: we should check if no other template other than ima-buf is specified in the policy rule for measuring keys.

It'd be great if you include it in v2.

Will do.

Quoted 17 lines

...

Quoted 7 lines
Quoted 6 lines

testcases/kernel/security/integrity/ima/tests/ima_keys.sh TST_CLEANUP=cleanup · line 18

Quoted 4 lines

FUNC_KEYCHECK='func=KEY_CHECK'

testcases/kernel/security/integrity/ima/tests/ima_keys.sh +1 -2
-TEMPLATE_BUF='template=ima-buf'
-REQUIRED_POLICY="^measure.*($FUNC_KEYCHECK.*$TEMPLATE_BUF|$TEMPLATE_BUF.*$FUNC_KEYCHECK)"
+REQUIRED_POLICY="^measure.*($FUNC_KEYCHECK)"

nit: remove brackets:
REQUIRED_POLICY="^measure.*$FUNC_KEYCHECK"

Sure - will remove that.

Thanks!

Quoted 5 lines
Quoted 5 lines

There is testcases/kernel/security/integrity/ima/datafiles/ima_keys/keycheck.policy file, which should be a helper to load proper policy and needs to be updated as well:

(quoted diff) +1 -1
-measure func=KEY_CHECK keyrings=.ima|.evm|.builtin_trusted_keys|.blacklist|key_import_test template=ima-buf
+measure func=KEY_CHECK keyrings=.ima|.evm|.builtin_trusted_keys|.blacklist|key_import_test
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

I was also thinking to move keyrings to REQUIRED_POLICY, e.g.:

KEYRINGS="keyrings=\.[a-z]+" REQUIRED_POLICY="^measure.*($FUNC_KEYCHECK.*$KEYRINGS|$KEYRINGS.*$FUNC_KEYCHECK)"

"keyrings=" is optional in the policy. If keyrings is specified it should be checked.

OK, just optional.

I'll see how to validate an optional field and update the test.

thanks,
-lakshmi