trace/exec: Fix crash when using --cwd #2422
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The ebpf code has some optimization to only send the right amount of bytes used to hold the arguments.
(See around L200 in pkg/gadgets/trace/exec/tracer/bpf/execsnoop.bpf.c). bpf2go defines
Args
as[7680]uint8
and the tracer was usingargs := bpfEvent.Args
, hence copying the array. It an issue since it's trying to copy memory outside the sample received from the perf ring buffer.Testing
The issue is easy to reproduce on the local machine (at least on mine):
Bug Investigation
It's not clear to me why this bug doesn't happen more often. The code with the defect was introduced in 34edb8b. I used git bisect and found out that it started to happen only after 62a333d. I first thought it that it was related to the overwritable perf ring support, I tried to use git bisect on ebpf-go and found out that this only happens after cilium/ebpf@8fa4c90. I have no idea why it doesn't happen before that commit.
ref