Skip to contentSkip to conversation

IMA: work on audit records produced by IMA

PATCH Superseded Stefan Berger 1 participant 5 messages May 31, 2018

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover IMA: work on audit records produced by IMA

This series of patches cleans up some usages of the audit subsystem's API by IMA. We also introduce a new record type that IMA creates while parsing policy rules.

Stefan

v1->v2:
- dropped several patches that extended existing messages with missing fields
- Using audit_log_task_info() for new record type in last patch
- rebased on security-next; new message type is now 1807

Stefan Berger (4):
ima: Call audit_log_string() rather than logging it untrusted
ima: Use audit_log_format() rather than audit_log_string()
ima: Do not audit if CONFIG_INTEGRITY_AUDIT is not set
ima: Differentiate auditing policy rules from "audit" actions

 include/uapi/linux/audit.h           |  1 +
 security/integrity/ima/Kconfig       |  1 +
 security/integrity/ima/ima_policy.c  | 17 +++++++++++++----
 security/integrity/integrity.h       | 15 +++++++++++++++
 security/integrity/integrity_audit.c |  6 +-----
 5 files changed, 31 insertions(+), 9 deletions(-)
Signature · 1 line
2.13.6
#1 lore raw

PATCH v2 1/4 ima: Call audit_log_string() rather than logging it untrusted

The parameters passed to this logging function are all provided by a privileged user and therefore we can call audit_log_string() rather than audit_log_untrustedstring().

---
 security/integrity/ima/ima_policy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/integrity/ima/ima_policy.c +1 -1
index 8bbc18eb07eb..1d00db19d167 100644
@@ -634,7 +634,7 @@ static void ima_log_string_op(struct audit_buffer *ab, char *key, char *value,
 		audit_log_format(ab, "%s<", key);
 	else
 		audit_log_format(ab, "%s=", key);
-	audit_log_untrustedstring(ab, value);
+	audit_log_string(ab, value);
 	audit_log_format(ab, " ");
 }
 static void ima_log_string(struct audit_buffer *ab, char *key, char *value)
Signature · 1 line
2.13.6
#2 lore raw

PATCH v2 2/4 ima: Use audit_log_format() rather than audit_log_string()

In reply to Stefan Berger

Remove the usage of audit_log_string() and replace it with audit_log_format().

---
 security/integrity/ima/ima_policy.c  | 3 +--
 security/integrity/integrity_audit.c | 6 +-----
 2 files changed, 2 insertions(+), 7 deletions(-)
