-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/cgo: memory sanitizer error due to uninitialized memory in C.CString when using cgo with sanitizers enabled #60912
Comments
CC @golang/compiler. |
I'm trying to understand why MSAN reports an uninitialized value in the above code. I put a gdb script to understand what's going on: Click to expand
And I get the following output:
It seems that the memory allocated by malloc isn't unpoisoned by I thought the copy held in https://github.com/golang/go/blob/go1.20.5/src/cmd/cgo/out.go#L1670 will let MSAN know that the memory is initialized, but apparently it doesn't. Any idea why? |
In triage, we think that maybe your |
Aha, I checked that there are no error messages after I replaced '-tags msan' with '-msan' in build.sh, and the binary is working fine. Thanks! |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Sample repo: https://github.com/bc-lee/test-golang-cgo-sanitizers
To reproduce, run the following commands on linux x86_64:
Basically, I'm making a executable with cgo, with address/memory sanitizers enabled C libraries.
I checked out Chromium's LLVM build and sysroot to build the executable.
The main code is as follows:
From my understanding,
C.Cstring
allocates a memory(usingmalloc
) and returns a pointer to it. So I'm callingC.free
to free the memory.However when I run the executable, I get the following error:
It seems that msan treats the memory allocated by
C.CString
as uninitialized.I'm not sure if this is a bug, or golang currently does not support this kind of use case, or I'm doing something wrong.
What did you expect to see?
No error.
What did you see instead?
Memory sanitizer error.
The text was updated successfully, but these errors were encountered: