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/checkptr: fatal error: checkptr: pointer arithmetic result points to invalid allocation #68415

Closed
leizhag opened this issue Jul 15, 2024 · 5 comments
Assignees
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@leizhag
Copy link

leizhag commented Jul 15, 2024

Go version

go version go1.23rc1 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/xxx/Library/Caches/go-build'
GOENV='/Users/xxx/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT='arenas'
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/xxx/go/pkg/mod'
GOOS='darwin'
GOPATH='/Users/xxx/go'
GOPROXY='https://goproxy.cn'
GOROOT='/Users/xxx/sdk/go1.23rc1'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/xxx/sdk/go1.23rc1/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23rc1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/xxx/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/df/2vy1kgkn1_98kqwtn0zgdyj80000gn/T/go-build775107601=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Run the following program with -gcflags=all=-d=checkptr flag.

package main

import "regexp"

var dataFileRegexp = regexp.MustCompile(`^data\.\d+\.bin$`)

func main() {
	_ = dataFileRegexp
}

What did you see happen?

fatal error: checkptr: pointer arithmetic result points to invalid allocation

goroutine 1 gp=0x140000021c0 m=0 mp=0x100cfd640 [running, locked to thread]:
runtime.throw({0x100c5465d?, 0x100c4bb34?})
	/Users/xxx/sdk/go1.23rc1/src/runtime/panic.go:1067 +0x38 fp=0x14000078bf0 sp=0x14000078bc0 pc=0x100c27678
runtime.checkptrArithmetic(0x1400007c180?, {0x0, 0x0, 0x80?})
	/Users/xxx/sdk/go1.23rc1/src/runtime/checkptr.go:69 +0xa8 fp=0x14000078c20 sp=0x14000078bf0 pc=0x100bcd568
internal/abi.NoEscape(...)
	/Users/xxx/sdk/go1.23rc1/src/internal/abi/escape.go:21
strings.(*Builder).copyCheck(...)
	/Users/xxx/sdk/go1.23rc1/src/strings/builder.go:33
strings.(*Builder).WriteRune(0x14000078cb8, 0x64)
	/Users/xxx/sdk/go1.23rc1/src/strings/builder.go:98 +0x48 fp=0x14000078c80 sp=0x14000078c20 pc=0x100c38588
regexp.onePassPrefix(0x1400007c120)
	/Users/xxx/sdk/go1.23rc1/src/regexp/onepass.go:60 +0x170 fp=0x14000078ce0 sp=0x14000078c80 pc=0x100c49450
regexp.compile({0x100c4f3ee, 0x10}, 0xd640?, 0x0)
	/Users/xxx/sdk/go1.23rc1/src/regexp/regexp.go:203 +0x208 fp=0x14000078d70 sp=0x14000078ce0 pc=0x100c4bee8
regexp.Compile(...)
	/Users/xxx/sdk/go1.23rc1/src/regexp/regexp.go:135
regexp.MustCompile({0x100c4f3ee, 0x10})
	/Users/xxx/sdk/go1.23rc1/src/regexp/regexp.go:315 +0x30 fp=0x14000078df0 sp=0x14000078d70 pc=0x100c4c3b0
main.init()
	/Users/xxx/Projects/guance/local-dev/cmd/checkptr/main.go:5 +0x28 fp=0x14000078e10 sp=0x14000078df0 pc=0x100c4d758
runtime.doInit1(0x100ce8820)
	/Users/xxx/sdk/go1.23rc1/src/runtime/proc.go:7278 +0xd4 fp=0x14000078f40 sp=0x14000078e10 pc=0x100c082b4
runtime.doInit(...)
	/Users/xxx/sdk/go1.23rc1/src/runtime/proc.go:7245
runtime.main()
	/Users/xxx/sdk/go1.23rc1/src/runtime/proc.go:254 +0x344 fp=0x14000078fd0 sp=0x14000078f40 pc=0x100bf90d4
runtime.goexit({})
	/Users/xxx/sdk/go1.23rc1/src/runtime/asm_arm64.s:1223 +0x4 fp=0x14000078fd0 sp=0x14000078fd0 pc=0x100c2dac4

