public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] coredump: Do not lock during 'comm' reporting
@ 2024-09-28 21:08 Kees Cook
  2024-09-28 21:35 ` Andrew Morton
  0 siblings, 1 reply; 6+ messages in thread
From: Kees Cook @ 2024-09-28 21:08 UTC (permalink / raw)
  To: Vegard Nossum
  Cc: Kees Cook, Eric W. Biederman, Allen Pais, Andrew Morton,
	Roman Kisel, Xiaoming Ni, Vijay Nag, linux-kernel,
	linux-hardening

The 'comm' member will always be NUL terminated, and this is not
fast-path, so we can just perform a direct memcpy during a coredump
instead of potentially deadlocking while holding the task struct lock.

Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Closes: https://lore.kernel.org/all/d122ece6-3606-49de-ae4d-8da88846bef2@oracle.com
Fixes: c114e9948c2b ("coredump: Standartize and fix logging")
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Allen Pais <apais@linux.microsoft.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Roman Kisel <romank@linux.microsoft.com>
Cc: Xiaoming Ni <nixiaoming@huawei.com>

Vegard, can you validate that this fixes the problem for you? I have
been wrecked by covid, so very slow to respond here. There's a related
thread about this locked, but we can just totally bypass it here.

---
 include/linux/coredump.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/coredump.h b/include/linux/coredump.h
index edeb8532ce0f..a99079115a38 100644
--- a/include/linux/coredump.h
+++ b/include/linux/coredump.h
@@ -52,8 +52,8 @@ extern int do_coredump(const kernel_siginfo_t *siginfo);
 #define __COREDUMP_PRINTK(Level, Format, ...) \
 	do {	\
 		char comm[TASK_COMM_LEN];	\
-	\
-		get_task_comm(comm, current);	\
+		/* This will always be NUL terminated. */ \
+		memcpy(comm, current->comm, sizeof(comm)); \
 		printk_ratelimited(Level "coredump: %d(%*pE): " Format "\n",	\
 			task_tgid_vnr(current), (int)strlen(comm), comm, ##__VA_ARGS__);	\
 	} while (0)	\
-- 
2.34.1


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

end of thread, other threads:[~2024-09-29 18:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-28 21:08 [PATCH] coredump: Do not lock during 'comm' reporting Kees Cook
2024-09-28 21:35 ` Andrew Morton
2024-09-28 21:39   ` Kees Cook
2024-09-28 21:46     ` Andrew Morton
2024-09-28 21:51       ` Kees Cook
2024-09-29 18:42         ` Vegard Nossum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox