Skip to contentSkip to conversation

ima: return IMA digest value only when IMA_COLLECTED flag is set

PATCH In review Matt Bobrowski 1 participant 2 messages Jan 4, 2023 – Jan 22, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ima: return IMA digest value only when IMA_COLLECTED flag is set

The IMA_COLLECTED flag indicates whether the IMA subsystem has successfully collected a measurement for a given file object. Ensure that we return the respective digest value stored within the iint entry only when this flag has been set.

Failing to check for the presence of this flag exposes consumers of this IMA API to receive potentially undesired IMA digest values when an erroneous condition has been experienced in some of the lower level IMA API code.

---
 security/integrity/ima/ima_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/integrity/ima/ima_main.c +1 -1
index b1ae0f2751f1..1d40cdfa23d5 100644
@@ -563,7 +563,7 @@ static int __ima_inode_hash(struct inode *inode, struct file *file, char *buf,
 	 * ima_file_hash can be called when ima_collect_measurement has still
 	 * not been called, we might not always have a hash.
 	 */
-	if (!iint->ima_hash) {
+	if (!iint->ima_hash || !(iint->flags & IMA_COLLECTED)) {
 		mutex_unlock(&iint->mutex);
 		return -EOPNOTSUPP;
 	}
Signature · 3 lines
2.39.0.314.g84b9a713c41-goog

/M
#1 lore raw

Hey Mimi,

Just a gentle ping on this one.

Quoted 30 lines · Matt Bobrowski

The IMA_COLLECTED flag indicates whether the IMA subsystem has successfully collected a measurement for a given file object. Ensure that we return the respective digest value stored within the iint entry only when this flag has been set.

Failing to check for the presence of this flag exposes consumers of this IMA API to receive potentially undesired IMA digest values when an erroneous condition has been experienced in some of the lower level IMA API code.

---
 security/integrity/ima/ima_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/integrity/ima/ima_main.c +1 -1
index b1ae0f2751f1..1d40cdfa23d5 100644
@@ -563,7 +563,7 @@ static int __ima_inode_hash(struct inode *inode, struct file *file, char *buf,
 	 * ima_file_hash can be called when ima_collect_measurement has still
 	 * not been called, we might not always have a hash.
 	 */
-	if (!iint->ima_hash) {
+	if (!iint->ima_hash || !(iint->flags & IMA_COLLECTED)) {
 		mutex_unlock(&iint->mutex);
 		return -EOPNOTSUPP;
 	}
Signature · 1 line
2.39.0.314.g84b9a713c41-goog

/M