From 60a9e5d613d6de21735e54ca62246e3f8ef8c8d3 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 18 Jan 2018 17:33:04 -0500 Subject: runtime: ensure abort actually crashes the process On all non-x86 arches, runtime.abort simply reads from nil. Unfortunately, if this happens on a user stack, the signal handler will dutifully turn this into a panicmem, which lets user defers run and which user code can even recover from. To fix this, add an explicit check to the signal handler that turns faults in abort into hard crashes directly in the signal handler. This has the added benefit of giving a register dump at the abort point. Change-Id: If26a7f13790745ee3867db7f53b72d8281176d70 Reviewed-on: https://go-review.googlesource.com/93661 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/runtime/testdata/testprog/abort.go | 23 +++++++++++++++++++++++ src/runtime/testdata/testprog/empty.s | 5 +++++ 2 files changed, 28 insertions(+) create mode 100644 src/runtime/testdata/testprog/abort.go create mode 100644 src/runtime/testdata/testprog/empty.s (limited to 'src/runtime/testdata') diff --git a/src/runtime/testdata/testprog/abort.go b/src/runtime/testdata/testprog/abort.go new file mode 100644 index 0000000000..9e79d4dea3 --- /dev/null +++ b/src/runtime/testdata/testprog/abort.go @@ -0,0 +1,23 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import _ "unsafe" // for go:linkname + +func init() { + register("Abort", Abort) +} + +//go:linkname runtimeAbort runtime.abort +func runtimeAbort() + +func Abort() { + defer func() { + recover() + panic("BAD: recovered from abort") + }() + runtimeAbort() + println("BAD: after abort") +} diff --git a/src/runtime/testdata/testprog/empty.s b/src/runtime/testdata/testprog/empty.s new file mode 100644 index 0000000000..c5aa6f8a54 --- /dev/null +++ b/src/runtime/testdata/testprog/empty.s @@ -0,0 +1,5 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This exists solely so we can linkname in symbols from runtime. -- cgit v1.3