Skip to content

fix: bound DWARF .eh_frame_hdr parsing to the section#571

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 5 commits into
DataDog:mainfrom
edznux-dd:fix/dwarf-parser-oob
Jun 3, 2026
Merged

fix: bound DWARF .eh_frame_hdr parsing to the section#571
gh-worker-dd-mergequeue-cf854d[bot] merged 5 commits into
DataDog:mainfrom
edznux-dd:fix/dwarf-parser-oob

Conversation

@edznux-dd
Copy link
Copy Markdown
Contributor

What does this PR do?:

Fix bound checking on untrusted section size, avoid infinite loops, and fix small fuzz-harness only memory leak.

Motivation:

Make the dwarf parser more reliable.

Additional Notes:

How to test the change?:

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.
  • JIRA: [JIRA-XXXX]

Unsure? Have a question? Request a review!

@edznux-dd edznux-dd requested a review from a team as a code owner June 1, 2026 16:39
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c6e3fc8393

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ddprof-lib/src/main/cpp/dwarf.cpp Outdated
@datadog-prod-us1-5

This comment has been minimized.

Copy link
Copy Markdown
Collaborator

@jbachorik jbachorik left a comment

Choose a reason for hiding this comment

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

Sphinx review — issues in unchanged parseFde() body

Two findings that couldn't be anchored as inline comments because they fall in the unchanged part of parseFde():

dwarf.cpp:301 — unguarded cie_offset underflow (HIGH)

cie_offset is a u32 read directly from the untrusted, memory-mapped ELF image. When cie_offset > (fde_start - _section_start), the subtraction fde_start - cie_offset underflows past the start of the mapped allocation — undefined behaviour. A crafted small value also redirects CIE parsing to an attacker-controlled position inside the section, defeating the bounds model this PR establishes.

if (cie_offset > (size_t)(fde_start - _section_start)) {
    return;
}
_ptr = fde_start - cie_offset;

dwarf.cpp:308 — unclamped _ptr advance after untrusted LEB (MEDIUM)

_ptr += getLeb() advances by a decoded value from untrusted input without clamping to _section_end. A large value pushes _ptr past the section boundary, silently truncating the rest of the FDE. Same issue in parseInstructions() at the DW_CFA_def_cfa_expression and DW_CFA_expression branches (lines ~404, ~409).

After each unclamped advance: if (_ptr > _section_end) _ptr = _section_end;

Raised by Sphinx review.

Comment thread ddprof-lib/src/main/cpp/dwarf.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/dwarf.cpp
Comment thread ddprof-lib/src/main/cpp/dwarf.h
Comment thread ddprof-lib/src/test/cpp/dwarf_ut.cpp
@edznux-dd edznux-dd force-pushed the fix/dwarf-parser-oob branch from a07abc8 to 40af28f Compare June 2, 2026 12:38
@edznux-dd edznux-dd requested a review from jbachorik June 2, 2026 17:51
@edznux-dd edznux-dd force-pushed the fix/dwarf-parser-oob branch from a412832 to e504121 Compare June 3, 2026 13:41
Copy link
Copy Markdown
Collaborator

@jbachorik jbachorik left a comment

Choose a reason for hiding this comment

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

LGTM

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants