diff options
| author | Austin Clements <austin@google.com> | 2016-04-14 13:27:36 -0400 |
|---|---|---|
| committer | Austin Clements <austin@google.com> | 2016-04-16 21:42:37 +0000 |
| commit | 8ce844e88ed8c16bef7febea05b003b50bd0609e (patch) | |
| tree | 4c07e0d006d2a8e2805ac37596710b2235bea156 /src/runtime | |
| parent | d6b177d1eb7849375e246b97c58406aed7350c86 (diff) | |
| download | go-8ce844e88ed8c16bef7febea05b003b50bd0609e.tar.xz | |
runtime: check kernel physical page size during init
The runtime hard-codes an assumed physical page size. If this is
smaller than the kernel's page size or not a multiple of it, sysUnused
may incorrectly release more memory to the system than intended.
Add a runtime startup check that the runtime's assumed physical page
is compatible with the kernel's physical page size.
For #9993.
Change-Id: Ida9d07f93c00ca9a95dd55fc59bf0d8a607f6728
Reviewed-on: https://go-review.googlesource.com/22064
Reviewed-by: Rick Hudson <rlh@golang.org>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/os_linux.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go index 4645f1c33d..35b57d8a23 100644 --- a/src/runtime/os_linux.go +++ b/src/runtime/os_linux.go @@ -178,6 +178,7 @@ var failthreadcreate = []byte("runtime: failed to create new OS thread\n") const ( _AT_NULL = 0 // End of vector + _AT_PAGESZ = 6 // System physical page size _AT_RANDOM = 25 // introduced in 2.6.29 ) @@ -201,7 +202,21 @@ func sysargs(argc int32, argv **byte) { // The kernel provides a pointer to 16-bytes // worth of random data. startupRandomData = (*[16]byte)(unsafe.Pointer(val))[:] + + case _AT_PAGESZ: + // Check that the true physical page size is + // compatible with the runtime's assumed + // physical page size. + if sys.PhysPageSize < val { + print("runtime: kernel page size (", val, ") is larger than runtime page size (", sys.PhysPageSize, ")\n") + exit(1) + } + if sys.PhysPageSize%val != 0 { + print("runtime: runtime page size (", sys.PhysPageSize, ") is not a multiple of kernel page size (", val, ")\n") + exit(1) + } } + archauxv(tag, val) } } |
