mm: do_xip_mapping_read: fix length calculation

upstream commit: 58984ce21d

The calculation of the value nr in do_xip_mapping_read is incorrect.  If
the copy required more than one iteration in the do while loop the copies
variable will be non-zero.  The maximum length that may be passed to the
call to copy_to_user(buf+copied, xip_mem+offset, nr) is len-copied but the
check only compares against (nr > len).

This bug is the cause for the heap corruption Carsten has been chasing
for so long:
This commit is contained in:
Martin Schwidefsky 2009-04-03 04:35:12 +00:00 committed by Greg Kroah-Hartman
parent 398e94c43b
commit e655a1eaa9

View File

@ -89,8 +89,8 @@ do_xip_mapping_read(struct address_space *mapping,
}
}
nr = nr - offset;
if (nr > len)
nr = len;
if (nr > len - copied)
nr = len - copied;
error = mapping->a_ops->get_xip_mem(mapping, index, 0,
&xip_mem, &xip_pfn);