Skip to contentSkip to conversation

integrity: Return error codes in audit messages

PATCH Superseded Frederick Lawler 2 participants 9 messages Jul 27 – Sep 15

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover integrity: Return error codes in audit messages

Commit 2f845882ecd2 ("integrity: Add errno field in audit message") introduced an audit log function that can take an error code. It is wrapped by integrity_audit_msg() that implicitly sets the error code argument to zero. The problem is that there are uses of integrity_audit_msg() such as ima_collect_measurement() that hide the failure cause for the message.

This series aims to convert integrity_audit_msg() call sites to integrity_audit_message(), and then expose error codes based on the following criteria:

1. The log depends on a result from earlier callee, and/or
2. The caller function itself returns with that result

ima_release_policy() is the only caller I thought made sense to keep as is. The message doesn't correlate with a return code, nor does it depend on a result from an earlier callee in the function.

---
This is probably a bit more than what was asked from v1, but as I was making changes and looking at other call sites, I didn't think it made sense to keep integrity_audit_msg() around anymore.

Changes in v2:
- Changes from v1 are now reflected in patch 3.
- Replace all instances of integrity_audit_msg().
- Convert to patch series.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Frederick Lawler (3):
integrity: Replace all uses of integrity_audit_msg() with integrity_audit_message()
integrity: Remove integrity_audit_msg()
integrity: Report error code in integrity_audit_message() call sites

 security/integrity/evm/evm_main.c         | 38 ++++++++++++++++++-------------
 security/integrity/ima/ima_api.c          | 20 ++++++++--------
 security/integrity/ima/ima_appraise.c     | 12 +++++-----
 security/integrity/ima/ima_fs.c           | 11 +++++----
 security/integrity/ima/ima_init.c         |  4 ++--
 security/integrity/ima/ima_main.c         | 16 +++++++------
 security/integrity/ima/ima_policy.c       | 25 ++++++++++----------
 security/integrity/ima/ima_queue.c        |  4 ++--
 security/integrity/ima/ima_template_lib.c |  6 ++---
 security/integrity/integrity.h            | 11 ---------
 security/integrity/integrity_audit.c      |  8 -------
 11 files changed, 73 insertions(+), 82 deletions(-)

---
base-commit: 1da739feb31b4fecae465ebf87ba44a97e44101b
change-id: 20260716-report-hash-error-5203d6fe6e4e

Best regards,

Signature · 1 line
Frederick Lawler <[email protected]>
#1 lore raw

PATCH v2 1/3 integrity: Replace all uses of integrity_audit_msg() with integrity_audit_message()

integrity_audit_msg() wraps integrity_audit_message() such that error codes are hidden by passing an additional parameter to integrity_audit_message(). Since this is a wrapper, we can replace this function with integrity_audit_message() introduced in commit 2f845882ecd2 ("integrity: Add errno field in audit message")

No functional change intended.

---
 security/integrity/evm/evm_main.c         | 38 ++++++++++++++++++-------------
 security/integrity/ima/ima_api.c          | 20 ++++++++--------
 security/integrity/ima/ima_appraise.c     | 12 +++++-----
 security/integrity/ima/ima_fs.c           | 11 +++++----
 security/integrity/ima/ima_init.c         |  4 ++--
 security/integrity/ima/ima_main.c         | 16 +++++++------
 security/integrity/ima/ima_policy.c       | 25 ++++++++++----------
 security/integrity/ima/ima_queue.c        |  4 ++--
 security/integrity/ima/ima_template_lib.c |  6 ++---
 9 files changed, 73 insertions(+), 63 deletions(-)
security/integrity/evm/evm_main.c +22 -16
index b59e3f121b8a89edb14d811351ec393a69de8ff7..a32c98089b055fcf84f1a33dd016a51f57693d36 100644
@@ -559,11 +559,11 @@ static int evm_protect_xattr(struct mnt_idmap *idmap,
 		    || dentry->d_sb->s_magic == SYSFS_MAGIC)
 			return 0;
 
-		integrity_audit_msg(AUDIT_INTEGRITY_METADATA,
-				    dentry->d_inode, dentry->d_name.name,
-				    "update_metadata",
-				    integrity_status_msg[evm_status],
-				    -EPERM, 0);
+		integrity_audit_message(AUDIT_INTEGRITY_METADATA,
+					dentry->d_inode, dentry->d_name.name,
+					"update_metadata",
+					integrity_status_msg[evm_status],
+					-EPERM, 0, 0);
 	}
 out:
 	/* Exception if the HMAC is not going to be calculated. */
@@ -585,10 +585,12 @@ static int evm_protect_xattr(struct mnt_idmap *idmap,
 
 	if (evm_status != INTEGRITY_PASS &&
 	    evm_status != INTEGRITY_PASS_IMMUTABLE)
-		integrity_audit_msg(AUDIT_INTEGRITY_METADATA, d_backing_inode(dentry),
-				    dentry->d_name.name, "appraise_metadata",
-				    integrity_status_msg[evm_status],
-				    -EPERM, 0);
+		integrity_audit_message(AUDIT_INTEGRITY_METADATA,
+					d_backing_inode(dentry),
+					dentry->d_name.name,
+					"appraise_metadata",
+					integrity_status_msg[evm_status],
+					-EPERM, 0, 0);
 	return evm_status == INTEGRITY_PASS ? 0 : -EPERM;
 }
 
