[PATCH]: Simple bounds checking for crashkernel args (version 2)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Better error message suggested by Vivek...


Add some simple bounds checking for crashkernel args in i386 & x86_64.

Signed-off-by: Prarit Bhargava <prarit at redhat.com>

diff -urNp linux-2.6.19.2.orig/arch/i386/kernel/machine_kexec.c linux-2.6.19.2/arch/i386/kernel/machine_kexec.c
--- linux-2.6.19.2.orig/arch/i386/kernel/machine_kexec.c	2007-01-15 11:13:43.000000000 -0500
+++ linux-2.6.19.2/arch/i386/kernel/machine_kexec.c	2007-01-15 11:17:09.000000000 -0500
@@ -160,9 +160,6 @@ static int __init parse_crashkernel(char
 	size = memparse(arg, &arg);
 	if (*arg == '@') {
 		base = memparse(arg+1, &arg);
-		/* FIXME: Do I want a sanity check
-		 * to validate the memory range?
-		 */
 		crashk_res.start = base;
 		crashk_res.end   = base + size - 1;
 	}
diff -urNp linux-2.6.19.2.orig/arch/i386/kernel/setup.c linux-2.6.19.2/arch/i386/kernel/setup.c
--- linux-2.6.19.2.orig/arch/i386/kernel/setup.c	2007-01-15 11:13:43.000000000 -0500
+++ linux-2.6.19.2/arch/i386/kernel/setup.c	2007-01-15 11:19:18.000000000 -0500
@@ -1176,9 +1176,20 @@ void __init setup_bootmem_allocator(void
 	}
 #endif
 #ifdef CONFIG_KEXEC
-	if (crashk_res.start != crashk_res.end)
+	if ((crashk_res.start < crashk_res.end) &&
+	    (crashk_res.end <= (max_low_pfn << PAGE_SHIFT))) {
 		reserve_bootmem(crashk_res.start,
-			crashk_res.end - crashk_res.start + 1);
+				crashk_res.end - crashk_res.start + 1);
+	}
+	else {
+		printk(KERN_ERR "Memory for crash kernel (0x%lx to 0x%lx) not"
+		       "within permissible range\ndisabling kdump\n",
+		       crashk_res.start, crashk_res.end);
+		crashk_res.end = 0;
+		crashk_res.start = 0;
+	}
+#endif
+
 #endif
 }
 
diff -urNp linux-2.6.19.2.orig/arch/x86_64/kernel/machine_kexec.c linux-2.6.19.2/arch/x86_64/kernel/machine_kexec.c
--- linux-2.6.19.2.orig/arch/x86_64/kernel/machine_kexec.c	2007-01-15 11:13:29.000000000 -0500
+++ linux-2.6.19.2/arch/x86_64/kernel/machine_kexec.c	2007-01-15 11:17:09.000000000 -0500
@@ -247,9 +247,6 @@ static int __init setup_crashkernel(char
 		return -EINVAL;
 	if (*p == '@') {
 		base = memparse(p+1, &p);
-		/* FIXME: Do I want a sanity check to validate the
-		 * memory range?  Yes you do, but it's too early for
-		 * e820 -AK */
 		crashk_res.start = base;
 		crashk_res.end   = base + size - 1;
 	}
diff -urNp linux-2.6.19.2.orig/arch/x86_64/kernel/setup.c linux-2.6.19.2/arch/x86_64/kernel/setup.c
--- linux-2.6.19.2.orig/arch/x86_64/kernel/setup.c	2007-01-15 11:13:29.000000000 -0500
+++ linux-2.6.19.2/arch/x86_64/kernel/setup.c	2007-01-15 11:19:40.000000000 -0500
@@ -485,9 +485,18 @@ void __init setup_arch(char **cmdline_p)
 	}
 #endif
 #ifdef CONFIG_KEXEC
-	if (crashk_res.start != crashk_res.end) {
+	/* FIXME: still too early for e820 range fix but better than nothing */
+	if ((crashk_res.start < crashk_res.end) &&
+	    (crashk_res.end <= (max_low_pfn << PAGE_SHIFT))) {
 		reserve_bootmem_generic(crashk_res.start,
-			crashk_res.end - crashk_res.start + 1);
+					crashk_res.end - crashk_res.start + 1);
+	}
+	else {
+		printk(KERN_ERR "Memory for crash kernel (0x%lx to 0x%lx) not"
+		       "within permissible range\ndisabling kdump\n",
+		       crashk_res.start, crashk_res.end);
+		crashk_res.end = 0;
+		crashk_res.start = 0;
 	}
 #endif
 


[Netdev]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Photo]     [Yosemite]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Linux Media]     [Linux Resources]

Powered by Linux