Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: msanwrite segfaults when called without a g on arm64 #34338

Closed
zhangfannie opened this issue Sep 17, 2019 · 6 comments
Closed

runtime: msanwrite segfaults when called without a g on arm64 #34338

zhangfannie opened this issue Sep 17, 2019 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@zhangfannie
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version devel +c3c53661ba Tue Sep 17 04:37:46 2019 +0000 linux/arm64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/home/fanzha02/.cache/go-build"
GOENV="/home/fanzha02/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/fanzha02/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/fanzha02/work/go_project/gomain"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/fanzha02/work/go_project/gomain/pkg/tool/linux_arm64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/fanzha02/work/go_project/gomain/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build714027259=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run testsanitizers/TestShared test

cd $GOROOT/src
run the command: CC=clang ../bin/go tool dist test -run testsanitizers
clang version: clang --version
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

What did you expect to see?

pass

What did you see instead?

The test failed.

../misc/cgo/testsanitizers

--- FAIL: TestShared (0.24s)
--- FAIL: TestShared/msan_shared (4.69s)
cshared_test.go:71: /tmp/TestShared066999108/msan_shared exited with exit status 77
MemorySanitizer:DEADLYSIGNAL
==24668==ERROR: MemorySanitizer: SEGV on unknown address 0x000000000030 (pc 0xffff94b3e9d4 bp 0xffffef3ca388 sp 0xffffef3ca390 T24668)
==24668==The signal is caused by a READ memory access.
==24668==Hint: address points to the zero page.
#0 0xffff94b3e9d3 (/tmp/TestShared066999108/libmsan_shared.so+0x8e9d3)

        MemorySanitizer can not provide additional info.
        SUMMARY: MemorySanitizer: SEGV (/tmp/TestShared066999108/libmsan_shared.so+0x8e9d3)
        ==24668==ABORTING

FAIL

@zhangfannie
Copy link
Contributor Author

The cause is that when built with -buildmode=c-shared, the sigaction() of runtime/cgo_sigaction.go will call msanwrite() during libpreinit (before the runtime has set up a g). Unfortunately, on arm64, msancall() called by msanwrite() assumes that it is always called with a valid g, leading to a segfault.

I will submit the fixed CL, checking for nil g in msancall() on arm64.

@toothrot toothrot changed the title runtime: msanwrite segfaults when called without a g on arm64 runtime/cgo: msanwrite segfaults when called without a g on arm64 Sep 17, 2019
@toothrot toothrot added this to the Go1.14 milestone Sep 17, 2019
@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 17, 2019
@toothrot
Copy link
Contributor

/cc @bcmills and @ianlancetaylor who know much more about runtime/cgo than myself.

@ianlancetaylor
Copy link
Contributor

The suggested change sounds correct. That is what the amd64 code already does.

@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 17, 2019
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 17, 2019
@ianlancetaylor
Copy link
Contributor

The change should be to msancall<> in runtime/msan_arm64.s.

@ianlancetaylor ianlancetaylor changed the title runtime/cgo: msanwrite segfaults when called without a g on arm64 runtime: msanwrite segfaults when called without a g on arm64 Sep 17, 2019
@zhangfannie
Copy link
Contributor Author

@ianlancetaylor Yes, you are right. We need to check nil g to msancall() in runtime/msan_arm64.s. The fixed patch is ready and I will submit it. Thank you.

@gopherbot
Copy link

Change https://golang.org/cl/196157 mentions this issue: runtime: check for nil g in msancall() on arm64

@golang golang locked and limited conversation to collaborators Sep 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants