Page MenuHomeFreeBSD

Add a helper function for validating VA ranges.
ClosedPublic

Authored by markj on Jun 17 2020, 6:30 PM.
Tags
None
Referenced Files
Unknown Object (File)
Nov 21 2024, 10:31 AM
Unknown Object (File)
Oct 19 2024, 2:01 PM
Unknown Object (File)
Oct 8 2024, 5:49 AM
Unknown Object (File)
Sep 11 2024, 6:30 PM
Unknown Object (File)
Sep 10 2024, 8:23 PM
Unknown Object (File)
Sep 8 2024, 9:49 PM
Unknown Object (File)
Sep 8 2024, 10:46 AM
Unknown Object (File)
Sep 8 2024, 7:41 AM
Subscribers

Details

Summary

Functions which take untrusted user ranges must validate against the
bounds of the map, and also check for wraparound. Instead of having the
same logic duplicated in a number of places, add a function to check.

This somewhat duplicates the VM_MAP_RANGE_CHECK macro, which does not in
fact do any checking but rather clips the range based on the map bounds.
Some functions (like kern_mprotect()) rely on this, while others
(kern_madvise()) do not. As a future step I think we should add such
checking to all syscall paths, and convert VM_MAP_RANGE_CHECK to
assert the validity of the range.

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 31812
Build 29372: arc lint + arc unit

Event Timeline

markj requested review of this revision.Jun 17 2020, 6:30 PM
markj created this revision.
sys/vm/vm_map.h
262

At least the code in vm_map.c does <= check there.

I think it visibly changes the user error code.

sys/vm/vm_map.h
262

That case is weird. Note it checks addr + length <= length, not <= addr. So it is just checking for overflow, not for length == 0. I'm not sure if it is intended or not.

This revision is now accepted and ready to land.Jun 18 2020, 5:12 PM
sys/vm/vm_map.c
1619

Why is this test different from the others?

sys/vm/vm_map.c
1619

I just missed it.

See also vm_fault_quick_hold_pages in vm_fault.c.

This revision now requires review to proceed.Jun 18 2020, 9:40 PM

See also vm_fault_quick_hold_pages in vm_fault.c.

Thanks. I also converted a similar check in the LinuxKPI.

This revision is now accepted and ready to land.Jun 18 2020, 10:05 PM
dougm added inline comments.
sys/vm/vm_map.h
260

vm_map_valid_range sounds more boolean. A non-blocking suggestion.

sys/vm/vm_map.h
260

I think that sounds better. vm_map_range_valid() seems a bit more natural to me, so I will go with that.

This revision was automatically updated to reflect the committed changes.
head/sys/compat/linuxkpi/common/src/linux_page.c
222 ↗(On Diff #73311)

This assignment is pointless. See below.