Skip to content

Commit 8ce844e

Browse files
committed
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>
1 parent d6b177d commit 8ce844e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/runtime/os_linux.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ var failthreadcreate = []byte("runtime: failed to create new OS thread\n")
178178

179179
const (
180180
_AT_NULL = 0 // End of vector
181+
_AT_PAGESZ = 6 // System physical page size
181182
_AT_RANDOM = 25 // introduced in 2.6.29
182183
)
183184

@@ -201,7 +202,21 @@ func sysargs(argc int32, argv **byte) {
201202
// The kernel provides a pointer to 16-bytes
202203
// worth of random data.
203204
startupRandomData = (*[16]byte)(unsafe.Pointer(val))[:]
205+
206+
case _AT_PAGESZ:
207+
// Check that the true physical page size is
208+
// compatible with the runtime's assumed
209+
// physical page size.
210+
if sys.PhysPageSize < val {
211+
print("runtime: kernel page size (", val, ") is larger than runtime page size (", sys.PhysPageSize, ")\n")
212+
exit(1)
213+
}
214+
if sys.PhysPageSize%val != 0 {
215+
print("runtime: runtime page size (", sys.PhysPageSize, ") is not a multiple of kernel page size (", val, ")\n")
216+
exit(1)
217+
}
204218
}
219+
205220
archauxv(tag, val)
206221
}
207222
}

0 commit comments

Comments
 (0)