Skip to contentSkip to conversation

Fix memory access errors for kexec PPC

PATCH In review Suzuki Poulose 2 participants 4 messages Apr 20, 2011 – Apr 27, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix memory access errors for kexec PPC

Hi,

I was trying the kexec for ppc32 and came across a couple of memory errors while running with glibc.

The attached patch is the outcome of the glibc's alerts !
We define buf[MAXBYTES-1] and issue fread(buf, 1, MAXBYTES, file), which glibc reports an error.

Also there is a typo in the realloc_memory_ranges() code for ppc which causes in a double free().

Kindly apply.

Thanks
Suzuki

---

kexec/arch/ppc/crashdump-powerpc.c +1 -1
index 7bfad20..7853dbe 100644
@@ -83,7 +83,7 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
 	int memory_ranges = 0;
 	char device_tree[256] = "/proc/device-tree/";
 	char fname[256];
-	char buf[MAXBYTES-1];
+	char buf[MAXBYTES];
 	DIR *dir, *dmem;
 	FILE *file;
 	struct dirent *dentry, *mentry;
kexec/arch/ppc/kexec-ppc.c +2 -2
index ab76d6f..837021f 100644
@@ -196,7 +196,7 @@ static int realloc_memory_ranges(void)
 	if (!memory_range)
 		goto err;
 
-	base_memory_range = (struct memory_range *) realloc(memory_range,
+	base_memory_range = (struct memory_range *) realloc(base_memory_range,
 			memory_range_len);
 	if (!base_memory_range)
 		goto err;
@@ -319,7 +319,7 @@ static int get_devtree_details(unsigned long kexec_flags)
 	unsigned long long htab_base, htab_size;
 	unsigned long long kernel_end;
 	unsigned long long initrd_start, initrd_end;
-	char buf[MAXBYTES-1];
+	char buf[MAXBYTES];
 	char device_tree[256] = "/proc/device-tree/";
 	char fname[256];
 	DIR *dir, *cdir;

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#1 lore raw
Quoted 11 lines · Suzuki Poulose

Hi,

I was trying the kexec for ppc32 and came across a couple of memory errors while running with glibc.

The attached patch is the outcome of the glibc's alerts !
We define buf[MAXBYTES-1] and issue fread(buf, 1, MAXBYTES, file), which glibc reports an error.

Also there is a typo in the realloc_memory_ranges() code for ppc which causes in a double free().

Thanks,

could you please make this a formal submission by
supplying a Signed-off-by line?

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw
Quoted 10 lines · Simon Horman
Quoted 9 lines · Suzuki Poulose

Hi,

I was trying the kexec for ppc32 and came across a couple of memory errors while running with glibc.

The attached patch is the outcome of the glibc's alerts !
We define buf[MAXBYTES-1] and issue fread(buf, 1, MAXBYTES, file), which glibc reports an error.

Quoted 7 lines
Quoted 2 lines

Also there is a typo in the realloc_memory_ranges() code for ppc which causes in a double free().

Thanks,

could you please make this a formal submission by
supplying a Signed-off-by line?

I have updated the patch to use realloc instead of malloc() for memory_range.
---

Fix memory access errors for ppc

The patch fixes memory overflow errors and improper reallocation of memory ranges.

kexec/arch/ppc/crashdump-powerpc.c +1 -1
index 7bfad20..7853dbe 100644
@@ -83,7 +83,7 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
 	int memory_ranges = 0;
 	char device_tree[256] = "/proc/device-tree/";
 	char fname[256];
-	char buf[MAXBYTES-1];
+	char buf[MAXBYTES];
 	DIR *dir, *dmem;
 	FILE *file;
 	struct dirent *dentry, *mentry;
kexec/arch/ppc/kexec-ppc.c +4 -3
index ab76d6f..96fbc12 100644
@@ -192,11 +192,12 @@ static int realloc_memory_ranges(void)
 	max_memory_ranges++;
 	memory_range_len = sizeof(struct memory_range) * max_memory_ranges;
 
-	memory_range = (struct memory_range *) malloc(memory_range_len);
+	memory_range = (struct memory_range *) realloc(memory_range,
+							memory_range_len);
 	if (!memory_range)
 		goto err;
 
-	base_memory_range = (struct memory_range *) realloc(memory_range,
+	base_memory_range = (struct memory_range *) realloc(base_memory_range,
 			memory_range_len);
 	if (!base_memory_range)
 		goto err;
@@ -319,7 +320,7 @@ static int get_devtree_details(unsigned long kexec_flags)
 	unsigned long long htab_base, htab_size;
 	unsigned long long kernel_end;
 	unsigned long long initrd_start, initrd_end;
-	char buf[MAXBYTES-1];
+	char buf[MAXBYTES];
 	char device_tree[256] = "/proc/device-tree/";
 	char fname[256];
 	DIR *dir, *cdir;

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#3 lore raw
Quoted 11 lines · Suzuki Poulose
Quoted 10 lines · Simon Horman
Quoted 9 lines · Suzuki Poulose

Hi,

I was trying the kexec for ppc32 and came across a couple of memory errors while running with glibc.

The attached patch is the outcome of the glibc's alerts !
We define buf[MAXBYTES-1] and issue fread(buf, 1, MAXBYTES, file), which glibc reports an error.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

Also there is a typo in the realloc_memory_ranges() code for ppc which causes in a double free().

Thanks,

could you please make this a formal submission by
supplying a Signed-off-by line?

I have updated the patch to use realloc instead of malloc() for memory_range.

Hi,

unfortuantely this doesn't seep to apply to the current git tree. Could you fix that?

The tree is available at
git://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec