]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: check that sysUnused is always physical-page aligned
authorAustin Clements <austin@google.com>
Thu, 14 Apr 2016 17:40:35 +0000 (13:40 -0400)
committerAustin Clements <austin@google.com>
Sat, 16 Apr 2016 21:42:40 +0000 (21:42 +0000)
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>
src/runtime/mem_linux.go

index 1ee13bd7e681b1c0df316219559a28aa57637503..61fdcee5430247c45ecf4b4ebcd2b74eca7c9873 100644 (file)
@@ -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)
 }