aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2016-04-14 13:40:35 -0400
committerAustin Clements <austin@google.com>2016-04-16 21:42:40 +0000
commit1151473077fb03df798d4eb57a22fa820f9e41f8 (patch)
tree83b999cf2abc4df95b04f0dbffe992341f7c6614 /src/runtime
parent8ce844e88ed8c16bef7febea05b003b50bd0609e (diff)
downloadgo-1151473077fb03df798d4eb57a22fa820f9e41f8.tar.xz
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/22065 Reviewed-by: Rick Hudson <rlh@golang.org> Reviewed-by: Dave Cheney <dave@cheney.net> Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/mem_linux.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/runtime/mem_linux.go b/src/runtime/mem_linux.go
index 1ee13bd7e6..61fdcee543 100644
--- a/src/runtime/mem_linux.go
+++ b/src/runtime/mem_linux.go
@@ -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)
}