goroutine 2 gp=0x14000002700 m=nil [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
	/Users/xxx/sdk/go1.23rc1/src/runtime/proc.go:424 +0xc8 fp=0x1400004ef90 sp=0x1400004ef70 pc=0x100c27758
runtime.goparkunlock(...)
	/Users/xxx/sdk/go1.23rc1/src/runtime/proc.go:430
runtime.forcegchelper()
	/Users/xxx/sdk/go1.23rc1/src/runtime/proc.go:337 +0xb8 fp=0x1400004efd0 sp=0x1400004ef90 pc=0x100bf9378
runtime.goexit({})
	/Users/xxx/sdk/go1.23rc1/src/runtime/asm_arm64.s:1223 +0x4 fp=0x1400004efd0 sp=0x1400004efd0 pc=0x100c2dac4
created by runtime.init.7 in goroutine 1
	/Users/xxx/sdk/go1.23rc1/src/runtime/proc.go:325 +0x24

goroutine 17 gp=0x14000082380 m=nil [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
	/Users/xxx/sdk/go1.23rc1/src/runtime/proc.go:424 +0xc8 fp=0x1400004a760 sp=0x1400004a740 pc=0x100c27758
runtime.goparkunlock(...)
	/Users/xxx/sdk/go1.23rc1/src/runtime/proc.go:430
runtime.bgsweep(0x1400008e000)
	/Users/xxx/sdk/go1.23rc1/src/runtime/mgcsweep.go:277 +0xa0 fp=0x1400004a7b0 sp=0x1400004a760 pc=0x100be5cb0
runtime.gcenable.gowrap1()
	/Users/xxx/sdk/go1.23rc1/src/runtime/mgc.go:203 +0x28 fp=0x1400004a7d0 sp=0x1400004a7b0 pc=0x100bd9f38
runtime.goexit({})
	/Users/xxx/sdk/go1.23rc1/src/runtime/asm_arm64.s:1223 +0x4 fp=0x1400004a7d0 sp=0x1400004a7d0 pc=0x100c2dac4
created by runtime.gcenable in goroutine 1
	/Users/xxx/sdk/go1.23rc1/src/runtime/mgc.go:203 +0x6c

goroutine 18 gp=0x14000082540 m=nil [GC scavenge wait]:
runtime.gopark(0x1400008e000?, 0x100c6d020?, 0x1?, 0x0?, 0x14000082540?)
	/Users/xxx/sdk/go1.23rc1/src/runtime/proc.go:424 +0xc8 fp=0x1400004af60 sp=0x1400004af40 pc=0x100c27758
runtime.goparkunlock(...)
	/Users/xxx/sdk/go1.23rc1/src/runtime/proc.go:430
runtime.(*scavengerState).park(0x100cfcec0)
	/Users/xxx/sdk/go1.23rc1/src/runtime/mgcscavenge.go:425 +0x5c fp=0x1400004af90 sp=0x1400004af60 pc=0x100be36ac
runtime.bgscavenge(0x1400008e000)
	/Users/xxx/sdk/go1.23rc1/src/runtime/mgcscavenge.go:653 +0x44 fp=0x1400004afb0 sp=0x1400004af90 pc=0x100be3bf4
runtime.gcenable.gowrap2()
	/Users/xxx/sdk/go1.23rc1/src/runtime/mgc.go:204 +0x28 fp=0x1400004afd0 sp=0x1400004afb0 pc=0x100bd9ed8
runtime.goexit({})
	/Users/xxx/sdk/go1.23rc1/src/runtime/asm_arm64.s:1223 +0x4 fp=0x1400004afd0 sp=0x1400004afd0 pc=0x100c2dac4
created by runtime.gcenable in goroutine 1
	/Users/xxx/sdk/go1.23rc1/src/runtime/mgc.go:204 +0xac
exit status 2

What did you expect to see?

Normal exit like using go1.22.

@Jorropo Jorropo added this to the Go1.23 milestone Jul 15, 2024
@Jorropo Jorropo added NeedsFix The path to resolution is known, but the work has not been done. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed NeedsFix The path to resolution is known, but the work has not been done. labels Jul 15, 2024
@Jorropo
Copy link
Member

Jorropo commented Jul 15, 2024

I reproduced the issue on linux/amd64. I bisected it to 4742c52
cc @mknyszek @dr2chase

@cuonglm cuonglm self-assigned this Jul 15, 2024
@cuonglm cuonglm added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jul 15, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/598295 mentions this issue: strings: re-introduce noescape wrapper

@cuonglm
Copy link
Member

cuonglm commented Jul 15, 2024

The problem is that internal/abi is a runtime package, so it cannot be built with -d=checkptr yet. The checkptr is always disabled for internal/abi (a runtime package)

This causes incorrect inlining decision for abi.NoEscape function, since one marked with go:nocheckptr should not be inlined when checkptr enabled.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/599435 mentions this issue: cmd/compile: don't inline runtime functions in -d=checkptr build

gopherbot pushed a commit that referenced this issue Jul 22, 2024
Runtime functions, e.g. internal/abi.NoEscape, should not be
instrumented with checkptr. But if they are inlined into a
checkptr-enabled function, they will be instrumented, and may
result in a check failure.

Let the compiler not inline runtime functions into checkptr-
enabled functions.

Also undo the change in the strings package in CL 598295, as the
compiler handles it now.

Fixes #68511.
Updates #68415.

Change-Id: I78eb380855ac9dd53c1a1a628ec0da75c3e5a1a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/599435
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
Reviewed-by: Cuong Manh Le <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants