Skip to content

Avoid UBSan wrap in ElfSection vaddr arithmetic - #795

Merged
jbachorik merged 1 commit into
mainfrom
jb/rc-1-ubsan-elf-vaddr
Sep 17, 2026
Merged

jbachorik merged 1 commit into
mainfrom
jb/rc-1-ubsan-elf-vaddr

Conversation

@jbachorik

@jbachorik jbachorik commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?:
Avoids undefined behavior (UBSan flagged) in ElfSection's vaddr handling in symbols_linux.cpp: p_vaddr is an unrelated virtual address, not an offset within the _base allocation; subtracting it via pointer arithmetic can wrap through a null representation. The subtraction now happens in integer space before reinterpreting, matching the file's existing integer-space validation pattern.

Motivation:
UBSan flags this arithmetic; it must be fixed before sanitizer CI can pass for the reference-chains work (PROF-15341). Kept as a tiny standalone PR at the bottom of the stack so reviewers see it in seconds.

Additional Notes:
Bottom of a stacked series for PROF-15341 (reference chains). No functional change.

How to test the change?:
Existing symbols-related tests; optionally run an UBSan build over the ELF parsing paths.

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 security review (run the dd:platform-security-review
    skill, or file a request via the PSEC review form).
    bewaire also runs automatically on every PR.
  • This PR doesn't touch any of that.
  • JIRA: PROF-15341

p_vaddr is an unrelated virtual address, not an offset within _base;
subtracting it via pointer arithmetic can wrap through a null
representation, which UBSan flags. Do the subtraction in integer space
and reinterpret, matching this file's existing integer-space validation.
@dd-octo-sts

dd-octo-sts Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Scan-Build Report

User:runner@runnervmlun5p
Working Directory:/home/runner/work/java-profiler/java-profiler/ddprof-lib/src/test/make
Command Line:make -j4 all
Clang Version:Ubuntu clang version 18.1.3 (1ubuntu1)
Date:Thu Sep 17 17:27:02 2026

Bug Summary

Bug TypeQuantityDisplay?
All Bugs1
Logic error
Dereference of null pointer1

Reports

Bug Group Bug Type ▾ File Function/Method Line Path Length
Logic errorDereference of null pointerfaultInjection.cppcrashNow242

@dd-octo-sts

dd-octo-sts Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #35252608321 | Commit: adcf5b2 | Duration: 15m 18s (longest job)

All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - - -
8-ibm - - -
8-j9 - -
8-librca - -
8-orcl - - -
11 - - -
11-j9 - -
11-librca - -
17 - -
17-graal - -
17-j9 - -
17-librca - -
21 - -
21-graal - -
21-librca - -
25 - -
25-graal - -
25-librca - -

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-09-17 17:43:15 UTC

@dd-octo-sts

dd-octo-sts Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

All 40 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 e4d19ff7

@jbachorik
jbachorik added this pull request to stack #803 September 17, 2026 20:02
@jbachorik
jbachorik marked this pull request as ready for review September 17, 2026 20:03
@jbachorik
jbachorik requested a review from a team as a code owner September 17, 2026 20:03
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-17T20:06:30.010775Z e4d19ff Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jbachorik
jbachorik merged commit d7cf675 into main Sep 17, 2026
113 of 121 checks passed
@jbachorik
jbachorik deleted the jb/rc-1-ubsan-elf-vaddr branch September 17, 2026 20:05
@github-actions github-actions Bot added this to the 1.51.0 milestone Sep 17, 2026

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

Copy link
Copy Markdown

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: e4d19ff7ff

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +753 to +755
// at(ph) is NULL when ph->p_vaddr == 0 (a real, if rare, case for
// the first LOAD segment of some binaries) - same null-base
// pointer-arithmetic UB as the other fixes in this file.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Correct the null-address rationale for ET_DYN images

For PIE/shared-object (ET_DYN) images whose first PT_LOAD has p_vaddr == 0, at(ph) normally returns _vaddr_diff (the non-null load bias), not NULL; only the ET_EXEC or zero-load-bias cases can produce the claimed null address. This comment therefore misdescribes the common ELF layout and should identify the actual condition being handled rather than attributing it to p_vaddr == 0.

AGENTS.md reference: AGENTS.md:L466-L467

Useful? React with 👍 / 👎.

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.

1 participant