The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] sprint_symbol: Replace strcpy with memmove to handle potential overlap
@ 2024-06-04  4:42 liujinlong
  2024-06-28 16:56 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: liujinlong @ 2024-06-04  4:42 UTC (permalink / raw)
  To: kees
  Cc: thunder.leizhen, yonghong.song, ndesaulniers, song, ardb,
	maninder1.s, azeemshaikh38, linux-kernel, liujinlong, k2ci

In the function __sprint_symbol, replace strcpy with memmove to ensure
correct behavior even if the source and destination buffers overlap.
This change prevents potential undefined behavior flagged by recent
compilers as [-Werror=restrict].

Reported-by: k2ci <kernel-bot@kylinos.cn>
Signed-off-by: liujinlong <liujinlong@kylinos.cn>
---
 kernel/kallsyms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 22ea19a36e6e..3c3a77fcd020 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -489,7 +489,7 @@ static int __sprint_symbol(char *buffer, unsigned long address,
 		return sprintf(buffer, "0x%lx", address - symbol_offset);
 
 	if (name != buffer)
-		strcpy(buffer, name);
+		memmove(buffer, name, strlen(name) + 1);
 	len = strlen(buffer);
 	offset -= symbol_offset;
 
-- 
2.17.1


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

end of thread, other threads:[~2024-06-28 16:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-04  4:42 [PATCH] sprint_symbol: Replace strcpy with memmove to handle potential overlap liujinlong
2024-06-28 16:56 ` Kees Cook

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