security/integrity/ima/ima_policy.c +1 -2
index 1d00db19d167..3fcf0935468c 100644
@@ -634,8 +634,7 @@ static void ima_log_string_op(struct audit_buffer *ab, char *key, char *value,
 		audit_log_format(ab, "%s<", key);
 	else
 		audit_log_format(ab, "%s=", key);
-	audit_log_string(ab, value);
-	audit_log_format(ab, " ");
+	audit_log_format(ab, "%s ", value);
 }
 static void ima_log_string(struct audit_buffer *ab, char *key, char *value)
 {
security/integrity/integrity_audit.c +1 -5
index 90987d15b6fe..db30763d5525 100644
@@ -45,11 +45,7 @@ void integrity_audit_msg(int audit_msgno, struct inode *inode,
 			 from_kuid(&init_user_ns, audit_get_loginuid(current)),
 			 audit_get_sessionid(current));
 	audit_log_task_context(ab);
-	audit_log_format(ab, " op=");
-	audit_log_string(ab, op);
-	audit_log_format(ab, " cause=");
-	audit_log_string(ab, cause);
-	audit_log_format(ab, " comm=");
+	audit_log_format(ab, " op=%s cause=%s comm=", op, cause);
 	audit_log_untrustedstring(ab, get_task_comm(name, current));
 	if (fname) {
 		audit_log_format(ab, " name=");
Signature · 1 line
2.13.6
#3 lore raw

PATCH v2 3/4 ima: Do not audit if CONFIG_INTEGRITY_AUDIT is not set

In reply to Stefan Berger

If Integrity is not auditing, IMA shouldn't audit, either.

---
 security/integrity/ima/Kconfig      |  1 +
 security/integrity/ima/ima_policy.c |  6 +++++-
 security/integrity/integrity.h      | 15 +++++++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)
security/integrity/ima/Kconfig +1 -0
index 6a8f67714c83..94c2151331aa 100644
@@ -12,6 +12,7 @@ config IMA
 	select TCG_TIS if TCG_TPM && X86
 	select TCG_CRB if TCG_TPM && ACPI
 	select TCG_IBMVTPM if TCG_TPM && PPC_PSERIES
+	select INTEGRITY_AUDIT if AUDIT
 	help
 	  The Trusted Computing Group(TCG) runtime Integrity
 	  Measurement Architecture(IMA) maintains a list of hash
security/integrity/ima/ima_policy.c +5 -1
index 3fcf0935468c..bc99713dfe57 100644
@@ -628,6 +628,9 @@ static int ima_lsm_rule_init(struct ima_rule_entry *entry,
 static void ima_log_string_op(struct audit_buffer *ab, char *key, char *value,
 			      bool (*rule_operator)(kuid_t, kuid_t))
 {
+	if (!ab)
+		return;
+
 	if (rule_operator == &uid_gt)
 		audit_log_format(ab, "%s>", key);
 	else if (rule_operator == &uid_lt)
@@ -649,7 +652,8 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
 	bool uid_token;
 	int result = 0;
 
-	ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_INTEGRITY_RULE);
+	ab = integrity_audit_log_start(NULL, GFP_KERNEL,
+				       AUDIT_INTEGRITY_RULE);
 
 	entry->uid = INVALID_UID;
 	entry->fowner = INVALID_UID;
security/integrity/integrity.h +15 -0
index 0bb372eed62a..e60473b13a8d 100644
@@ -15,6 +15,7 @@
 #include <linux/integrity.h>
 #include <crypto/sha.h>
 #include <linux/key.h>
+#include <linux/audit.h>
 
 /* iint action cache flags */
 #define IMA_MEASURE		0x00000001
@@ -199,6 +200,13 @@ static inline void evm_load_x509(void)
 void integrity_audit_msg(int audit_msgno, struct inode *inode,
 			 const unsigned char *fname, const char *op,
 			 const char *cause, int result, int info);
+
+static inline struct audit_buffer *
+integrity_audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, int type)
+{
+	return audit_log_start(ctx, gfp_mask, type);
+}
+
 #else
 static inline void integrity_audit_msg(int audit_msgno, struct inode *inode,
 				       const unsigned char *fname,
@@ -206,4 +214,11 @@ static inline void integrity_audit_msg(int audit_msgno, struct inode *inode,
 				       int result, int info)
 {
 }
+
+static inline struct audit_buffer *
+integrity_audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, int type)
+{
+	return NULL;
+}
+
 #endif
Signature · 1 line
2.13.6
#4 lore raw

PATCH v2 4/4 ima: Differentiate auditing policy rules from "audit" actions

In reply to Stefan Berger

The AUDIT_INTEGRITY_RULE is used for auditing IMA policy rules and the IMA "audit" policy action. This patch defines AUDIT_INTEGRITY_POLICY_RULE to reflect the IMA policy rules.

Since we defined a new message type we can now also call audit_log_task_info() for task specific fields. This now produces the following record when parsing an IMA policy rule:

type=UNKNOWN[1807] msg=audit(1527722337.757:338): action=audit \
func=BPRM_CHECK mask=MAY_EXEC ppid=1613 pid=1657 auid=0 uid=0 \
gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=tty4 ses=4 \
comm="echo" exe="/usr/bin/echo" \
subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 res=1

---
 include/uapi/linux/audit.h          |  1 +
 security/integrity/ima/ima_policy.c | 12 +++++++++---
 2 files changed, 10 insertions(+), 3 deletions(-)
include/uapi/linux/audit.h +1 -0
index 65d9293f1fb8..cb358551376b 100644
@@ -148,6 +148,7 @@
 #define AUDIT_INTEGRITY_PCR	    1804 /* PCR invalidation msgs */
 #define AUDIT_INTEGRITY_RULE	    1805 /* policy rule */
 #define AUDIT_INTEGRITY_EVM_XATTR   1806 /* New EVM-covered xattr */
+#define AUDIT_INTEGRITY_POLICY_RULE 1807 /* IMA policy rules */
 
 #define AUDIT_KERNEL		2000	/* Asynchronous audit record. NOT A REQUEST. */
 
security/integrity/ima/ima_policy.c +9 -3
index bc99713dfe57..d56857223b73 100644
@@ -637,7 +637,7 @@ static void ima_log_string_op(struct audit_buffer *ab, char *key, char *value,
 		audit_log_format(ab, "%s<", key);
 	else
 		audit_log_format(ab, "%s=", key);
-	audit_log_format(ab, "%s ", value);
+	audit_log_format(ab, "%s", value);
 }
 static void ima_log_string(struct audit_buffer *ab, char *key, char *value)
 {
@@ -651,9 +651,10 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
 	char *p;
 	bool uid_token;
 	int result = 0;
+	const char *orig_rule = rule;
 
 	ab = integrity_audit_log_start(NULL, GFP_KERNEL,
-				       AUDIT_INTEGRITY_RULE);
+				       AUDIT_INTEGRITY_POLICY_RULE);
 
 	entry->uid = INVALID_UID;
 	entry->fowner = INVALID_UID;
@@ -669,6 +670,10 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
 			break;
 		if ((*p == '\0') || (*p == ' ') || (*p == '\t'))
 			continue;
+
+		if (p != orig_rule)
+			audit_log_format(ab, " ");
+
 		token = match_token(p, policy_tokens, args);
 		switch (token) {
 		case Opt_measure:
@@ -953,7 +958,8 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
 	else if (entry->action == APPRAISE)
 		temp_ima_appraise |= ima_appraise_flag(entry->func);
 
-	audit_log_format(ab, "res=%d", !result);
+	audit_log_task_info(ab, current);
+	audit_log_format(ab, " res=%d", !result);
 	audit_log_end(ab);
 	return result;
 }
Signature · 1 line
2.13.6