Skip to contentSkip to conversation

kernel/audit: Use struct_group() for memcpy() region

PATCH New [email protected] 1 participant 1 message Dec 2, 2024 Audit

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel/audit: Use struct_group() for memcpy() region

From: lihaojie <[email protected]>

In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memcpy(), memmove(), and memset(), avoid intentionally writing across neighboring fields.

Use struct_group() in struct audit_context around members target_comm[], This will allow memcpy() and sizeof() to more easily reason about sizes, improve readability, and avoid future warnings about writing beyond the end of target_comm[].

"pahole" shows no size nor member offset changes to struct vlan_ethhdr. "objdump -d" shows no object code changes.

---
 kernel/audit.h   | 5 ++++-
 kernel/auditsc.c | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)
kernel/audit.h +4 -1
index 0211cb307d30..20483670ea02 100644
@@ -145,7 +145,10 @@ struct audit_context {
 	kuid_t		    target_uid;
 	unsigned int	    target_sessionid;
 	struct lsm_prop	    target_ref;
-	char		    target_comm[TASK_COMM_LEN];
+
+	struct_group(comm,
+		char target_comm[TASK_COMM_LEN];
+	);
 
 	struct audit_tree_refs *trees, *first_trees;
 	struct list_head killed_trees;
kernel/auditsc.c +2 -2
index 91afdd0d036e..e279762463b0 100644
@@ -2729,7 +2729,7 @@ void __audit_ptrace(struct task_struct *t)
 	context->target_uid = task_uid(t);
 	context->target_sessionid = audit_get_sessionid(t);
 	security_task_getlsmprop_obj(t, &context->target_ref);
-	memcpy(context->target_comm, t->comm, TASK_COMM_LEN);
+	memcpy(&context->comm, t->comm, TASK_COMM_LEN);
 }
 
 /**
@@ -2756,7 +2756,7 @@ int audit_signal_info_syscall(struct task_struct *t)
 		ctx->target_uid = t_uid;
 		ctx->target_sessionid = audit_get_sessionid(t);
 		security_task_getlsmprop_obj(t, &ctx->target_ref);
-		memcpy(ctx->target_comm, t->comm, TASK_COMM_LEN);
+		memcpy(&ctx->comm, t->comm, TASK_COMM_LEN);
 		return 0;
 	}
 
Signature · 1 line
2.25.1