@@ -726,10 +728,12 @@ static int evm_inode_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 		return 0;
 
 	if (evm_status != INTEGRITY_PASS_IMMUTABLE)
-		integrity_audit_msg(AUDIT_INTEGRITY_METADATA, d_backing_inode(dentry),
-				    dentry->d_name.name, "appraise_metadata",
-				    integrity_status_msg[evm_status],
-				    -EPERM, 0);
+		integrity_audit_message(AUDIT_INTEGRITY_METADATA,
+					d_backing_inode(dentry),
+					dentry->d_name.name,
+					"appraise_metadata",
+					integrity_status_msg[evm_status],
+					-EPERM, 0, 0);
 	return -EPERM;
 }
 
@@ -990,9 +994,11 @@ static int evm_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 	    !evm_attr_change(idmap, dentry, attr))
 		return 0;
 
-	integrity_audit_msg(AUDIT_INTEGRITY_METADATA, d_backing_inode(dentry),
-			    dentry->d_name.name, "appraise_metadata",
-			    integrity_status_msg[evm_status], -EPERM, 0);
+	integrity_audit_message(AUDIT_INTEGRITY_METADATA,
+				d_backing_inode(dentry), dentry->d_name.name,
+				"appraise_metadata",
+				integrity_status_msg[evm_status], -EPERM, 0,
+				0);
 	return -EPERM;
 }
 
security/integrity/ima/ima_api.c +10 -10
index 122d127e108dcca8ddae6575c908144859783fb6..8c37dd4c9bb805213fb62e597a70189eca12b897 100644
@@ -114,9 +114,9 @@ int ima_store_template(struct ima_template_entry *entry,
 		result = ima_calc_field_array_hash(&entry->template_data[0],
 						   entry);
 		if (result < 0) {
-			integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode,
-					    template_name, op,
-					    audit_cause, result, 0);
+			integrity_audit_message(AUDIT_INTEGRITY_PCR, inode,
+						template_name, op, audit_cause,
+						result, 0, 0);
 			return result;
 		}
 	}
@@ -158,8 +158,8 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
 	if (result < 0)
 		ima_free_template_entry(entry);
 err_out:
-	integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode, filename,
-			    op, cause, result, 0);
+	integrity_audit_message(AUDIT_INTEGRITY_PCR, inode, filename, op,
+				cause, result, 0, 0);
 }
 
 /**
@@ -328,9 +328,9 @@ int ima_collect_measurement(struct ima_iint_cache *iint, struct file *file,
 
 		take_dentry_name_snapshot(&filename, file->f_path.dentry);
 
-		integrity_audit_msg(AUDIT_INTEGRITY_DATA, inode,
-				    filename.name.name, "collect_data",
-				    audit_cause, result, 0);
+		integrity_audit_message(AUDIT_INTEGRITY_DATA, inode,
+					filename.name.name, "collect_data",
+					audit_cause, result, 0, 0);
 
 		release_dentry_name_snapshot(&filename);
 	}
@@ -382,8 +382,8 @@ void ima_store_measurement(struct ima_iint_cache *iint, struct file *file,
 
 	result = ima_alloc_init_template(&event_data, &entry, template_desc);
 	if (result < 0) {
-		integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode, filename,
-				    op, audit_cause, result, 0);
+		integrity_audit_message(AUDIT_INTEGRITY_PCR, inode, filename,
+					op, audit_cause, result, 0, 0);
 		return;
 	}
 
security/integrity/ima/ima_appraise.c +6 -6
index 18d0d9154317b8efe9a806760f7e8eca75cca692..cc88e3add5b7028d4901e284ef920b324645e719 100644
@@ -558,8 +558,8 @@ int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint,
 	     (iint->flags & IMA_FAIL_UNVERIFIABLE_SIGS))) {
 		status = INTEGRITY_FAIL;
 		cause = "unverifiable-signature";
-		integrity_audit_msg(audit_msgno, inode, filename,
-				    op, cause, rc, 0);
+		integrity_audit_message(audit_msgno, inode, filename,
+					op, cause, rc, 0, 0);
 	} else if (status != INTEGRITY_PASS) {
 		/* Fix mode, but don't replace file signatures. */
 		if ((ima_appraise & IMA_APPRAISE_FIX) && !try_modsig &&
@@ -583,8 +583,8 @@ int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint,
 			status = INTEGRITY_PASS;
 		}
 
-		integrity_audit_msg(audit_msgno, inode, filename,
-				    op, cause, rc, 0);
+		integrity_audit_message(audit_msgno, inode, filename,
+					op, cause, rc, 0, 0);
 	} else {
 		ima_cache_flags(iint, func);
 	}
