[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20101026214128.29808.77226.stgit@bob.kio>
Date: Tue, 26 Oct 2010 15:41:28 -0600
From: Bjorn Helgaas <bjorn.helgaas@...com>
To: Jesse Barnes <jbarnes@...tuousgeek.org>
Cc: Bob Picco <bpicco@...hat.com>,
Brian Bloniarz <phunge0@...mail.com>,
Charles Butterfield <charles.butterfield@...tcentury.com>,
Denys Vlasenko <dvlasenk@...hat.com>,
Ingo Molnar <mingo@...e.hu>, linux-pci@...r.kernel.org,
"Horst H. von Brand" <vonbrand@....utfsm.cl>,
"H. Peter Anvin" <hpa@...or.com>, linux-kernel@...r.kernel.org,
Stefan Becker <chemobejk@...il.com>,
Chuck Ebbert <cebbert@...hat.com>,
Fabrice Bellet <fabrice@...let.info>,
Yinghai Lu <yinghai@...nel.org>,
Leann Ogasawara <leann.ogasawara@...onical.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Thomas Gleixner <tglx@...utronix.de>
Subject: [PATCH v5 4/9] resources: handle overflow when aligning start of
available area
If tmp.start is near ~0, ALIGN(tmp.start) may overflow, which would
make us think there's more available space than there really is. We
would likely return something that conflicts with a previous resource,
which would cause a failure when allocate_resource() requests the newly-
allocated region.
Reference: https://bugzilla.redhat.com/show_bug.cgi?id=646027
Reported-by: Fabrice Bellet <fabrice@...let.info>
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@...com>
---
kernel/resource.c | 21 +++++++++++++--------
1 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/kernel/resource.c b/kernel/resource.c
index 89d5041..e15b922 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -392,7 +392,7 @@ static int find_resource(struct resource *root, struct resource *new,
void *alignf_data)
{
struct resource *this = root->child;
- struct resource tmp = *new, alloc;
+ struct resource tmp = *new, avail, alloc;
tmp.start = root->start;
/*
@@ -410,14 +410,19 @@ static int find_resource(struct resource *root, struct resource *new,
tmp.end = root->end;
resource_clip(&tmp, min, max);
- tmp.start = ALIGN(tmp.start, align);
- alloc.start = alignf(alignf_data, &tmp, size, align);
- alloc.end = alloc.start + size - 1;
- if (resource_contains(&tmp, &alloc)) {
- new->start = alloc.start;
- new->end = alloc.end;
- return 0;
+ /* Check for overflow after ALIGN() */
+ avail = *new;
+ avail.start = ALIGN(tmp.start, align);
+ avail.end = tmp.end;
+ if (avail.start >= tmp.start) {
+ alloc.start = alignf(alignf_data, &avail, size, align);
+ alloc.end = alloc.start + size - 1;
+ if (resource_contains(&avail, &alloc)) {
+ new->start = alloc.start;
+ new->end = alloc.end;
+ return 0;
+ }
}
if (!this)
break;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists