Commit 11514730 authored by Austin Clements's avatar Austin Clements

runtime: check that sysUnused is always physical-page aligned

If sysUnused is passed an address or length that is not aligned to the
physical page boundary, the kernel will unmap more memory than the
caller wanted. Add a check for this.

For #9993.

Change-Id: I68ff03032e7b65cf0a853fe706ce21dc7f2aaaf8
Reviewed-on: https://go-review.googlesource.com/22065Reviewed-by: 's avatarRick Hudson <rlh@golang.org>
Reviewed-by: 's avatarDave Cheney <dave@cheney.net>
Reviewed-by: 's avatarMichael Hudson-Doyle <michael.hudson@canonical.com>
parent 8ce844e8
......@@ -132,6 +132,13 @@ func sysUnused(v unsafe.Pointer, n uintptr) {
}
}
if uintptr(v)&(sys.PhysPageSize-1) != 0 || n&(sys.PhysPageSize-1) != 0 {
// madvise will round this to any physical page
// *covered* by this range, so an unaligned madvise
// will release more memory than intended.
throw("unaligned sysUnused")
}
madvise(v, n, _MADV_DONTNEED)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment