Page MenuHomeFreeBSD

kmem: Check for overflows when rounding up allocation sizes
Needs ReviewPublic

Authored by markj on Jul 24 2024, 9:31 PM.
Tags
None
Referenced Files
F100626370: D46111.id141335.diff
Thu, Oct 17, 1:48 PM
Unknown Object (File)
Tue, Oct 8, 3:32 PM
Unknown Object (File)
Sat, Oct 5, 2:05 PM
Unknown Object (File)
Sat, Oct 5, 10:53 AM
Unknown Object (File)
Wed, Oct 2, 2:42 PM
Unknown Object (File)
Wed, Oct 2, 2:18 PM
Unknown Object (File)
Tue, Oct 1, 12:06 AM
Unknown Object (File)
Mon, Sep 30, 8:02 PM
Subscribers

Details

Reviewers
dougm
Summary

In the past we've had bugs where lack of argument validation allowed a
user-controlled size to be passed to kmem_malloc() and friends.
Explicitly check before rounding up the allocation size to the page size.

This requires a bit of reorganization for kmem_alloc_san(), which wants
both the requested size and the true allocation size.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 58809
Build 55696: arc lint + arc unit

Event Timeline

markj requested review of this revision.Jul 24 2024, 9:31 PM
sys/vm/vm_kern.c
332

addr could be NULL. Add a check.

432

add addr != NULL check.

529

Add addr != NULL check.

alc added inline comments.
sys/vm/vm_kern.c
165

This rounding operation has always been redundant, since vmem_xalloc() also rounds. I would suggest moving the overflow test into vmem_xalloc().

188–191

vmem_xfree() already asserts that the rounded, passed-in size matches the boundary tag, which basically accomplishes the same.