From b1d94c118fd163381537a22be4913742103baece Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sun, 3 Dec 2017 19:28:28 -0500 Subject: [PATCH] runtime: validate lfnode addresses Change-Id: Ic8c506289caaf6218494e5150d10002e0232feaa Reviewed-on: https://go-review.googlesource.com/85876 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/lfstack.go | 10 ++++++++++ src/runtime/mgcwork.go | 1 + 2 files changed, 11 insertions(+) diff --git a/src/runtime/lfstack.go b/src/runtime/lfstack.go index 4787c5be3f..406561a275 100644 --- a/src/runtime/lfstack.go +++ b/src/runtime/lfstack.go @@ -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") + } +} diff --git a/src/runtime/mgcwork.go b/src/runtime/mgcwork.go index c6634fc78c..99771e2e57 100644 --- a/src/runtime/mgcwork.go +++ b/src/runtime/mgcwork.go @@ -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 { -- 2.50.0