All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] kdb: Replace deprecated strcpy() with strscpy() and memcpy()
@ 2025-08-14 22:01 Thorsten Blum
  2025-08-15  2:05 ` Doug Anderson
  2025-08-15  8:57 ` Daniel Thompson
  0 siblings, 2 replies; 10+ messages in thread
From: Thorsten Blum @ 2025-08-14 22:01 UTC (permalink / raw)
  To: Jason Wessel, Daniel Thompson, Douglas Anderson, Nir Lichtman,
	Greg Kroah-Hartman, Yuran Pereira
  Cc: linux-hardening, Thorsten Blum, Daniel Thompson, kgdb-bugreport,
	linux-kernel

strcpy() is deprecated; use strscpy() and memcpy() instead and remove
several manual NUL-terminations.

In parse_grep(), we can safely use memcpy() because we already know the
length of the source string 'cp' and that it is guaranteed to be
NUL-terminated within the first KDB_GREP_STRLEN bytes.

No functional changes intended.

Link: https://github.com/KSPP/linux/issues/88
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Changes in v3:
- Extract the strscpy() changes into a separate patch and focus on
  replacing the deprecated strcpy() calls as suggested by Greg
- Link to v2: https://lore.kernel.org/lkml/20250814163237.229544-2-thorsten.blum@linux.dev/

Changes in v2:
- Use memcpy() instead of strscpy() in parse_grep() as suggested by Greg
- Compile-tested only so far
- Link to v1: https://lore.kernel.org/lkml/20250814120338.219585-2-thorsten.blum@linux.dev/
---
 kernel/debug/kdb/kdb_main.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index 7a4d2d4689a5..40de0ece724b 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -727,14 +727,10 @@ static int kdb_defcmd(int argc, const char **argv)
 	mp->help = kdb_strdup(argv[3], GFP_KDB);
 	if (!mp->help)
 		goto fail_help;
-	if (mp->usage[0] == '"') {
-		strcpy(mp->usage, argv[2]+1);
-		mp->usage[strlen(mp->usage)-1] = '\0';
-	}
-	if (mp->help[0] == '"') {
-		strcpy(mp->help, argv[3]+1);
-		mp->help[strlen(mp->help)-1] = '\0';
-	}
+	if (mp->usage[0] == '"')
+		strscpy(mp->usage, argv[2] + 1, strlen(argv[2]) - 1);
+	if (mp->help[0] == '"')
+		strscpy(mp->help, argv[3] + 1, strlen(argv[3]) - 1);
 
 	INIT_LIST_HEAD(&kdb_macro->statements);
 	defcmd_in_progress = true;
@@ -860,7 +856,7 @@ static void parse_grep(const char *str)
 		kdb_printf("search string too long\n");
 		return;
 	}
-	strcpy(kdb_grep_string, cp);
+	memcpy(kdb_grep_string, cp, len + 1);
 	kdb_grepping_flag++;
 	return;
 }
-- 
2.50.1


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

end of thread, other threads:[~2025-08-15 14:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-14 22:01 [PATCH v3] kdb: Replace deprecated strcpy() with strscpy() and memcpy() Thorsten Blum
2025-08-15  2:05 ` Doug Anderson
2025-08-15 10:48   ` Thorsten Blum
2025-08-15 14:32     ` Doug Anderson
2025-08-15  8:57 ` Daniel Thompson
2025-08-15 11:28   ` Thorsten Blum
2025-08-15 11:40     ` Daniel Thompson
2025-08-15 13:16       ` Thorsten Blum
2025-08-15 14:29         ` Daniel Thompson
2025-08-15 14:40           ` Thorsten Blum

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.