@@ -744,8 +744,8 @@ static int validate_hash_algo(struct dentry *dentry,
 
 	path = dentry_path(dentry, pathbuf, PATH_MAX);
 
-	integrity_audit_msg(AUDIT_INTEGRITY_DATA, d_inode(dentry), path,
-			    "set_data", errmsg, -EACCES, 0);
+	integrity_audit_message(AUDIT_INTEGRITY_DATA, d_inode(dentry), path,
+				"set_data", errmsg, -EACCES, 0, 0);
 
 	kfree(pathbuf);
 
security/integrity/ima/ima_fs.c +6 -5
index 2a0bca5543161912abe2a0236c9fcae7055e62bc..a0c1a6dd6a750220b529cc3f77c2ae5673188e11 100644
@@ -593,9 +593,10 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf,
 		result = ima_read_policy(data);
 	} else if (ima_appraise & IMA_APPRAISE_POLICY) {
 		pr_err("signed policy file (specified as an absolute pathname) required\n");
-		integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL, NULL,
-				    "policy_update", "signed policy required",
-				    1, 0);
+		integrity_audit_message(AUDIT_INTEGRITY_STATUS, NULL, NULL,
+					"policy_update",
+					"signed policy required",
+					result, 0, 0);
 		result = -EACCES;
 	} else {
 		ima_measure_raw_policy(data, datalen);
@@ -744,8 +745,8 @@ static int ima_release_policy(struct inode *inode, struct file *file)
 	}
 
 	pr_info("policy update %s\n", cause);
-	integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL, NULL,
-			    "policy_update", cause, !valid_policy, 0);
+	integrity_audit_message(AUDIT_INTEGRITY_STATUS, NULL, NULL,
+				"policy_update", cause, !valid_policy, 0, 0);
 
 	if (!valid_policy) {
 		ima_delete_rules();
security/integrity/ima/ima_init.c +2 -2
index d53f4d89a53e56d7ebb31950c10b37fc89782753..def350f7d6a0c58f119f2c74f26ea365471fb1c7 100644
@@ -102,8 +102,8 @@ static int __init ima_add_boot_aggregate(void)
 	}
 	return 0;
 err_out:
-	integrity_audit_msg(AUDIT_INTEGRITY_PCR, NULL, filename, op,
-			    audit_cause, result, 0);
+	integrity_audit_message(AUDIT_INTEGRITY_PCR, NULL, filename, op,
+				audit_cause, result, 0, 0);
 	return result;
 }
 
security/integrity/ima/ima_main.c +9 -7
index 334e21be407547cedfacce2a0b23cdb222192019..22d649fa19b334674b8e81dd537033cebf569699 100644
@@ -118,8 +118,9 @@ static int mmap_violation_check(enum ima_hooks func, struct file *file,
 		if (!*pathbuf)	/* ima_rdwr_violation possibly pre-fetched */
 			*pathname = ima_d_path(&file->f_path, pathbuf,
 					       filename);
-		integrity_audit_msg(AUDIT_INTEGRITY_DATA, inode, *pathname,
-				    "mmap_file", "mmapped_writers", rc, 0);
+		integrity_audit_message(AUDIT_INTEGRITY_DATA, inode, *pathname,
+					"mmap_file", "mmapped_writers", rc, 0,
+					0);
 	}
 	return rc;
 }
@@ -464,9 +465,9 @@ static int process_measurement(struct file *file, const struct cred *cred,
 	    (allowed_algos & (1U << hash_algo)) == 0) {
 		rc = -EACCES;
 
-		integrity_audit_msg(AUDIT_INTEGRITY_DATA, file_inode(file),
-				    pathname, "collect_data",
-				    "denied-hash-algorithm", rc, 0);
+		integrity_audit_message(AUDIT_INTEGRITY_DATA, file_inode(file),
+					pathname, "collect_data",
+					"denied-hash-algorithm", rc, 0, 0);
 	}
 out_locked:
 	if ((mask & MAY_WRITE) && test_bit(IMA_DIGSIG, &iint->atomic_flags) &&
@@ -578,8 +579,9 @@ static int ima_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
 
 	file = vma->vm_file;
 	pathname = ima_d_path(&file->f_path, &pathbuf, filename);
-	integrity_audit_msg(AUDIT_INTEGRITY_DATA, inode, pathname,
-			    "collect_data", "failed-mprotect", result, 0);
+	integrity_audit_message(AUDIT_INTEGRITY_DATA, inode, pathname,
+				"collect_data", "failed-mprotect", result, 0,
+				0);
 	if (pathbuf)
 		__putname(pathbuf);
 
security/integrity/ima/ima_policy.c +13 -12
index f79d07bb63c6fc4ba6fe594140de8d59f57e4f0b..4f0ebc02de4eb4cf48633f3e87362a20ece3a689 100644
@@ -1986,8 +1986,9 @@ ssize_t ima_parse_add_rule(char *rule)
 
 	entry = kzalloc_obj(*entry);
 	if (!entry) {
-		integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL,
-				    NULL, op, "-ENOMEM", -ENOMEM, audit_info);
+		integrity_audit_message(AUDIT_INTEGRITY_STATUS, NULL,
+					NULL, op, "-ENOMEM", -ENOMEM,
+					audit_info, 0);
 		return -ENOMEM;
 	}
 
