* [for-linus][PATCH 0/2] tracing: Fixes to bootconfig memory handling
@ 2021-09-14 14:48 Steven Rostedt
2021-09-14 14:48 ` [for-linus][PATCH 1/2] bootconfig: Fix to check the xbc_node is used before free it Steven Rostedt
2021-09-14 14:48 ` [for-linus][PATCH 2/2] bootconfig: Free copied bootconfig data after boot Steven Rostedt
0 siblings, 2 replies; 5+ messages in thread
From: Steven Rostedt @ 2021-09-14 14:48 UTC (permalink / raw)
To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton, Masami Hiramatsu
Some memory management fixes to the bootconfig code.
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next
Head SHA1: 8e9f0934a07e699044d422ca9cfb553f25c72b41
Masami Hiramatsu (2):
bootconfig: Fix to check the xbc_node is used before free it
bootconfig: Free copied bootconfig data after boot
----
init/main.c | 8 ++++++++
lib/bootconfig.c | 3 ++-
2 files changed, 10 insertions(+), 1 deletion(-)
^ permalink raw reply [flat|nested] 5+ messages in thread* [for-linus][PATCH 1/2] bootconfig: Fix to check the xbc_node is used before free it 2021-09-14 14:48 [for-linus][PATCH 0/2] tracing: Fixes to bootconfig memory handling Steven Rostedt @ 2021-09-14 14:48 ` Steven Rostedt 2021-09-14 16:11 ` Vlastimil Babka 2021-09-14 14:48 ` [for-linus][PATCH 2/2] bootconfig: Free copied bootconfig data after boot Steven Rostedt 1 sibling, 1 reply; 5+ messages in thread From: Steven Rostedt @ 2021-09-14 14:48 UTC (permalink / raw) To: linux-kernel Cc: Ingo Molnar, Andrew Morton, kernel test robot, Masami Hiramatsu From: Masami Hiramatsu <mhiramat@kernel.org> Fix to check the xbc_node is used before calling memblock_free() because passing NULL to phys_addr() will cause a panic. This will happen if user doesn't pass any bootconfig to the kernel, because kernel will call xbc_destroy_all() after booting. Link: https://lkml.kernel.org/r/163149460533.291098.7342418455457691240.stgit@devnote2 Fixes: 40caa127f3c7 ("init: bootconfig: Remove all bootconfig data when the init memory is removed") Reported-by: kernel test robot <oliver.sang@intel.com> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> --- lib/bootconfig.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/bootconfig.c b/lib/bootconfig.c index f8419cff1147..4f8849706ef6 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -792,7 +792,8 @@ void __init xbc_destroy_all(void) xbc_data = NULL; xbc_data_size = 0; xbc_node_num = 0; - memblock_free(__pa(xbc_nodes), sizeof(struct xbc_node) * XBC_NODE_MAX); + if (xbc_nodes) + memblock_free(__pa(xbc_nodes), sizeof(struct xbc_node) * XBC_NODE_MAX); xbc_nodes = NULL; brace_index = 0; } -- 2.32.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [for-linus][PATCH 1/2] bootconfig: Fix to check the xbc_node is used before free it 2021-09-14 14:48 ` [for-linus][PATCH 1/2] bootconfig: Fix to check the xbc_node is used before free it Steven Rostedt @ 2021-09-14 16:11 ` Vlastimil Babka 2021-09-14 16:18 ` Steven Rostedt 0 siblings, 1 reply; 5+ messages in thread From: Vlastimil Babka @ 2021-09-14 16:11 UTC (permalink / raw) To: Steven Rostedt, linux-kernel Cc: Ingo Molnar, Andrew Morton, kernel test robot, Masami Hiramatsu On 9/14/21 16:48, Steven Rostedt wrote: > From: Masami Hiramatsu <mhiramat@kernel.org> > > Fix to check the xbc_node is used before calling memblock_free() > because passing NULL to phys_addr() will cause a panic. > This will happen if user doesn't pass any bootconfig to the > kernel, because kernel will call xbc_destroy_all() after > booting. > > Link: https://lkml.kernel.org/r/163149460533.291098.7342418455457691240.stgit@devnote2 > > Fixes: 40caa127f3c7 ("init: bootconfig: Remove all bootconfig data when the init memory is removed") > Reported-by: kernel test robot <oliver.sang@intel.com> > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> > Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Should have replied here. Tested-by: Vlastimil Babka <vbabka@suse.cz> details: https://lore.kernel.org/all/61ab2d0c-3313-aaab-514c-e15b7aa054a0@suse.cz/ > --- > lib/bootconfig.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/lib/bootconfig.c b/lib/bootconfig.c > index f8419cff1147..4f8849706ef6 100644 > --- a/lib/bootconfig.c > +++ b/lib/bootconfig.c > @@ -792,7 +792,8 @@ void __init xbc_destroy_all(void) > xbc_data = NULL; > xbc_data_size = 0; > xbc_node_num = 0; > - memblock_free(__pa(xbc_nodes), sizeof(struct xbc_node) * XBC_NODE_MAX); > + if (xbc_nodes) > + memblock_free(__pa(xbc_nodes), sizeof(struct xbc_node) * XBC_NODE_MAX); > xbc_nodes = NULL; > brace_index = 0; > } > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [for-linus][PATCH 1/2] bootconfig: Fix to check the xbc_node is used before free it 2021-09-14 16:11 ` Vlastimil Babka @ 2021-09-14 16:18 ` Steven Rostedt 0 siblings, 0 replies; 5+ messages in thread From: Steven Rostedt @ 2021-09-14 16:18 UTC (permalink / raw) To: Vlastimil Babka Cc: linux-kernel, Ingo Molnar, Andrew Morton, kernel test robot, Masami Hiramatsu On Tue, 14 Sep 2021 18:11:01 +0200 Vlastimil Babka <vbabka@suse.cz> wrote: > Should have replied here. > > Tested-by: Vlastimil Babka <vbabka@suse.cz> Thanks, but I already sent a pull request to Linus. Too late to add the tag. :-/ -- Steve ^ permalink raw reply [flat|nested] 5+ messages in thread
* [for-linus][PATCH 2/2] bootconfig: Free copied bootconfig data after boot 2021-09-14 14:48 [for-linus][PATCH 0/2] tracing: Fixes to bootconfig memory handling Steven Rostedt 2021-09-14 14:48 ` [for-linus][PATCH 1/2] bootconfig: Fix to check the xbc_node is used before free it Steven Rostedt @ 2021-09-14 14:48 ` Steven Rostedt 1 sibling, 0 replies; 5+ messages in thread From: Steven Rostedt @ 2021-09-14 14:48 UTC (permalink / raw) To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton, Masami Hiramatsu From: Masami Hiramatsu <mhiramat@kernel.org> Free copied bootconfig data after booting kernel because that data will not be used anymore. commit 40caa127f3c7 ("init: bootconfig: Remove all bootconfig data when the init memory is removed") freed the bootconfig xbc_node array after booting kernel, but forgot to free the bootconfig data itself. This fixes that to free the bootconfig data too. This also frees the bootconfig data if the bootconfig data parsing failed. Link: https://lkml.kernel.org/r/163151166275.369741.12201304720604568345.stgit@devnote2 Fixes: 40caa127f3c7 ("init: bootconfig: Remove all bootconfig data when the init memory is removed") Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> --- init/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/init/main.c b/init/main.c index d08caed17c7f..ddbcb372225a 100644 --- a/init/main.c +++ b/init/main.c @@ -319,6 +319,8 @@ static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum) #ifdef CONFIG_BOOT_CONFIG static char xbc_namebuf[XBC_KEYLEN_MAX] __initdata; +static void *init_xbc_data_copy __initdata; +static phys_addr_t init_xbc_data_size __initdata; #define rest(dst, end) ((end) > (dst) ? (end) - (dst) : 0) @@ -458,18 +460,24 @@ static void __init setup_boot_config(void) else pr_err("Failed to parse bootconfig: %s at %d.\n", msg, pos); + memblock_free(__pa(copy), size + 1); } else { pr_info("Load bootconfig: %d bytes %d nodes\n", size, ret); /* keys starting with "kernel." are passed via cmdline */ extra_command_line = xbc_make_cmdline("kernel"); /* Also, "init." keys are init arguments */ extra_init_args = xbc_make_cmdline("init"); + init_xbc_data_copy = copy; + init_xbc_data_size = size + 1; } return; } static void __init exit_boot_config(void) { + if (!init_xbc_data_copy) + return; + memblock_free(__pa(init_xbc_data_copy), init_xbc_data_size); xbc_destroy_all(); } -- 2.32.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-09-14 16:18 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-09-14 14:48 [for-linus][PATCH 0/2] tracing: Fixes to bootconfig memory handling Steven Rostedt 2021-09-14 14:48 ` [for-linus][PATCH 1/2] bootconfig: Fix to check the xbc_node is used before free it Steven Rostedt 2021-09-14 16:11 ` Vlastimil Babka 2021-09-14 16:18 ` Steven Rostedt 2021-09-14 14:48 ` [for-linus][PATCH 2/2] bootconfig: Free copied bootconfig data after boot Steven Rostedt
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox