]> git.hungrycats.org Git - linux/commitdiff
[PATCH] resource.c bounds checking fix
authorAndrew Morton <akpm@osdl.org>
Tue, 18 Nov 2003 16:16:42 +0000 (08:16 -0800)
committerLinus Torvalds <torvalds@home.osdl.org>
Tue, 18 Nov 2003 16:16:42 +0000 (08:16 -0800)
From: Jeremy Higdon <jeremy@classic.engr.sgi.com>

I believe there is a bug in kernel/resource.c.

We (SGI sn2 I/O code) are using this for allocating dma map resources, and
we tracked failures we were seeing to find_resource().

The problem is that when testing bounds in the forever loop, the end bound
would be one higher than it should be if it gets set from another resource
(it's set to the proper value when it gets set from the root), causing
find_resource to return an invalid min/max when the requested size was one
greater than would fit between two existing resources.

kernel/resource.c

index 58413f46cdf5fa07b5feb0002a818192bbec5de8..e2048de77ae3a274583dcea5d9110d06e87fd4f5 100644 (file)
@@ -244,9 +244,17 @@ static int find_resource(struct resource *root, struct resource *new,
        struct resource *this = root->child;
 
        new->start = root->start;
+       /*
+        * Skip past an allocated resource that starts at 0, since the assignment
+        * of this->start - 1 to new->end below would cause an underflow.
+        */
+       if (this && this->start == 0) {
+               new->start = this->end + 1;
+               this = this->sibling;
+       }
        for(;;) {
                if (this)
-                       new->end = this->start;
+                       new->end = this->start - 1;
                else
                        new->end = root->end;
                if (new->start < min)