@@ -1996,9 +1997,9 @@ ssize_t ima_parse_add_rule(char *rule)
 	result = ima_parse_rule(p, entry);
 	if (result) {
 		ima_free_rule(entry);
-		integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL,
-				    NULL, op, "invalid-policy", result,
-				    audit_info);
+		integrity_audit_message(AUDIT_INTEGRITY_STATUS, NULL,
+					NULL, op, "invalid-policy", result,
+					audit_info, 0);
 		return result;
 	}
 
@@ -2415,8 +2416,8 @@ void ima_measure_loaded_policy(void)
 
 	rule = kmalloc(rule_len, GFP_KERNEL);
 	if (!rule) {
-		integrity_audit_msg(AUDIT_INTEGRITY_PCR, NULL, event_name,
-				    op, "ENOMEM", result, 0);
+		integrity_audit_message(AUDIT_INTEGRITY_PCR, NULL, event_name,
+					op, "ENOMEM", result, 0, 0);
 		return;
 	}
 
@@ -2433,9 +2434,9 @@ void ima_measure_loaded_policy(void)
 
 		if (seq_has_overflowed(&file)) {
 			result = -E2BIG;
-			integrity_audit_msg(AUDIT_INTEGRITY_PCR, NULL,
-					    event_name, op, "rule_length",
-					    result, 0);
+			integrity_audit_message(AUDIT_INTEGRITY_PCR, NULL,
+						event_name, op, "rule_length",
+						result, 0, 0);
 			rcu_read_unlock();
 			goto free_rule;
 		}
@@ -2448,8 +2449,8 @@ void ima_measure_loaded_policy(void)
 	/* copy IMA policy rules to a buffer for measuring */
 	file.buf = kmalloc(file_len, GFP_KERNEL);
 	if (!file.buf) {
-		integrity_audit_msg(AUDIT_INTEGRITY_PCR, NULL, event_name,
-				    op, "ENOMEM", result, 0);
+		integrity_audit_message(AUDIT_INTEGRITY_PCR, NULL, event_name,
+					op, "ENOMEM", result, 0, 0);
 		goto free_rule;
 	}
 
security/integrity/ima/ima_queue.c +2 -2
index f89f0ca3d4edf16a7147b3c23d25fc2cf18044c6..e7b4df6b2ca299c38976012ac6eaaffcc5100e51 100644
@@ -291,8 +291,8 @@ int ima_add_template_entry(struct ima_template_entry *entry, int violation,
 	}
 out:
 	mutex_unlock(&ima_extend_list_mutex);
-	integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode, filename,
-			    op, audit_cause, result, audit_info);
+	integrity_audit_message(AUDIT_INTEGRITY_PCR, inode, filename, op,
+				audit_cause, result, audit_info, 0);
 	return result;
 }
 
security/integrity/ima/ima_template_lib.c +3 -3
index 8a89236f926c10af0dd2b2ef08fbe59bd8a78b66..c87dcbe67820266149da6ad7d4f2f7061ff3c5c1 100644
@@ -390,9 +390,9 @@ int ima_eventdigest_init(struct ima_event_data *event_data,
 	    ima_hash_algo : HASH_ALGO_SHA1;
 	result = ima_calc_file_hash(event_data->file, hash_hdr);
 	if (result) {
-		integrity_audit_msg(AUDIT_INTEGRITY_DATA, inode,
-				    event_data->filename, "collect_data",
-				    "failed", result, 0);
+		integrity_audit_message(AUDIT_INTEGRITY_DATA, inode,
+					event_data->filename, "collect_data",
+					"failed", result, 0, 0);
 		return result;
 	}
 	cur_digest = hash_hdr->digest;
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH v2 1/3] integrity: Replace all uses of integrity_audit_msg() with integrity_audit_message()

Quoted 7 lines · Frederick Lawler

integrity_audit_msg() wraps integrity_audit_message() such that error codes are hidden by passing an additional parameter to integrity_audit_message(). Since this is a wrapper, we can replace this function with integrity_audit_message() introduced in commit 2f845882ecd2 ("integrity: Add errno field in audit message")

No functional change intended.

There's an unintentional change in ima_write_policy(), which replaces the existing '1' with result.

Quoted 2 lines

Is renaming integrity_audit_msg() to integrity_audit_message() actually the right approach here? integrity_audit_message() currently has only 2 callers vs. ~20+ for integrity_audit_msg(), and the rename forces re-wrapping of every multi-line call site since integrity_audit_message is 4 chars longer, bloating the first patch.

Why not simply add errno to the integrity_audit_msg() definition and callers.

Patch 1 — Add errno param to integrity_audit_msg(); update its ~20+ existing call sites with real error values. Purely semantic, needs careful per-site review.

Patch 2 — Convert integrity_audit_message()'s 2 callers to integrity_audit_msg() (now identical signature, trivial rename), then delete integrity_audit_message() as dead code. Purely mechanical, trivially reviewable, no functional risk.

