public inbox for kexec@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v2] kexec: Fix off-by-one errors in locate_hole()
@ 2013-10-02  8:42 Geert Uytterhoeven
  2013-10-03  1:15 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: Geert Uytterhoeven @ 2013-10-02  8:42 UTC (permalink / raw)
  To: Simon Horman; +Cc: Geert Uytterhoeven, kexec

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).
But explicitly check if "hole_size" is zero first, to handle this case
without causing underflows.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
v2: Accept hole_size == zero.

 kexec/kexec.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kexec/kexec.c b/kexec/kexec.c
index 2b98ef055a15..185c85bef342 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -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 (!hole_size || 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_size && (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;
-- 
1.7.9.5


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] kexec: Fix off-by-one errors in locate_hole()
  2013-10-02  8:42 [PATCH v2] kexec: Fix off-by-one errors in locate_hole() Geert Uytterhoeven
@ 2013-10-03  1:15 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2013-10-03  1:15 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: kexec

On Wed, Oct 02, 2013 at 10:42:27AM +0200, Geert Uytterhoeven wrote:
> 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).
> But explicitly check if "hole_size" is zero first, to handle this case
> without causing underflows.
> 
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

Thanks, applied.

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-10-03  1:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-02  8:42 [PATCH v2] kexec: Fix off-by-one errors in locate_hole() Geert Uytterhoeven
2013-10-03  1:15 ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox