Blame SOURCES/kexec-tools-2.0.15-ppc64-fix-command-line-overflow-error.patch

1d9674
From 21eb397a5fc9227cd95d23e8c74a49cf6a293e57 Mon Sep 17 00:00:00 2001
1d9674
From: Hari Bathini <hbathini@linux.vnet.ibm.com>
1d9674
Date: Wed, 9 Aug 2017 23:47:42 +0530
1d9674
Subject: [PATCH] kexec-tools: powerpc: fix command line overflow error
1d9674
1d9674
Since kernel commit a5980d064fe2 ("powerpc: Bump COMMAND_LINE_SIZE
1d9674
to 2048"), powerpc bumped command line size to 2048 but the size
1d9674
used here is still the default value of 512. Bump it to 2048 to
1d9674
fix command line overflow errors observed when command line length
1d9674
is above 512 bytes. Also, get rid of the multiple definitions of
1d9674
COMMAND_LINE_SIZE macro in ppc architecture.
1d9674
1d9674
Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com>
1d9674
Signed-off-by: Simon Horman <horms@verge.net.au>
1d9674
Signed-off-by: Pingfan Liu <piliu@redhat.com>
1d9674
---
1d9674
 kexec/arch/ppc/crashdump-powerpc.c | 6 +++++-
1d9674
 kexec/arch/ppc/crashdump-powerpc.h | 2 --
1d9674
 kexec/arch/ppc/fs2dt.c             | 1 -
1d9674
 kexec/arch/ppc/kexec-ppc.h         | 3 ++-
1d9674
 kexec/arch/ppc/ops.h               | 1 -
1d9674
 kexec/arch/ppc64/crashdump-ppc64.c | 6 ++++--
1d9674
 kexec/arch/ppc64/crashdump-ppc64.h | 2 +-
1d9674
 7 files changed, 12 insertions(+), 9 deletions(-)
1d9674
1d9674
diff --git a/kexec/arch/ppc/crashdump-powerpc.c b/kexec/arch/ppc/crashdump-powerpc.c
1d9674
index dde6de7..4ad026f 100644
1d9674
--- a/kexec/arch/ppc/crashdump-powerpc.c
1d9674
+++ b/kexec/arch/ppc/crashdump-powerpc.c
1d9674
@@ -252,8 +252,12 @@ static void ulltoa(unsigned long long i, char *str)
1d9674
 /* Append str to cmdline */
1d9674
 static void add_cmdline(char *cmdline, char *str)
1d9674
 {
1d9674
+	int cmdline_size;
1d9674
 	int cmdlen = strlen(cmdline) + strlen(str);
1d9674
-	if (cmdlen > (COMMAND_LINE_SIZE - 1))
1d9674
+
1d9674
+	cmdline_size = (kernel_version() < KERNEL_VERSION(3, 10, 0) ?
1d9674
+			512 : COMMAND_LINE_SIZE);
1d9674
+	if (cmdlen > (cmdline_size - 1))
1d9674
 		die("Command line overflow\n");
1d9674
 	strcat(cmdline, str);
1d9674
 }
1d9674
diff --git a/kexec/arch/ppc/crashdump-powerpc.h b/kexec/arch/ppc/crashdump-powerpc.h
1d9674
index 9b9b01e..97b5095 100644
1d9674
--- a/kexec/arch/ppc/crashdump-powerpc.h
1d9674
+++ b/kexec/arch/ppc/crashdump-powerpc.h
1d9674
@@ -20,8 +20,6 @@ extern struct arch_options_t arch_options;
1d9674
 #define KERNELBASE	PAGE_OFFSET
1d9674
 #define __pa(x)		((unsigned long)(x)-PAGE_OFFSET)
1d9674
 
1d9674
-#define COMMAND_LINE_SIZE	512 /* from kernel */
1d9674
-
1d9674
 #ifdef CONFIG_BOOKE
1d9674
 /* We don't need backup region in Book E */
1d9674
 #define BACKUP_SRC_START	0x0000
1d9674
diff --git a/kexec/arch/ppc/fs2dt.c b/kexec/arch/ppc/fs2dt.c
1d9674
index 6e77379..fed499b 100644
1d9674
--- a/kexec/arch/ppc/fs2dt.c
1d9674
+++ b/kexec/arch/ppc/fs2dt.c
1d9674
@@ -37,7 +37,6 @@
1d9674
 #define TREEWORDS		65536	/* max 32 bit words for properties */
1d9674
 #define MEMRESERVE		256	/* max number of reserved memory blks */
1d9674
 #define MAX_MEMORY_RANGES	1024
1d9674
-#define COMMAND_LINE_SIZE	512	/* from kernel */
1d9674
 
1d9674
 static char pathname[MAXPATH];
1d9674
 static char propnames[NAMESPACE] = { 0 };
1d9674
diff --git a/kexec/arch/ppc/kexec-ppc.h b/kexec/arch/ppc/kexec-ppc.h
1d9674
index f8fd678..04e728e 100644
1d9674
--- a/kexec/arch/ppc/kexec-ppc.h
1d9674
+++ b/kexec/arch/ppc/kexec-ppc.h
1d9674
@@ -6,6 +6,8 @@
1d9674
 #define CORE_TYPE_ELF32	1
1d9674
 #define CORE_TYPE_ELF64	2
1d9674
 
1d9674
+#define COMMAND_LINE_SIZE	2048 /* from kernel */
1d9674
+
1d9674
 extern unsigned char setup_simple_start[];
1d9674
 extern uint32_t setup_simple_size;
1d9674
 
1d9674
@@ -76,7 +78,6 @@ extern int init_memory_region_info(void);
1d9674
 extern int read_memory_region_limits(int fd, unsigned long long *start,
1d9674
 					unsigned long long *end);
1d9674
 extern int get_devtree_value(const char *fname, unsigned long long *pvalue);
1d9674
-#define COMMAND_LINE_SIZE	512 /* from kernel */
1d9674
 /*fs2dt*/
1d9674
 void reserve(unsigned long long where, unsigned long long length);
1d9674
 
1d9674
diff --git a/kexec/arch/ppc/ops.h b/kexec/arch/ppc/ops.h
1d9674
index 7334a05..5e7a070 100644
1d9674
--- a/kexec/arch/ppc/ops.h
1d9674
+++ b/kexec/arch/ppc/ops.h
1d9674
@@ -12,7 +12,6 @@
1d9674
 #define _PPC_BOOT_OPS_H_
1d9674
 #include "types.h"
1d9674
 
1d9674
-#define	COMMAND_LINE_SIZE	512
1d9674
 #define	MAX_PATH_LEN		256
1d9674
 #define	MAX_PROP_LEN		256 /* What should this be? */
1d9674
 
1d9674
diff --git a/kexec/arch/ppc64/crashdump-ppc64.c b/kexec/arch/ppc64/crashdump-ppc64.c
1d9674
index 5a71d51..13995bf 100644
1d9674
--- a/kexec/arch/ppc64/crashdump-ppc64.c
1d9674
+++ b/kexec/arch/ppc64/crashdump-ppc64.c
1d9674
@@ -381,7 +381,7 @@ static void ultoa(uint64_t i, char *str)
1d9674
 static int add_cmdline_param(char *cmdline, uint64_t addr, char *cmdstr,
1d9674
 				char *byte)
1d9674
 {
1d9674
-	int cmdlen, len, align = 1024;
1d9674
+	int cmdline_size, cmdlen, len, align = 1024;
1d9674
 	char str[COMMAND_LINE_SIZE], *ptr;
1d9674
 
1d9674
 	/* Passing in =xxxK / =xxxM format. Saves space required in cmdline.*/
1d9674
@@ -402,7 +402,9 @@ static int add_cmdline_param(char *cmdline, uint64_t addr, char *cmdstr,
1d9674
 	strcat(str, byte);
1d9674
 	len = strlen(str);
1d9674
 	cmdlen = strlen(cmdline) + len;
1d9674
-	if (cmdlen > (COMMAND_LINE_SIZE - 1))
1d9674
+	cmdline_size = (kernel_version() < KERNEL_VERSION(3, 10, 0) ?
1d9674
+			512 : COMMAND_LINE_SIZE);
1d9674
+	if (cmdlen > (cmdline_size - 1))
1d9674
 		die("Command line overflow\n");
1d9674
 	strcat(cmdline, str);
1d9674
 	dbgprintf("Command line after adding elfcorehdr: %s\n", cmdline);
1d9674
diff --git a/kexec/arch/ppc64/crashdump-ppc64.h b/kexec/arch/ppc64/crashdump-ppc64.h
1d9674
index d654c6b..42ccc31 100644
1d9674
--- a/kexec/arch/ppc64/crashdump-ppc64.h
1d9674
+++ b/kexec/arch/ppc64/crashdump-ppc64.h
1d9674
@@ -16,7 +16,7 @@ void add_usable_mem_rgns(unsigned long long base, unsigned long long size);
1d9674
 #define __pa(x)         ((unsigned long)(x)-PAGE_OFFSET)
1d9674
 #define MAXMEM          (-KERNELBASE-VMALLOCBASE)
1d9674
 
1d9674
-#define COMMAND_LINE_SIZE       512 /* from kernel */
1d9674
+#define COMMAND_LINE_SIZE       2048 /* from kernel */
1d9674
 /* Backup Region, First 64K of System RAM. */
1d9674
 #define BACKUP_SRC_START    0x0000
1d9674
 #define BACKUP_SRC_END      0xffff
1d9674
-- 
1d9674
2.7.4
1d9674