thanks,

Mimi

Quoted 21 lines

---

security/integrity/ima/ima_fs.c +4 -3
index 2a0bca5543161912abe2a0236c9fcae7055e62bc..a0c1a6dd6a750220b529cc3f77c2ae5673188e11 100644
@@ -593,9 +593,10 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf,
 		result = ima_read_policy(data);
 	} else if (ima_appraise & IMA_APPRAISE_POLICY) {
 		pr_err("signed policy file (specified as an absolute pathname) required\n");
-		integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL, NULL,
-				    "policy_update", "signed policy required",
-				    1, 0);
+		integrity_audit_message(AUDIT_INTEGRITY_STATUS, NULL, NULL,
+					"policy_update",
+					"signed policy required",
+					result, 0, 0);
 		result = -EACCES;
 	} else {
 		ima_measure_raw_policy(data, datalen);
#3 lore raw

Re: [PATCH v2 1/3] integrity: Replace all uses of integrity_audit_msg() with integrity_audit_message()

Hi Mimi,

Quoted 11 lines · Mimi Zohar
Quoted 7 lines · Frederick Lawler

integrity_audit_msg() wraps integrity_audit_message() such that error codes are hidden by passing an additional parameter to integrity_audit_message(). Since this is a wrapper, we can replace this function with integrity_audit_message() introduced in commit 2f845882ecd2 ("integrity: Add errno field in audit message")

No functional change intended.

There's an unintentional change in ima_write_policy(), which replaces the existing '1' with result.

Oof. Good catch. That was intended for the later patch.

Quoted 4 lines
Quoted 3 lines
Quoted 8 lines

Is renaming integrity_audit_msg() to integrity_audit_message() actually the right approach here? integrity_audit_message() currently has only 2 callers vs. ~20+ for integrity_audit_msg(), and the rename forces re-wrapping of every multi-line call site since integrity_audit_message is 4 chars longer, bloating the first patch.

Why not simply add errno to the integrity_audit_msg() definition and callers.

I can switch that around. I assumed we'd want to keep _message() since that was wrapped by _msg(). And not dealing with the line-wrapping is better.

Best,
Fred

maintainer
#4 lore raw

Re: [PATCH v2 1/3] integrity: Replace all uses of integrity_audit_msg() with integrity_audit_message()

Quoted 27 lines · Frederick Lawler

Hi Mimi,

Quoted 11 lines · Mimi Zohar
Quoted 7 lines · Frederick Lawler

integrity_audit_msg() wraps integrity_audit_message() such that error codes are hidden by passing an additional parameter to integrity_audit_message(). Since this is a wrapper, we can replace this function with integrity_audit_message() introduced in commit 2f845882ecd2 ("integrity: Add errno field in audit message")

No functional change intended.

There's an unintentional change in ima_write_policy(), which replaces the existing '1' with result.

Oof. Good catch. That was intended for the later patch.

Quoted 10 lines
Quoted 3 lines

Is renaming integrity_audit_msg() to integrity_audit_message() actually the right approach here? integrity_audit_message() currently has only 2 callers vs. ~20+ for integrity_audit_msg(), and the rename forces re-wrapping of every multi-line call site since integrity_audit_message is 4 chars longer, bloating the first patch.

Quoted 6 lines
Quoted 2 lines

Why not simply add errno to the integrity_audit_msg() definition and callers.

I can switch that around. I assumed we'd want to keep _message() since that was wrapped by _msg(). And not dealing with the line-wrapping is better.

No, making integrity_audit_msg() a wrapper for integrity_audit_message was done for expediency, instead of changing ALL the integrity_audit_msg() call sites.

Thank you for taking the time to review all the integrity_audit_msg() call sites and adding errno..

Mimi

#5 lore raw

PATCH v2 2/3 integrity: Remove integrity_audit_msg()

In reply to Frederick Lawler

There are no more users of integrity_audit_msg(). Remove it.

---
 security/integrity/integrity.h       | 11 -----------
 security/integrity/integrity_audit.c |  8 --------
 2 files changed, 19 deletions(-)
security/integrity/integrity.h +0 -11
index 0c581c03c5da72d80e9c352a7adff1fb89628644..1a88c245f3dde01ceb759383ef870c16de80626a 100644
@@ -216,10 +216,6 @@ static inline void evm_load_x509(void)
 
 #ifdef CONFIG_INTEGRITY_AUDIT
 /* declarations */
-void integrity_audit_msg(int audit_msgno, struct inode *inode,
-			 const unsigned char *fname, const char *op,
-			 const char *cause, int result, int info);
-
 void integrity_audit_message(int audit_msgno, struct inode *inode,
 			     const unsigned char *fname, const char *op,
 			     const char *cause, int result, int info,
@@ -232,13 +228,6 @@ integrity_audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, int type)
 }
 
 #else
