Skip to contentSkip to conversation

vmlinux parameter segment stomping fix

PATCH In review Vivek Goyal 2 participants 2 messages Mar 28, 2005 – Jul 18, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/17 vmlinux parameter segment stomping fix

During loading of panic kernel(vmlinux), it was found that on some systems, parameter segment was being stomped over by kernel. This was resulting in corruption of e820 memory map and leading to boot memory allocator initialization failures while booting into new kernel. This patch fixes the problem by loading the parameter segment beyond alrady loaded kernel image and setup code. A 64K buffer has been provided to avoid any stomping by kernel.

---

 kexec-tools-1.101-root/kexec/arch/i386/kexec-elf-x86.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
kexec/arch/i386/kexec-elf-x86.c renamed from kexec/arch/i386/kexec-elf-x86.c~kexec-tools-vmlinux-parameter-segment-stomping-fix +14 -2
diff -puN kexec/arch/i386/kexec-elf-x86.c~kexec-tools-vmlinux-parameter-segment-stomping-fix kexec/arch/i386/kexec-elf-x86.c
@@ -199,15 +199,27 @@ int elf_x86_load(int argc, char **argv, 
 	}
 	else if (arg_style == ARG_STYLE_LINUX) {
 		struct x86_linux_faked_param_header *hdr;
-		unsigned long param_base;
+		unsigned long param_base, min_param_base = 0;
 		const unsigned char *ramdisk_buf;
 		off_t ramdisk_length;
 		struct entry32_regs regs;
+		int i;
 
 		/* Get the linux parameter header */
 		hdr = xmalloc(sizeof(*hdr));
+		/* Add parameter segment beyond already loaded segments, so that
+		 * it does not get stomped by kernel. */
+		for (i = 0; i < info->nr_segments; i++) {
+			unsigned long temp;
+			temp = (unsigned long) info->segment[i].mem +
+				info->segment[i].memsz;
+			if (temp > min_param_base)
+				min_param_base =  temp;
+		}
+		/* 64K of buffer to keep enough distance from kernel. */
+		min_param_base += 64*1024;
 		param_base = add_buffer(info, hdr, sizeof(*hdr), sizeof(*hdr),
-			16, 0, max_addr, 1);
+			16, min_param_base, max_addr, 1);
 
 		/* Initialize the parameter header */
 		memset(hdr, 0, sizeof(*hdr));

_

#1 lore raw

My apologies for taking so long to look at these patches.

I agree there is an issue here, but large parts of this
we need to address kernel side. If the parameter buffer is allocated after the kernel there is no guarantee that it will be addressable from the kernels early page table so this fix will not work. As for the practical problem it addresses it looks like we simply need to increase the size of the kernel's bss segment so we don't stop things.

Problem agreed upon patch rejected.

Eric

Quoted 53 lines · Vivek Goyal

During loading of panic kernel(vmlinux), it was found that on some systems, parameter segment was being stomped over by kernel. This was resulting in corruption of e820 memory map and leading to boot memory allocator initialization failures while booting into new kernel. This patch fixes the problem by loading the parameter segment beyond alrady loaded kernel image and setup code. A 64K buffer has been provided to avoid any stomping by kernel.

---

 kexec-tools-1.101-root/kexec/arch/i386/kexec-elf-x86.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff -puN kexec/arch/i386/kexec-elf-x86.c~kexec-tools-vmlinux-parameter-segment-stomping-fix kexec/arch/i386/kexec-elf-x86.c

kexec/arch/i386/kexec-elf-x86.c renamed from kexec/arch/i386/kexec-elf-x86.c~kexec-tools-vmlinux-parameter-segment-stomping-fix +14 -2
@@ -199,15 +199,27 @@ int elf_x86_load(int argc, char **argv, 
 	}
 	else if (arg_style == ARG_STYLE_LINUX) {
 		struct x86_linux_faked_param_header *hdr;
-		unsigned long param_base;
+		unsigned long param_base, min_param_base = 0;
 		const unsigned char *ramdisk_buf;
 		off_t ramdisk_length;
 		struct entry32_regs regs;
+		int i;
 
 		/* Get the linux parameter header */
 		hdr = xmalloc(sizeof(*hdr));
+		/* Add parameter segment beyond already loaded segments, so that
+		 * it does not get stomped by kernel. */
+		for (i = 0; i < info->nr_segments; i++) {
+			unsigned long temp;
+			temp = (unsigned long) info->segment[i].mem +
+				info->segment[i].memsz;
+			if (temp > min_param_base)
+				min_param_base =  temp;
+		}
+		/* 64K of buffer to keep enough distance from kernel. */
+		min_param_base += 64*1024;
 		param_base = add_buffer(info, hdr, sizeof(*hdr), sizeof(*hdr),
-			16, 0, max_addr, 1);
+			16, min_param_base, max_addr, 1);
 
 		/* Initialize the parameter header */
 		memset(hdr, 0, sizeof(*hdr));

_
_______________________________________________
fastboot mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/fastboot