opentelemetry-go-instrumentation icon indicating copy to clipboard operation
opentelemetry-go-instrumentation copied to clipboard

Allocated buffer data can wrap around and overwrite live data

Open grcevski opened this issue 2 years ago • 2 comments

Describe the bug

Assuming we have large enough number of goroutines, the code in alloc.h, write_target_data can wrap around and overwrite an ongroing request data.

Namely the following code: https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/main/include/alloc.h#L77

When we reach the end of the allocated buffer, it simply begins at the start of the buffer for the current CPU. However, the data that's at the beginning of the per CPU segment can technically be in use. One simple example is a goroutine thread being preempted after the CreateHeaderFields uprobe returns. After the preempted thread resumes, the data for its headers can be replaced with something else that's using the buffer.

Environment

  • OS: Linux
  • Go Version: any
  • Version: any

To Reproduce

No reproduction case. Making a testcase that fails should be possible, but it would be unreliable reproduction case.

Expected behavior

Allocating new space from the shared memory segment should be safe.

Additional context

I think a solution here could be a rudimentary reference counting.

grcevski avatar May 03 '23 18:05 grcevski