Page MenuHomeFreeBSD

Avoid overflow in checking the size of free gaps in vm_map_findspace

Authored by dougm on Jun 10 2019, 9:53 PM.



To test to see if a free space is big enough compare the required length to the difference of the two offsets that define the gap, to avoid overflow, rather that adding the length to an offset and comparing that to another offset.

This addresses an overflow issue reported by Peter Holm on i386.

Diff Detail

rS FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

dougm created this revision.Jun 10 2019, 9:53 PM
kib added a comment.Jun 11 2019, 10:46 AM

Is this a fix for the i386 wrap issue, or just a related change ?

1802 ↗(On Diff #58495)

(void *) space before star.

Since you are changing format, note that the length is truncated. Perhaps use %ju (I would prefer %jx) and cast to uintmax_t for length.

dougm updated this revision to Diff 58518.Jun 11 2019, 12:01 PM
dougm edited the summary of this revision. (Show Details)

Change formatting in error log, as suggested.

kib accepted this revision.Jun 11 2019, 2:52 PM
kib added inline comments.
1801 ↗(On Diff #58518)

I suggest %#jx

This revision is now accepted and ready to land.Jun 11 2019, 2:52 PM
pho added a comment.Jun 11 2019, 9:00 PM

I tested this patch on i386 with all of the mmap() tests I have. I also ran the same tests on amd64 plus a buildworld.
I can run a full test if you prefer that.

This revision was automatically updated to reflect the committed changes.