All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] init/main.c: Fix potential static_command_line memory overflow
@ 2024-04-11  3:21 Yuntao Wang
  2024-04-11  7:23 ` Geert Uytterhoeven
  0 siblings, 1 reply; 14+ messages in thread
From: Yuntao Wang @ 2024-04-11  3:21 UTC (permalink / raw)
  To: linux-kernel
  Cc: Thomas Gleixner, Andrew Morton, ndesaulniers@google.com,
	Josh Poimboeuf, Peter Zijlstra (Intel), Tejun Heo,
	Christophe Leroy, Krister Johansen, Arnd Bergmann,
	Geert Uytterhoeven, Mike Rapoport, Yuntao Wang

We allocate memory of size 'xlen + strlen(boot_command_line) + 1' for
static_command_line, but the strings copied into static_command_line are
extra_command_line and command_line, rather than extra_command_line and
boot_command_line.

When strlen(command_line) > strlen(boot_command_line), static_command_line
will overflow.

Fixes: f5c7310ac73e ("init/main: add checks for the return value of memblock_alloc*()")
Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
---
 init/main.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/init/main.c b/init/main.c
index 2ca52474d0c3..a7b1f5f3e3b6 100644
--- a/init/main.c
+++ b/init/main.c
@@ -625,11 +625,13 @@ static void __init setup_command_line(char *command_line)
 	if (extra_init_args)
 		ilen = strlen(extra_init_args) + 4; /* for " -- " */
 
-	len = xlen + strlen(boot_command_line) + 1;
+	len = xlen + strlen(boot_command_line) + ilen + 1;
 
-	saved_command_line = memblock_alloc(len + ilen, SMP_CACHE_BYTES);
+	saved_command_line = memblock_alloc(len, SMP_CACHE_BYTES);
 	if (!saved_command_line)
-		panic("%s: Failed to allocate %zu bytes\n", __func__, len + ilen);
+		panic("%s: Failed to allocate %zu bytes\n", __func__, len);
+
+	len = xlen + strlen(command_line) + 1;
 
 	static_command_line = memblock_alloc(len, SMP_CACHE_BYTES);
 	if (!static_command_line)
-- 
2.44.0


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

end of thread, other threads:[~2024-04-12 15:58 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-11  3:21 [PATCH] init/main.c: Fix potential static_command_line memory overflow Yuntao Wang
2024-04-11  7:23 ` Geert Uytterhoeven
2024-04-11 13:21   ` Mike Rapoport
2024-04-11 14:27     ` Yuntao Wang
2024-04-11 15:08       ` Masami Hiramatsu
2024-04-11 15:47         ` Yuntao Wang
2024-04-12  3:51         ` Yuntao Wang
2024-04-12  5:15           ` Masami Hiramatsu
2024-04-12  8:17             ` [PATCH v2 0/2] " Yuntao Wang
2024-04-12  8:17               ` [PATCH v2 1/2] init/main.c: " Yuntao Wang
2024-04-12  8:17               ` [PATCH v2 2/2] init/main.c: Minor cleanup for the setup_command_line() function Yuntao Wang
2024-04-12 15:58               ` [PATCH v2 0/2] Fix potential static_command_line memory overflow Masami Hiramatsu
2024-04-11 14:29   ` [PATCH] init/main.c: " Masami Hiramatsu
2024-04-11 14:59     ` Yuntao Wang

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.