-
Notifications
You must be signed in to change notification settings - Fork 3.4k
pkg/bpf: Protect each uintptr with runtime.KeepAlive #10168
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
Conversation
Release note label not set, please set the appropriate release note. |
2 similar comments
Release note label not set, please set the appropriate release note. |
Release note label not set, please set the appropriate release note. |
test-me-please |
|
Maybe just an idea: |
c2282f8
to
42c3226
Compare
test-me-please |
@florianl This is just a temporary fix. We are planning to migrate to cilium/ebpf soonish. |
Travis failed:
|
test-me-please |
42c3226
to
da0448c
Compare
da0448c
to
4fa0da5
Compare
test-me-please |
4fa0da5
to
d1527b6
Compare
test-me-please |
d1527b6
to
f9f49fd
Compare
test-me-please |
Otherise, the Go's GC might collect it while the syscall is being executed. See #10168 for more context. Signed-off-by: Martynas Pumputis <m@lambda.lt>
Otherise, the Go's GC might collect it while the syscall is being executed. See #10168 for more context. Signed-off-by: Martynas Pumputis <m@lambda.lt>
@@ -122,6 +125,8 @@ func GetProgInfoByFD(fd int) (ProgInfo, error) { | |||
duration = spanstat.Start() | |||
} | |||
ret, _, err := unix.Syscall(unix.SYS_BPF, BPF_OBJ_GET_INFO_BY_FD, uintptr(unsafe.Pointer(&attr)), unsafe.Sizeof(attr)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also need, runtime.KeepAlive(&attr) here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree backporting dead-code removal makes sense here. I'll rework the backport series as well.
The Go's GC is unable to track objects referred by
uintptr
[1] [2].A consequence of this is that the GC might collect such objects when a blocking syscall is executed. This might corrupt memory of other Go objects e.g. if the reclaimed memory is used for new objects and the kernel modifies the objects in the context of the blocking syscall.
To prevent from this, we protect each pointer to objects with
runtime.KeepAlive()
which marks the objects as alive at least untilruntime.KeepAlive()
has been called.FOR REVIEWERS:
uintptr
and then passed toSyscall*()
is protected withruntime.KeepAlive()
.perf_linux.go
which in v1.7 was replaced bycilium/ebpf
. I will do it once this PR gets backported.[1]: golang/go#13372 (comment)
[2]: https://utcc.utoronto.ca/~cks/space/blog/programming/GoUintptrVsUnsafePointer
Developed together with @aanm and @borkmann.
This change is