-static inline 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 void integrity_audit_message(int audit_msgno,
 					   struct inode *inode,
 					   const unsigned char *fname,
security/integrity/integrity_audit.c +0 -8
index d8d9e5ff1cd22b091f462d1e83d28d2d6bd983e9..cf98d00f1a1681ff738763d5c4d95c025f7d9ca5 100644
@@ -25,14 +25,6 @@ static int __init integrity_audit_setup(char *str)
 }
 __setup("integrity_audit=", integrity_audit_setup);
 
-void integrity_audit_msg(int audit_msgno, struct inode *inode,
-			 const unsigned char *fname, const char *op,
-			 const char *cause, int result, int audit_info)
-{
-	integrity_audit_message(audit_msgno, inode, fname, op, cause,
-				result, audit_info, 0);
-}
-
 void integrity_audit_message(int audit_msgno, struct inode *inode,
 			     const unsigned char *fname, const char *op,
 			     const char *cause, int result, int audit_info,
Signature · 1 line
2.43.0
#6 lore raw

PATCH v2 3/3 integrity: Report error code in integrity_audit_message() call sites

In reply to Frederick Lawler

Most IMA functions return a error code reported with a log message, or depend on a error code from a callee in prior code paths. When inspecting audit logs, it's not always clear a message was produced in the first place because the cause may not expose the underlying reason. Since integrity_audit_message() can take a error code, expose these where it makes sense.

---
 security/integrity/evm/evm_main.c         |  8 ++++----
 security/integrity/ima/ima_api.c          |  8 ++++----
 security/integrity/ima/ima_appraise.c     |  6 +++---
 security/integrity/ima/ima_fs.c           |  2 +-
 security/integrity/ima/ima_init.c         |  2 +-
 security/integrity/ima/ima_main.c         |  6 +++---
 security/integrity/ima/ima_policy.c       | 10 +++++-----
 security/integrity/ima/ima_queue.c        |  2 +-
 security/integrity/ima/ima_template_lib.c |  2 +-
 9 files changed, 23 insertions(+), 23 deletions(-)
security/integrity/evm/evm_main.c +4 -4
index a32c98089b055fcf84f1a33dd016a51f57693d36..ba5c0dc4a8c131165aee688be68b27462489bd12 100644
@@ -563,7 +563,7 @@ static int evm_protect_xattr(struct mnt_idmap *idmap,
 					dentry->d_inode, dentry->d_name.name,
 					"update_metadata",
 					integrity_status_msg[evm_status],
-					-EPERM, 0, 0);
+					-EPERM, 0, -EPERM);
 	}
 out:
 	/* Exception if the HMAC is not going to be calculated. */
@@ -590,7 +590,7 @@ static int evm_protect_xattr(struct mnt_idmap *idmap,
 					dentry->d_name.name,
 					"appraise_metadata",
 					integrity_status_msg[evm_status],
-					-EPERM, 0, 0);
+					-EPERM, 0, -EPERM);
 	return evm_status == INTEGRITY_PASS ? 0 : -EPERM;
 }
 
@@ -733,7 +733,7 @@ static int evm_inode_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 					dentry->d_name.name,
 					"appraise_metadata",
 					integrity_status_msg[evm_status],
-					-EPERM, 0, 0);
+					-EPERM, 0, -EPERM);
 	return -EPERM;
 }
 
@@ -998,7 +998,7 @@ static int evm_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 				d_backing_inode(dentry), dentry->d_name.name,
 				"appraise_metadata",
 				integrity_status_msg[evm_status], -EPERM, 0,
-				0);
+				-EPERM);
 	return -EPERM;
 }
 
security/integrity/ima/ima_api.c +4 -4
index 8c37dd4c9bb805213fb62e597a70189eca12b897..1c40fea4b9a7d990ffe2c1a5ce54cec94f9cb7ef 100644
@@ -116,7 +116,7 @@ int ima_store_template(struct ima_template_entry *entry,
 		if (result < 0) {
 			integrity_audit_message(AUDIT_INTEGRITY_PCR, inode,
 						template_name, op, audit_cause,
-						result, 0, 0);
+						result, 0, result);
 			return result;
 		}
 	}
