All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cgroup: align the comm length with TASK_COMM_LEN
@ 2022-09-20  8:49 Kassey Li
  2022-09-22  0:33 ` Kassey Li
  0 siblings, 1 reply; 2+ messages in thread
From: Kassey Li @ 2022-09-20  8:49 UTC (permalink / raw)
  To: rostedt, mingo, tj, william.kucharski; +Cc: Kassey Li, linux-kernel

__string could get a dst string with length less than
TASK_COMM_LEN.

a task->comm possbile change dynamic that can cause
out of bounds access for the dst string buffer.

change it as arrary with same length TASK_COMM_LEN,
this aligns the same usage of include/trace on task->comm.

Signed-off-by: Kassey Li <quic_yingangl@quicinc.com>
---
 include/trace/events/cgroup.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/trace/events/cgroup.h b/include/trace/events/cgroup.h
index dd7d7c9efecd..d0c5f93e3611 100644
--- a/include/trace/events/cgroup.h
+++ b/include/trace/events/cgroup.h
@@ -130,7 +130,7 @@ DECLARE_EVENT_CLASS(cgroup_migrate,
 		__field(	u64,		dst_id			)
 		__field(	int,		pid			)
 		__string(	dst_path,	path			)
-		__string(	comm,		task->comm		)
+		__array(char,   comm, TASK_COMM_LEN)
 	),
 
 	TP_fast_assign(
@@ -139,12 +139,12 @@ DECLARE_EVENT_CLASS(cgroup_migrate,
 		__entry->dst_level = dst_cgrp->level;
 		__assign_str(dst_path, path);
 		__entry->pid = task->pid;
-		__assign_str(comm, task->comm);
+		memcpy(__entry->comm, task->comm, TASK_COMM_LEN);
 	),
 
 	TP_printk("dst_root=%d dst_id=%llu dst_level=%d dst_path=%s pid=%d comm=%s",
 		  __entry->dst_root, __entry->dst_id, __entry->dst_level,
-		  __get_str(dst_path), __entry->pid, __get_str(comm))
+		  __get_str(dst_path), __entry->pid, __entry->comm)
 );
 
 DEFINE_EVENT(cgroup_migrate, cgroup_attach_task,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-22  0:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-20  8:49 [PATCH] cgroup: align the comm length with TASK_COMM_LEN Kassey Li
2022-09-22  0:33 ` Kassey Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.