linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Kasatkin <d.kasatkin@samsung.com>
To: zohar@linux.vnet.ibm.com, dhowells@redhat.com, jmorris@namei.org
Cc: roberto.sassu@polito.it, linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Dmitry Kasatkin <d.kasatkin@samsung.com>
Subject: [PATCH 14/20] ima: check if policy was set at open
Date: Wed, 23 Apr 2014 16:30:32 +0300	[thread overview]
Message-ID: <512bd4902270ae50b7cfaa1467e12817130290b4.1398259638.git.d.kasatkin@samsung.com> (raw)
In-Reply-To: <cover.1398259638.git.d.kasatkin@samsung.com>
In-Reply-To: <cover.1398259638.git.d.kasatkin@samsung.com>

IMA default behavior is to forbid more than one policy update.
It easier to check at open phase if policy was already set,
so it would not be necessary to perform useless policy parsing
and removing of sysfs entry.

Signed-off-by: Dmitry Kasatkin <d.kasatkin@samsung.com>
---
 security/integrity/ima/ima.h        |  1 +
 security/integrity/ima/ima_fs.c     |  7 +++++--
 security/integrity/ima/ima_policy.c | 16 +++++++++-------
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
index a5d5ccb..3b90b60 100644
--- a/security/integrity/ima/ima.h
+++ b/security/integrity/ima/ima.h
@@ -166,6 +166,7 @@ int ima_match_policy(struct dentry *dentry, enum ima_hooks func, int mask,
 		     int flags);
 void ima_init_policy(void);
 void ima_update_policy(void);
+bool ima_default_policy(void);
 ssize_t ima_parse_add_rule(char *);
 void ima_delete_rules(void);
 
diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
index 71f0d8f..34ae5f2 100644
--- a/security/integrity/ima/ima_fs.c
+++ b/security/integrity/ima/ima_fs.c
@@ -304,6 +304,11 @@ static int ima_open_policy(struct inode *inode, struct file *filp)
 		return -EACCES;
 	if (test_and_set_bit(IMA_FS_BUSY, &ima_fs_flags))
 		return -EBUSY;
+	if (!ima_default_policy()) {
+		/* policy was already set*/
+		clear_bit(IMA_FS_BUSY, &ima_fs_flags);
+		return -EACCES;
+	}
 	return 0;
 }
 
@@ -321,8 +326,6 @@ static int ima_release_policy(struct inode *inode, struct file *file)
 		valid_policy = 1;
 	} else {
 		ima_update_policy();
-		securityfs_remove(ima_policy);
-		ima_policy = NULL;
 	}
 	clear_bit(IMA_FS_BUSY, &ima_fs_flags);
 	return 0;
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
index 9b8121b..b24e7d1 100644
--- a/security/integrity/ima/ima_policy.c
+++ b/security/integrity/ima/ima_policy.c
@@ -345,6 +345,11 @@ void __init ima_init_policy(void)
 	ima_rules = &ima_default_rules;
 }
 
+bool ima_default_policy(void)
+{
+	return ima_rules == &ima_default_rules;
+}
+
 /**
  * ima_update_policy - update default_rules with new measure rules
  *
@@ -355,15 +360,12 @@ void __init ima_init_policy(void)
 void ima_update_policy(void)
 {
 	static const char op[] = "policy_update";
-	const char *cause = "already exists";
-	int result = 1;
+	const char *cause = "complete";
+	int result = 0;
 	int audit_info = 0;
 
-	if (ima_rules == &ima_default_rules) {
-		ima_rules = &ima_policy_rules;
-		cause = "complete";
-		result = 0;
-	}
+	ima_rules = &ima_policy_rules;
+
 	integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL,
 			    NULL, op, cause, result, audit_info);
 }
-- 
1.8.3.2


  parent reply	other threads:[~2014-04-23 13:43 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-23 13:30 [PATCH 00/20] in-kernel IMA/EVM initialization Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 01/20] KEYS: verify a certificate is signed by a 'trusted' key Dmitry Kasatkin
2014-04-24 16:53   ` Mimi Zohar
2014-04-24 20:07     ` Dmitry Kasatkin
2014-04-24 21:03       ` Mimi Zohar
2014-04-23 13:30 ` [PATCH 02/20] integrity: initialize EVM before IMA Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 03/20] ima: move asymmetric keys config option Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 04/20] integrity: move integrity subsystem options to a separate menu Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 05/20] integrity: provide builtin 'trusted' keyrings Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 06/20] ima: create '_ima' as a builtin 'trusted' keyring Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 07/20] integrity: provide x509 certificate loading from the kernel Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 08/20] ima: load x509 certificate " Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 09/20] evm: create '_evm' as a builtin 'trusted' keyring Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 10/20] evm: load x509 certificate from the kernel Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 11/20] ima: added kernel parameter for disabling IMA Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 12/20] ima: provide buffer hash calculation function Dmitry Kasatkin
2014-04-24 21:04   ` Mimi Zohar
2014-04-25 14:52     ` Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 13/20] ima: replace opencount with bitop Dmitry Kasatkin
2014-04-23 13:30 ` Dmitry Kasatkin [this message]
2014-04-23 13:30 ` [PATCH 15/20] ima: path based policy loading interface Dmitry Kasatkin
2014-04-24 21:03   ` Mimi Zohar
2014-04-25 15:18     ` Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 16/20] ima: load policy from the kernel Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 17/20] ima: make IMA policy replaceable at runtime Dmitry Kasatkin
2014-05-14 23:45   ` Mimi Zohar
2014-05-15  6:08     ` Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 18/20] evm: added kernel parameter for disabling EVM Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 19/20] evm: try enable EVM from the kernel Dmitry Kasatkin
2014-04-23 13:30 ` [PATCH 20/20] evm: read EVM key " Dmitry Kasatkin
2014-04-24 18:44 ` [PATCH 00/20] in-kernel IMA/EVM initialization Mimi Zohar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=512bd4902270ae50b7cfaa1467e12817130290b4.1398259638.git.d.kasatkin@samsung.com \
    --to=d.kasatkin@samsung.com \
    --cc=dhowells@redhat.com \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=roberto.sassu@polito.it \
    --cc=zohar@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).