All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] prepend elfcorehdr instead of appending it to the crash-kernel command-line.
@ 2015-05-13 10:05 KarimAllah Ahmed
  2015-05-14 14:34 ` Vivek Goyal
  0 siblings, 1 reply; 2+ messages in thread
From: KarimAllah Ahmed @ 2015-05-13 10:05 UTC (permalink / raw)
  To: kexec, x86, aliguori
  Cc: KarimAllah Ahmed, Haren Myneni, Ingo Molnar, Eric Biederman,
	H. Peter Anvin, Thomas Gleixner, Andrew Morton, Vivek Goyal

Any parameter passed after '--' in the kernel command-line will not be parsed
by the kernel at all, instead it will be passed directly to init process.

Currently the kernel appends elfcorehdr=<paddr> to the cmdline passed from kexec
load, and if this command-line is used to pass parameters to init process this
means that 'elfcorehdr' will not be parsed as a kernel parameter at all which
will be a problem for vmcore subsystem since it will know nothing about the
location of the ELF structure!

Prepending 'elfcorehdr' instead of appending it fixes this problem since it
ensures that it always comes before '--' and so it's always parsed as a kernel
command-line parameter.

Even with this patch things can still go wrong if 'CONFIG_CMDLINE' was also used
to embedd a command-line to the crash dump kernel and this command-line contains
'--' since the current behavior of the kernel is to actually append the boot
loader command-line to the embedded command-line.

Signed-off-by: KarimAllah Ahmed <karahmed@amazon.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Haren Myneni <hbabu@us.ibm.com>
Cc: Eric Biederman <ebiederm@xmission.com>
---
 arch/x86/kernel/kexec-bzimage64.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index ca05f86..ca83f7ac 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -72,15 +72,16 @@ static int setup_cmdline(struct kimage *image, struct boot_params *params,
 			 unsigned long cmdline_len)
 {
 	char *cmdline_ptr = ((char *)params) + cmdline_offset;
-	unsigned long cmdline_ptr_phys, len;
+	unsigned long cmdline_ptr_phys, len = 0;
 	uint32_t cmdline_low_32, cmdline_ext_32;
 
-	memcpy(cmdline_ptr, cmdline, cmdline_len);
 	if (image->type == KEXEC_TYPE_CRASH) {
-		len = sprintf(cmdline_ptr + cmdline_len - 1,
-			" elfcorehdr=0x%lx", image->arch.elf_load_addr);
-		cmdline_len += len;
+		len = sprintf(cmdline_ptr,
+			"elfcorehdr=0x%lx ", image->arch.elf_load_addr);
 	}
+	memcpy(cmdline_ptr + len, cmdline, cmdline_len);
+	cmdline_len += len;
+
 	cmdline_ptr[cmdline_len - 1] = '\0';
 
 	pr_debug("Final command line is: %s\n", cmdline_ptr);
-- 
1.7.9.5


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH] prepend elfcorehdr instead of appending it to the crash-kernel command-line.
  2015-05-13 10:05 [PATCH] prepend elfcorehdr instead of appending it to the crash-kernel command-line KarimAllah Ahmed
@ 2015-05-14 14:34 ` Vivek Goyal
  0 siblings, 0 replies; 2+ messages in thread
From: Vivek Goyal @ 2015-05-14 14:34 UTC (permalink / raw)
  To: KarimAllah Ahmed
  Cc: Baoquan He, x86, kexec, Haren Myneni, Ingo Molnar,
	Eric Biederman, aliguori, H. Peter Anvin, Thomas Gleixner,
	Dave Young, Andrew Morton

On Wed, May 13, 2015 at 12:05:54PM +0200, KarimAllah Ahmed wrote:
> Any parameter passed after '--' in the kernel command-line will not be parsed
> by the kernel at all, instead it will be passed directly to init process.
> 
> Currently the kernel appends elfcorehdr=<paddr> to the cmdline passed from kexec
> load, and if this command-line is used to pass parameters to init process this
> means that 'elfcorehdr' will not be parsed as a kernel parameter at all which
> will be a problem for vmcore subsystem since it will know nothing about the
> location of the ELF structure!
> 
> Prepending 'elfcorehdr' instead of appending it fixes this problem since it
> ensures that it always comes before '--' and so it's always parsed as a kernel
> command-line parameter.
> 
> Even with this patch things can still go wrong if 'CONFIG_CMDLINE' was also used
> to embedd a command-line to the crash dump kernel and this command-line contains
> '--' since the current behavior of the kernel is to actually append the boot
> loader command-line to the embedded command-line.
> 
> Signed-off-by: KarimAllah Ahmed <karahmed@amazon.de>

Looks good to me. 

We might require a similar change in kexec-tools for old systemcall?

Acked-by: Vivek Goyal <vgoyal@redhat.com>

Thanks
Vivek

> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: H. Peter Anvin <hpa@zytor.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Vivek Goyal <vgoyal@redhat.com>
> Cc: Haren Myneni <hbabu@us.ibm.com>
> Cc: Eric Biederman <ebiederm@xmission.com>
> ---
>  arch/x86/kernel/kexec-bzimage64.c |   11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
> index ca05f86..ca83f7ac 100644
> --- a/arch/x86/kernel/kexec-bzimage64.c
> +++ b/arch/x86/kernel/kexec-bzimage64.c
> @@ -72,15 +72,16 @@ static int setup_cmdline(struct kimage *image, struct boot_params *params,
>  			 unsigned long cmdline_len)
>  {
>  	char *cmdline_ptr = ((char *)params) + cmdline_offset;
> -	unsigned long cmdline_ptr_phys, len;
> +	unsigned long cmdline_ptr_phys, len = 0;
>  	uint32_t cmdline_low_32, cmdline_ext_32;
>  
> -	memcpy(cmdline_ptr, cmdline, cmdline_len);
>  	if (image->type == KEXEC_TYPE_CRASH) {
> -		len = sprintf(cmdline_ptr + cmdline_len - 1,
> -			" elfcorehdr=0x%lx", image->arch.elf_load_addr);
> -		cmdline_len += len;
> +		len = sprintf(cmdline_ptr,
> +			"elfcorehdr=0x%lx ", image->arch.elf_load_addr);
>  	}
> +	memcpy(cmdline_ptr + len, cmdline, cmdline_len);
> +	cmdline_len += len;
> +
>  	cmdline_ptr[cmdline_len - 1] = '\0';
>  
>  	pr_debug("Final command line is: %s\n", cmdline_ptr);
> -- 
> 1.7.9.5

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

end of thread, other threads:[~2015-05-14 14:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-13 10:05 [PATCH] prepend elfcorehdr instead of appending it to the crash-kernel command-line KarimAllah Ahmed
2015-05-14 14:34 ` Vivek Goyal

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.