@@ -159,7 +159,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
 		ima_free_template_entry(entry);
 err_out:
 	integrity_audit_message(AUDIT_INTEGRITY_PCR, inode, filename, op,
-				cause, result, 0, 0);
+				cause, result, 0, result);
 }
 
 /**
@@ -330,7 +330,7 @@ int ima_collect_measurement(struct ima_iint_cache *iint, struct file *file,
 
 		integrity_audit_message(AUDIT_INTEGRITY_DATA, inode,
 					filename.name.name, "collect_data",
-					audit_cause, result, 0, 0);
+					audit_cause, result, 0, result);
 
 		release_dentry_name_snapshot(&filename);
 	}
@@ -383,7 +383,7 @@ void ima_store_measurement(struct ima_iint_cache *iint, struct file *file,
 	result = ima_alloc_init_template(&event_data, &entry, template_desc);
 	if (result < 0) {
 		integrity_audit_message(AUDIT_INTEGRITY_PCR, inode, filename,
-					op, audit_cause, result, 0, 0);
+					op, audit_cause, result, 0, result);
 		return;
 	}
 
security/integrity/ima/ima_appraise.c +3 -3
index cc88e3add5b7028d4901e284ef920b324645e719..6c9c1e04669a700c0558639a6f06bd759de60aef 100644
@@ -559,7 +559,7 @@ int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint,
 		status = INTEGRITY_FAIL;
 		cause = "unverifiable-signature";
 		integrity_audit_message(audit_msgno, inode, filename,
-					op, cause, rc, 0, 0);
+					op, cause, rc, 0, rc);
 	} else if (status != INTEGRITY_PASS) {
 		/* Fix mode, but don't replace file signatures. */
 		if ((ima_appraise & IMA_APPRAISE_FIX) && !try_modsig &&
@@ -584,7 +584,7 @@ int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint,
 		}
 
 		integrity_audit_message(audit_msgno, inode, filename,
-					op, cause, rc, 0, 0);
+					op, cause, rc, 0, rc);
 	} else {
 		ima_cache_flags(iint, func);
 	}
@@ -745,7 +745,7 @@ static int validate_hash_algo(struct dentry *dentry,
 	path = dentry_path(dentry, pathbuf, PATH_MAX);
 
 	integrity_audit_message(AUDIT_INTEGRITY_DATA, d_inode(dentry), path,
-				"set_data", errmsg, -EACCES, 0, 0);
+				"set_data", errmsg, -EACCES, 0, -EACCES);
 
 	kfree(pathbuf);
 
security/integrity/ima/ima_fs.c +1 -1
index a0c1a6dd6a750220b529cc3f77c2ae5673188e11..deadc946af641811928b7e65d53de3515126e85a 100644
@@ -596,7 +596,7 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf,
 		integrity_audit_message(AUDIT_INTEGRITY_STATUS, NULL, NULL,
 					"policy_update",
 					"signed policy required",
-					result, 0, 0);
+					result, 0, result);
 		result = -EACCES;
 	} else {
 		ima_measure_raw_policy(data, datalen);
security/integrity/ima/ima_init.c +1 -1
index def350f7d6a0c58f119f2c74f26ea365471fb1c7..ca53a19911dab46b7bfd34fba2fc1380da872b14 100644
@@ -103,7 +103,7 @@ static int __init ima_add_boot_aggregate(void)
 	return 0;
 err_out:
 	integrity_audit_message(AUDIT_INTEGRITY_PCR, NULL, filename, op,
-				audit_cause, result, 0, 0);
+				audit_cause, result, 0, result);
 	return result;
 }
 
security/integrity/ima/ima_main.c +3 -3
index 22d649fa19b334674b8e81dd537033cebf569699..1d2a2ab2ff89e92f34b58e4b7c651f1d21daf7e2 100644
@@ -120,7 +120,7 @@ static int mmap_violation_check(enum ima_hooks func, struct file *file,
 					       filename);
 		integrity_audit_message(AUDIT_INTEGRITY_DATA, inode, *pathname,
 					"mmap_file", "mmapped_writers", rc, 0,
-					0);
+					rc);
 	}
 	return rc;
 }
@@ -467,7 +467,7 @@ static int process_measurement(struct file *file, const struct cred *cred,
 
 		integrity_audit_message(AUDIT_INTEGRITY_DATA, file_inode(file),
 					pathname, "collect_data",
-					"denied-hash-algorithm", rc, 0, 0);
+					"denied-hash-algorithm", rc, 0, rc);
 	}
 out_locked:
 	if ((mask & MAY_WRITE) && test_bit(IMA_DIGSIG, &iint->atomic_flags) &&
@@ -581,7 +581,7 @@ static int ima_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
 	pathname = ima_d_path(&file->f_path, &pathbuf, filename);
 	integrity_audit_message(AUDIT_INTEGRITY_DATA, inode, pathname,
 				"collect_data", "failed-mprotect", result, 0,
-				0);
+				result);
 	if (pathbuf)
 		__putname(pathbuf);
 
security/integrity/ima/ima_policy.c +5 -5
index 4f0ebc02de4eb4cf48633f3e87362a20ece3a689..3961f0b99d0672efdb4cd225ab86a54c2a75df5b 100644
@@ -1988,7 +1988,7 @@ ssize_t ima_parse_add_rule(char *rule)
 	if (!entry) {
 		integrity_audit_message(AUDIT_INTEGRITY_STATUS, NULL,
 					NULL, op, "-ENOMEM", -ENOMEM,
-					audit_info, 0);
+					audit_info, -ENOMEM);
 		return -ENOMEM;
 	}
 
@@ -1999,7 +1999,7 @@ ssize_t ima_parse_add_rule(char *rule)
 		ima_free_rule(entry);
 		integrity_audit_message(AUDIT_INTEGRITY_STATUS, NULL,
 					NULL, op, "invalid-policy", result,
-					audit_info, 0);
+					audit_info, result);
 		return result;
 	}
 
