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

codegen: Fix interaction with verifier when accessing ctx field twice #2008

Merged
merged 2 commits into from
Sep 17, 2021

Conversation

danobi
Copy link
Member

@danobi danobi commented Sep 16, 2021

The verifier doesn't like it if we modify the ctx pointer twice before
dereferencing it. In other words, ctx+8 is OK, but ctx+4+4 is NOT.
The reasoning in kernel land is due to interactions w/ socket buffer
(skb) access rewrites. Without this limitation, the kernel may let the
prog write past the end of the skb.

We trip over this issue when accessing the same tracepoint field twice.
LLVM decides to save ctx+8 in a temporary register and reuse the value
when indexing into the struct in the unrolled memcpy loop.

Fix this issue by using bpf_probe_read_*() so that we only modify the
ctx pointer once.

Checklist
  • Language changes are updated in man/adoc/bpftrace.adoc and if needed in docs/reference_guide.md
  • User-visible and non-trivial changes updated in CHANGELOG.md
  • The new behaviour is covered by tests

The verifier doesn't like it if we modify the ctx pointer twice before
dereferencing it. In other words, ctx+8 is OK, but ctx+4+4 is NOT.
The reasoning in kernel land is due to interactions w/ socket buffer
(skb) access rewrites. Without this limitation, the kernel may let the
prog write past the end of the skb.

We trip over this issue when accessing the same tracepoint field twice.
LLVM decides to save ctx+8 in a temporary register and reuse the value
when indexing into the struct in the unrolled memcpy loop.

Fix this issue by using bpf_probe_read_*() so that we only modify the
ctx pointer once.
@danobi
Copy link
Member Author

danobi commented Sep 16, 2021

@viktormalik what do you think?

Copy link
Contributor

@viktormalik viktormalik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - replacing memcpy by probe_read when reading strings from ctx should be a safe thing to do.

@danobi danobi merged commit c6716d3 into bpftrace:master Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants