mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] init: Use strscpy() in do_initcalls()
@ 2026-11-14 11:52 Thorsten Blum
  2026-11-14 11:52 ` [PATCH 2/2] init: Use kmalloc() " Thorsten Blum
  2026-11-15 15:00 ` [PATCH 1/2] init: Use strscpy() " David Laight
  0 siblings, 2 replies; 3+ messages in thread
From: Thorsten Blum @ 2026-11-14 11:52 UTC (permalink / raw)
  To: Andrew Morton, Masami Hiramatsu (Google),
	Breno Leitao, Christian Brauner, Sang-Heon Jeon,
	Wilson Felipe Pereira, Ryan Roberts
  Cc: Thorsten Blum, Mike Rapoport (Microsoft), linux-kernel

Replace the deprecated strcpy() [1] with strscpy() to bound the copy to
the allocated buffer size.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 init/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/init/main.c b/init/main.c
index db8fb6ebe830..93a2b12976f0 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1481,7 +1481,7 @@ static void __init do_initcalls(void)
 
 	for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++) {
 		/* Parser modifies command_line, restore it each time */
-		strcpy(command_line, saved_command_line);
+		strscpy(command_line, saved_command_line, len);
 		do_initcall_level(level, command_line);
 	}
 

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

* [PATCH 2/2] init: Use kmalloc() in do_initcalls()
  2026-11-14 11:52 [PATCH 1/2] init: Use strscpy() in do_initcalls() Thorsten Blum
@ 2026-11-14 11:52 ` Thorsten Blum
  2026-11-15 15:00 ` [PATCH 1/2] init: Use strscpy() " David Laight
  1 sibling, 0 replies; 3+ messages in thread
From: Thorsten Blum @ 2026-11-14 11:52 UTC (permalink / raw)
  To: Andrew Morton, Masami Hiramatsu (Google),
	Breno Leitao, Sang-Heon Jeon, Christian Brauner,
	Wilson Felipe Pereira, Ryan Roberts
  Cc: Thorsten Blum, linux-kernel

Use kmalloc() since strscpy() already NUL-terminates command_line.

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 init/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/init/main.c b/init/main.c
index 93a2b12976f0..7f52a1b00c0f 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1475,7 +1475,7 @@ static void __init do_initcalls(void)
 	size_t len = saved_command_line_len + 1;
 	char *command_line;
 
-	command_line = kzalloc(len, GFP_KERNEL);
+	command_line = kmalloc(len, GFP_KERNEL);
 	if (!command_line)
 		panic("%s: Failed to allocate %zu bytes\n", __func__, len);
 

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

* Re: [PATCH 1/2] init: Use strscpy() in do_initcalls()
  2026-11-14 11:52 [PATCH 1/2] init: Use strscpy() in do_initcalls() Thorsten Blum
  2026-11-14 11:52 ` [PATCH 2/2] init: Use kmalloc() " Thorsten Blum
@ 2026-11-15 15:00 ` David Laight
  1 sibling, 0 replies; 3+ messages in thread
From: David Laight @ 2026-11-15 15:00 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Andrew Morton, Masami Hiramatsu (Google),
	Breno Leitao, Christian Brauner, Sang-Heon Jeon,
	Wilson Felipe Pereira, Ryan Roberts, Mike Rapoport (Microsoft),
	linux-kernel

On Sat, 14 Nov 2026 12:52:29 +0100
Thorsten Blum <blum@kernel.org> wrote:

> Replace the deprecated strcpy() [1] with strscpy() to bound the copy to
> the allocated buffer size.
> 
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
> Signed-off-by: Thorsten Blum <blum@kernel.org>
> ---
>  init/main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/init/main.c b/init/main.c
> index db8fb6ebe830..93a2b12976f0 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -1481,7 +1481,7 @@ static void __init do_initcalls(void)
>  
>  	for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++) {
>  		/* Parser modifies command_line, restore it each time */
> -		strcpy(command_line, saved_command_line);
> +		strscpy(command_line, saved_command_line, len);

That could be a memcpy().

David

>  		do_initcall_level(level, command_line);
>  	}
>  
> 


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

end of thread, other threads:[~2026-11-15 15:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-14 11:52 [PATCH 1/2] init: Use strscpy() in do_initcalls() Thorsten Blum
2026-11-14 11:52 ` [PATCH 2/2] init: Use kmalloc() " Thorsten Blum
2026-11-15 15:00 ` [PATCH 1/2] init: Use strscpy() " David Laight

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

all inboxes | Powered by JetHome®