From 7c58ed44bd399277c4a14fcb4e447e1da39870d3 Mon Sep 17 00:00:00 2001 From: Yafang Shao Date: Thu, 19 Dec 2024 10:34:51 +0800 Subject: security: remove get_task_comm() and print task comm directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations. Link: https://lkml.kernel.org/r/20241219023452.69907-5-laoar.shao@gmail.com Signed-off-by: Yafang Shao Reviewed-by: Paul Moore Acked-by: Kees Cook Cc: James Morris Cc: "Serge E. Hallyn" Cc: "André Almeida" Cc: Andy Shevchenko Cc: Borislav Petkov (AMD) Cc: Danilo Krummrich Cc: Darren Hart Cc: Dave Hansen Cc: David Airlie Cc: Davidlohr Bueso Cc: Greg Kroah-Hartman Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Jani Nikula Cc: Jiri Slaby Cc: Johannes Berg Cc: Joonas Lahtinen Cc: Kalle Valo Cc: Karol Herbst Cc: Linus Torvalds Cc: Lyude Paul Cc: Oded Gabbay Cc: Peter Zijlstra Cc: Petr Mladek Cc: Rodrigo Vivi Cc: Simona Vetter Cc: Thomas Gleixner Cc: Tvrtko Ursulin Cc: Vineet Gupta Signed-off-by: Andrew Morton --- security/yama/yama_lsm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'security') diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c index e1a5e13ea269..1a2d02fee09b 100644 --- a/security/yama/yama_lsm.c +++ b/security/yama/yama_lsm.c @@ -76,7 +76,6 @@ static void report_access(const char *access, struct task_struct *target, struct task_struct *agent) { struct access_report_info *info; - char agent_comm[sizeof(agent->comm)]; assert_spin_locked(&target->alloc_lock); /* for target->comm */ @@ -86,8 +85,7 @@ static void report_access(const char *access, struct task_struct *target, */ pr_notice_ratelimited( "ptrace %s of \"%s\"[%d] was attempted by \"%s\"[%d]\n", - access, target->comm, target->pid, - get_task_comm(agent_comm, agent), agent->pid); + access, target->comm, target->pid, agent->comm, agent->pid); return; } -- cgit v1.2.3