Skip to contentSkip to conversation

ima: detect file change code cleanup

PATCH In review Mimi Zohar 2 participants 2 messages Mar 6

Subsystems (4)
lore
Share & tools
lore

Mimi Zohar

author maintainer
#0 lore raw

PATCH 1/1 ima: detect file change code cleanup

Functionally no change, just simplify the ima_detect_file_change() code.

---
@Fred, looking to merge with commit 0824f861605d ("ima: fallback to using i_version to detect file change")

 security/integrity/ima/ima_main.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
security/integrity/ima/ima_main.c +7 -12
index 6c49afa8dcc0..5cea53fc36df 100644
@@ -194,18 +194,13 @@ static bool ima_detect_file_change(struct ima_iint_cache *iint,
 	result = vfs_getattr_nosec(&file->f_path, &stat, STATX_CHANGE_COOKIE,
 				   AT_STATX_SYNC_AS_STAT);
 
-	if (!result && stat.result_mask & STATX_CHANGE_COOKIE &&
-	    stat.change_cookie != iint->real_inode.version)
-		return true;
-	else if (!(stat.result_mask & STATX_CHANGE_COOKIE) &&
-		 IS_I_VERSION(inode) &&
-		 !(inode_eq_iversion(inode, iint->real_inode.version)))
-		return true;
-	else if (!(stat.result_mask & STATX_CHANGE_COOKIE) &&
-		 !(IS_I_VERSION(inode)))
-		return true;
-
-	return false;
+	if (!result && stat.result_mask & STATX_CHANGE_COOKIE)
+		return stat.change_cookie != iint->real_inode.version;
+
+	if (IS_I_VERSION(inode))
+		return !inode_eq_iversion(inode, iint->real_inode.version);
+
+	return true;
 }
 
 static void ima_check_last_writer(struct ima_iint_cache *iint,

--
2.53.0

Reviewed-by on v1 1/1
#1 lore raw

Hi Mimi,

Quoted 41 lines · Mimi Zohar

Functionally no change, just simplify the ima_detect_file_change() code.

---
@Fred, looking to merge with commit 0824f861605d ("ima: fallback to using i_version to detect file change")

 security/integrity/ima/ima_main.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
security/integrity/ima/ima_main.c +7 -13
index 6c49afa8dcc0..5cea53fc36df 100644
@@ -194,18 +194,13 @@ static bool ima_detect_file_change(struct ima_iint_cache *iint,
 	result = vfs_getattr_nosec(&file->f_path, &stat, STATX_CHANGE_COOKIE,
 				   AT_STATX_SYNC_AS_STAT);
 
-	if (!result && stat.result_mask & STATX_CHANGE_COOKIE &&
-	    stat.change_cookie != iint->real_inode.version)
-		return true;
-	else if (!(stat.result_mask & STATX_CHANGE_COOKIE) &&
-		 IS_I_VERSION(inode) &&
-		 !(inode_eq_iversion(inode, iint->real_inode.version)))
-		return true;
-	else if (!(stat.result_mask & STATX_CHANGE_COOKIE) &&
-		 !(IS_I_VERSION(inode)))
-		return true;
-
-	return false;
+	if (!result && stat.result_mask & STATX_CHANGE_COOKIE)
+		return stat.change_cookie != iint->real_inode.version;
+
+	if (IS_I_VERSION(inode))
+		return !inode_eq_iversion(inode, iint->real_inode.version);
+
+	return true;
 }
 
 static void ima_check_last_writer(struct ima_iint_cache *iint,
--
Quoted 2 lines

2.53.0

Refactor looks good to me.

Best,
Fred