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/asan: the -asan option cannot print where the error occurred. #50362

Closed
zhangfannie opened this issue Dec 27, 2021 · 2 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.

Comments

@zhangfannie
Copy link
Contributor

zhangfannie commented Dec 27, 2021

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

$ go version
go version devel go1.18-b357b05b70 Thu Dec 23 20:03:38 2021 +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=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/fanzha02/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/fanzha02/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/fanzha02/work/go_project/govscode/gomain"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/fanzha02/work/go_project/govscode/gomain/pkg/tool/linux_arm64"
GOVCS=""
GOVERSION="devel go1.18-b357b05b70 Thu Dec 23 20:03:38 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/fanzha02/work/go_project/govscode/gomain/src/go.mod"
GOWORK=""
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-build1769828368=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. go build -asan test.go (https://go.dev/play/p/ufagb_TwZfi)
  2. ./test

// test.go

package main

import (
        "fmt"
        "unsafe"
)

func main() {
        p := new([1024*100]int)
        p[1] = 10
        r := bar(&p[102399])           // line0
        fmt.Printf("r value is %d", r)
}

func bar(a *int) int {
        p := (*int)(unsafe.Add(unsafe.Pointer(a), 2*unsafe.Sizeof(int(1))))
        *p = 10  // BO0M               //  line1
        return *p
}

What did you expect to see?

I expect the -asan can print where the error occurred, like
#0 0x454ad0 in main.bar test.go:line1
#1 0x454ad0 in main.main test.go:line0

What did you see instead?

The -asan option does not print where the error occurred.

==5406==ERROR: AddressSanitizer: use-after-poison on address 0x204000348008 at pc 0x0000004916a8 bp 0xffffd62ddc90 sp 0xffffd62ddcb0
WRITE of size 8 at 0x204000348008 thread T0
#0 0x4916a4 in __asan_write_go /home/fanzha02/work/go_project/govscode/gomain/src/runtime/asan/asan.go:46
#1 0x458d6c in asancall /home/fanzha02/work/go_project/govscode/gomain/src/runtime/asan_arm64.s:60

Address 0x204000348008 is a wild pointer.
SUMMARY: AddressSanitizer: use-after-poison /home/fanzha02/work/go_project/govscode/gomain/src/runtime/asan/asan.go:46 in __asan_write_go
Shadow bytes around the buggy address:
0x041800068fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x041800068fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x041800068fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x041800068fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x041800068ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x041800069000: f7[f7]f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
0x041800069010: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
0x041800069020: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
0x041800069030: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
0x041800069040: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
0x041800069050: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7

@zhangfannie
Copy link
Contributor Author

The reason is that the current implementation calls incorrect asan runtime functions to report error, they do not record pc and sp, and only report the memory access errors without printing the location of the error. The correct asan runtime function we should call is __asan_report_error, it will record pc and sp, and report where the error occurred.

The fixed patch will be submitted soon. Thank you.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/374395 mentions this issue: runtime: fix the issue that the -asan option cannot print where the error occurred

@thanm thanm added the NeedsFix The path to resolution is known, but the work has not been done. label Dec 28, 2021
@golang golang locked and limited conversation to collaborators Dec 29, 2022
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

3 participants