]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: validate lfnode addresses
authorAustin Clements <austin@google.com>
Mon, 4 Dec 2017 00:28:28 +0000 (19:28 -0500)
committerAustin Clements <austin@google.com>
Thu, 15 Feb 2018 21:12:11 +0000 (21:12 +0000)
Change-Id: Ic8c506289caaf6218494e5150d10002e0232feaa
Reviewed-on: https://go-review.googlesource.com/85876
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
src/runtime/lfstack.go
src/runtime/mgcwork.go

index 4787c5be3fac497f524f4f7fbbc613cf2ab97d6c..406561a275b6fe8ef96c7d2d61200f9e5ad6c266 100644 (file)
@@ -55,3 +55,13 @@ func (head *lfstack) pop() unsafe.Pointer {
 func (head *lfstack) empty() bool {
        return atomic.Load64((*uint64)(head)) == 0
 }
+
+// lfnodeValidate panics if node is not a valid address for use with
+// lfstack.push. This only needs to be called when node is allocated.
+func lfnodeValidate(node *lfnode) {
+       if lfstackUnpack(lfstackPack(node, ^uintptr(0))) != node {
+               printlock()
+               println("runtime: bad lfnode address", hex(uintptr(unsafe.Pointer(node))))
+               throw("bad lfnode address")
+       }
+}
index c6634fc78ca57ca15ef4b4a577f12e7aaf5342d9..99771e2e57f2cccfd5bd3e030fbc5f4b62426cfd 100644 (file)
@@ -400,6 +400,7 @@ func getempty() *workbuf {
                for i := uintptr(0); i+_WorkbufSize <= workbufAlloc; i += _WorkbufSize {
                        newb := (*workbuf)(unsafe.Pointer(s.base() + i))
                        newb.nobj = 0
+                       lfnodeValidate(&newb.node)
                        if i == 0 {
                                b = newb
                        } else {