@@ -2417,7 +2417,7 @@ void ima_measure_loaded_policy(void)
 	rule = kmalloc(rule_len, GFP_KERNEL);
 	if (!rule) {
 		integrity_audit_message(AUDIT_INTEGRITY_PCR, NULL, event_name,
-					op, "ENOMEM", result, 0, 0);
+					op, "ENOMEM", result, 0, result);
 		return;
 	}
 
@@ -2436,7 +2436,7 @@ void ima_measure_loaded_policy(void)
 			result = -E2BIG;
 			integrity_audit_message(AUDIT_INTEGRITY_PCR, NULL,
 						event_name, op, "rule_length",
-						result, 0, 0);
+						result, 0, result);
 			rcu_read_unlock();
 			goto free_rule;
 		}
@@ -2450,7 +2450,7 @@ void ima_measure_loaded_policy(void)
 	file.buf = kmalloc(file_len, GFP_KERNEL);
 	if (!file.buf) {
 		integrity_audit_message(AUDIT_INTEGRITY_PCR, NULL, event_name,
-					op, "ENOMEM", result, 0, 0);
+					op, "ENOMEM", result, 0, result);
 		goto free_rule;
 	}
 
security/integrity/ima/ima_queue.c +1 -1
index e7b4df6b2ca299c38976012ac6eaaffcc5100e51..3b898930dea66ae6362160d0b47a320e16453280 100644
@@ -292,7 +292,7 @@ int ima_add_template_entry(struct ima_template_entry *entry, int violation,
 out:
 	mutex_unlock(&ima_extend_list_mutex);
 	integrity_audit_message(AUDIT_INTEGRITY_PCR, inode, filename, op,
-				audit_cause, result, audit_info, 0);
+				audit_cause, result, audit_info, result);
 	return result;
 }
 
security/integrity/ima/ima_template_lib.c +1 -1
index c87dcbe67820266149da6ad7d4f2f7061ff3c5c1..6d163312fb4c47ce256766e997aac5f7375088a8 100644
@@ -392,7 +392,7 @@ int ima_eventdigest_init(struct ima_event_data *event_data,
 	if (result) {
 		integrity_audit_message(AUDIT_INTEGRITY_DATA, inode,
 					event_data->filename, "collect_data",
-					"failed", result, 0, 0);
+					"failed", result, 0, result);
 		return result;
 	}
 	cur_digest = hash_hdr->digest;
Signature · 1 line
2.43.0
#7 lore raw
In reply to Frederick Lawler

Hi Mimi and Roberto,

Quoted 24 lines · Frederick Lawler

Commit 2f845882ecd2 ("integrity: Add errno field in audit message") introduced an audit log function that can take an error code. It is wrapped by integrity_audit_msg() that implicitly sets the error code argument to zero. The problem is that there are uses of integrity_audit_msg() such as ima_collect_measurement() that hide the failure cause for the message.

This series aims to convert integrity_audit_msg() call sites to integrity_audit_message(), and then expose error codes based on the following criteria:

1. The log depends on a result from earlier callee, and/or
2. The caller function itself returns with that result

ima_release_policy() is the only caller I thought made sense to keep as is. The message doesn't correlate with a return code, nor does it depend on a result from an earlier callee in the function.

---
This is probably a bit more than what was asked from v1, but as I was making changes and looking at other call sites, I didn't think it made sense to keep integrity_audit_msg() around anymore.

Quoted 6 lines

Changes in v2:
- Changes from v1 are now reflected in patch 3.
- Replace all instances of integrity_audit_msg().
- Convert to patch series.
- Link to v1: https://lore.kernel.org/r/[email protected]

I think this series may have fallen through the cracks between the merge windows. Shall I respin + rebase?

Best,
Fred

maintainer
#8 lore raw
Quoted 34 lines · Frederick Lawler

Hi Mimi and Roberto,

Quoted 24 lines · Frederick Lawler

Commit 2f845882ecd2 ("integrity: Add errno field in audit message") introduced an audit log function that can take an error code. It is wrapped by integrity_audit_msg() that implicitly sets the error code argument to zero. The problem is that there are uses of integrity_audit_msg() such as ima_collect_measurement() that hide the failure cause for the message.

This series aims to convert integrity_audit_msg() call sites to integrity_audit_message(), and then expose error codes based on the following criteria:

1. The log depends on a result from earlier callee, and/or
2. The caller function itself returns with that result

ima_release_policy() is the only caller I thought made sense to keep as is. The message doesn't correlate with a return code, nor does it depend on a result from an earlier callee in the function.

---
This is probably a bit more than what was asked from v1, but as I was making changes and looking at other call sites, I didn't think it made sense to keep integrity_audit_msg() around anymore.

Quoted 6 lines

Changes in v2:
- Changes from v1 are now reflected in patch 3.
- Replace all instances of integrity_audit_msg().
- Convert to patch series.
- Link to v1: https://lore.kernel.org/r/[email protected]

Quoted 2 lines

I think this series may have fallen through the cracks between the merge windows. Shall I respin + rebase?

Thanks for the reminder. Let me take a look at it again, before you post another version. It might take a few days until I get to it.

Thanks,

Mimi