Skip to content

fix: prevent uint32 overflow in struct_ops bounds check - #2025

Merged
dylandreimerink merged 2 commits into
cilium:mainfrom
DARSHANR007:fix/struct_ops_datasec_overflow
May 29, 2026
Merged

dylandreimerink merged 2 commits into
cilium:mainfrom
DARSHANR007:fix/struct_ops_datasec_overflow

Conversation

@DARSHANR007

@DARSHANR007 DARSHANR007 commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Fix: Prevent uint32 overflow in struct_ops DATASEC bounds check

Problem

LoadCollectionSpecFromReader could panic while parsing malformed struct_ops metadata from an ELF object.

A malformed object can provide a very large offset that bypasses the bounds check due to an integer overflow. The code then accesses memory outside the section bounds, leading to a panic.

Solution

Convert baseOff and userSize to uint64 before addition to prevent overflow:

// Before (vulnerable)
if baseOff+userSize > uint32(len(userData)) {
    return nil, 0, fmt.Errorf("%s exceeds section", mapName)
}

// After (fixed)
if uint64(baseOff)+uint64(userSize) > uint64(len(userData)) {
    return nil, 0, fmt.Errorf("%s exceeds section", mapName)
}

Fixes #2024

Malformed ELF files with large offsets now return error instead of panic.

Signed-off-by: darsh <[email protected]>
@DARSHANR007
DARSHANR007 requested a review from a team as a code owner May 29, 2026 04:38

@dylandreimerink dylandreimerink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fix looks good. Lets drop the test, its not stable like this.

Comment thread struct_ops_overflow_test.go Resolved
@dylandreimerink
dylandreimerink merged commit 4a62a54 into cilium:main May 29, 2026
20 checks 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.

elf: malformed struct_ops DATASEC offset can panic LoadCollectionSpecFromReader

2 participants