Skip to content

Commit c25ef62

Browse files
tiwaigregkh
authored andcommitted
resource: fix integer overflow at reallocation
commit 60bb83b upstream. We've got a bug report indicating a kernel panic at booting on an x86-32 system, and it turned out to be the invalid PCI resource assigned after reallocation. __find_resource() first aligns the resource start address and resets the end address with start+size-1 accordingly, then checks whether it's contained. Here the end address may overflow the integer, although resource_contains() still returns true because the function validates only start and end address. So this ends up with returning an invalid resource (start > end). There was already an attempt to cover such a problem in the commit 47ea91b ("Resource: fix wrong resource window calculation"), but this case is an overseen one. This patch adds the validity check of the newly calculated resource for avoiding the integer overflow problem. Bugzilla: http://bugzilla.opensuse.org/show_bug.cgi?id=1086739 Link: http://lkml.kernel.org/r/[email protected] Fixes: 23c570a ("resource: ability to resize an allocated resource") Signed-off-by: Takashi Iwai <[email protected]> Reported-by: Michael Henders <[email protected]> Tested-by: Michael Henders <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Cc: Ram Pai <[email protected]> Cc: Bjorn Helgaas <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f659e7e commit c25ef62

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/resource.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,8 @@ static int __find_resource(struct resource *root, struct resource *old,
633633
alloc.start = constraint->alignf(constraint->alignf_data, &avail,
634634
size, constraint->align);
635635
alloc.end = alloc.start + size - 1;
636-
if (resource_contains(&avail, &alloc)) {
636+
if (alloc.start <= alloc.end &&
637+
resource_contains(&avail, &alloc)) {
637638
new->start = alloc.start;
638639
new->end = alloc.end;
639640
return 0;

0 commit comments

Comments
 (0)