Skip to content

Use bpf_probe_read_*_str for all string buffer reads#57

Merged
lizrice merged 2 commits into
erratafrom
copilot/sub-pr-55-again
Mar 23, 2026
Merged

Use bpf_probe_read_*_str for all string buffer reads#57
lizrice merged 2 commits into
erratafrom
copilot/sub-pr-55-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 23, 2026

bpf_probe_read_kernel/user does not NUL-terminate when truncating, so buffers read into data.path, data.message, and data.command could contain garbage when printed as C strings in user space.

Changes

  • chapter7/hello.bpf.c — replaced bpf_probe_read_kernel/user with bpf_probe_read_kernel_str / bpf_probe_read_user_str for all data.path reads (kprobe_sys_execve, kprobe_do_execve, fentry_execve, tp_sys_enter_execve)
  • chapter6/hello-verifier.bpf.c — replaced bpf_probe_read_kernel with bpf_probe_read_kernel_str for data.message in both the p != 0 and fallback branches
  • Multiple files — removed superfluous & when passing array fields to BPF helpers (arrays already decay to pointers)
// Before
bpf_probe_read_user(&data.path, sizeof(data.path), pathname);

// After
bpf_probe_read_user_str(data.path, sizeof(data.path), pathname);

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix errata in array handling and tidy string output Use bpf_probe_read_*_str for all string buffer reads Mar 23, 2026
Copilot AI requested a review from lizrice March 23, 2026 13:47
@lizrice
Copy link
Copy Markdown
Owner

lizrice commented Mar 23, 2026

@copilot I approved this, what happens next?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 23, 2026

@copilot I approved this, what happens next?

Since this is a stacked PR on top of the errata branch, the next step is to merge the errata base PR first. Once that's merged into main, this PR's base will update and it can then be merged as well. You can merge this PR directly into errata if you'd like to keep the changes together, or wait for errata to land first.

Copilot AI requested a review from lizrice March 23, 2026 14:12
@lizrice lizrice marked this pull request as ready for review March 23, 2026 14:22
@lizrice lizrice merged commit 2d83e94 into errata Mar 23, 2026
1 check passed
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