Skip to content

Validate total_size in eBPF metadata headers - #5552

Open
Nicholas L (nmlud21) wants to merge 1 commit into
microsoft:mainfrom
nmlud21:fix-memcpy-buffer-overflow
Open

Validate total_size in eBPF metadata headers#5552
Nicholas L (nmlud21) wants to merge 1 commit into
microsoft:mainfrom
nmlud21:fix-memcpy-buffer-overflow

Conversation

@nmlud21

Copy link
Copy Markdown
Contributor

Description

ebpf_extension_header_t carries version, size, and total_size. _ebpf_validate_extension_object_header validated only version and size, total_size was never bounded, yet it was used verbatim as both an array stride and a memcpy length into fixed-size stack and pool destinations, an attacker-length, attacker-content kernel out-of-bounds write.

Changes

  1. Bound total_size — added _ebpf_extension_type_max_total_size[] (parallel to the existing _supported_ebpf_extension_version[]); the validator now rejects total_size > sizeof(struct). One choke point closes every sink.
  2. Validate element 0 before using its total_size as a stride — 6 walkers in ebpf_native.c + 1 in shared_common.c. They previously read the stride from unvalidated memory.
  3. Clamp copies to min(total_size, sizeof(dest)) — 5 sites in ebpf_native.c, 1 in shared_common.c; matches the existing _ebpf_copy_program_entry idiom.
  4. Collateral OOB readhelper_prototype[i].flags double-indexed an already-offset pointer behind a dead guard (byte count compared to a version constant).

Testing

Ran unit_test passes.

Negative unit test for oversized total_size can be added.

Documentation

No

Installation

No

Signed-off-by: Nicholas Ludwig <nludwig@microsoft.com>
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

This pull request isn't linked to any GitHub issue. Please reference an issue with a keyword such as Fixes #123, Closes #456, etc., so the work can be tracked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants