Skip to contentSkip to conversation

kexec: Fix off-by-one errors in locate_hole()

RFC PATCH Superseded Geert Uytterhoeven 2 participants 2 messages Sep 23, 2013 – Sep 25, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 kexec: Fix off-by-one errors in locate_hole()

When calling locate_hole() with "hole_size" equal to the size of an available memory block, it fails to use that memory block.

"end" and "hole_max" point to the last byte within the range, hence
- "size = end - start" is one less than "hole_size",
- "hole_base + hole_size" is one more than "hole_max".

Subtract one from "hole_size" when doing the comparison (adding 1 to "size" could overflow in case of one big range covering the whole address space).

---
Question:
The code no longer handles the case where "hole_size" is zero. Should this be rejected (like is done for a zero "hole_end" at the top of the function), or accepted?

 kexec/kexec.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kexec/kexec.c +2 -2
index 2b98ef0..eafd6c2 100644
@@ -270,7 +270,7 @@ unsigned long locate_hole(struct kexec_info *info,
 		}
 		/* Is there enough space left so we can use it? */
 		size = end - start;
-		if (size >= hole_size) {
+		if (size >= hole_size - 1) {
 			if (hole_end > 0) {
 				hole_base = start;
 				break;
@@ -286,7 +286,7 @@ unsigned long locate_hole(struct kexec_info *info,
 			"0x%lx bytes...\n", hole_size);
 		return ULONG_MAX;
 	}
-	if ((hole_base + hole_size)  > hole_max) {
+	if ((hole_base + hole_size - 1)  > hole_max) {
 		fprintf(stderr, "Could not find a free area of memory below: "
 			"0x%lx...\n", hole_max);
 		return ULONG_MAX;
Signature · 7 lines
1.7.9.5


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw
Quoted 10 lines · Geert Uytterhoeven

When calling locate_hole() with "hole_size" equal to the size of an available memory block, it fails to use that memory block.

"end" and "hole_max" point to the last byte within the range, hence
- "size = end - start" is one less than "hole_size",
- "hole_base + hole_size" is one more than "hole_max".

Subtract one from "hole_size" when doing the comparison (adding 1 to "size" could overflow in case of one big range covering the whole address space).

Quoted 6 lines

---
Question:
The code no longer handles the case where "hole_size" is zero. Should this be rejected (like is done for a zero "hole_end" at the top of the function), or accepted?

Either way would be fine by me though I lean towards accepting it.

Quoted 29 lines
 kexec/kexec.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kexec/kexec.c +2 -2
index 2b98ef0..eafd6c2 100644
@@ -270,7 +270,7 @@ unsigned long locate_hole(struct kexec_info *info,
 		}
 		/* Is there enough space left so we can use it? */
 		size = end - start;
-		if (size >= hole_size) {
+		if (size >= hole_size - 1) {
 			if (hole_end > 0) {
 				hole_base = start;
 				break;
@@ -286,7 +286,7 @@ unsigned long locate_hole(struct kexec_info *info,
 			"0x%lx bytes...\n", hole_size);
 		return ULONG_MAX;
 	}
-	if ((hole_base + hole_size)  > hole_max) {
+	if ((hole_base + hole_size - 1)  > hole_max) {
 		fprintf(stderr, "Could not find a free area of memory below: "
 			"0x%lx...\n", hole_max);
 		return ULONG_MAX;
Signature · 1 line
1.7.9.5

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