Skip to content

fix: avoid UB left shift of negative ADRP immediate in decodeAdrTarget - #848

Merged
kaahos merged 2 commits into
mainfrom
paul.fournillon/fix-adrp-ubsan-left-shift
Oct 9, 2026
Merged

kaahos merged 2 commits into
mainfrom
paul.fournillon/fix-adrp-ubsan-left-shift

Conversation

@kaahos

@kaahos kaahos commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • decodeAdrTarget() left-shifts the sign-extended ADRP immediate (imm << 12), which is undefined behavior when imm is negative (ADRP addresses pages in either direction relative to PC)
  • UBSan traps this on every forked test JVM during VM::initProfilerBridge -> JvmtiEnv::GenerateEvents -> analyzeStubUnwind, aborting the process almost immediately (checks are compiled non-recoverable via -fno-sanitize-recover=all)
  • Fix: cast to uint64_t before shifting, matching the existing attributionPC pattern in this codebase for the same UB class -- two's-complement wraparound produces an identical bit pattern, just well-defined
  • Reference: https://en.cppreference.com/w/cpp/language/operator_arithmetic.html (bitwise shift operators -- left shift of a negative value is undefined behavior before C++20)

Test plan

  • gtestAsan / testAsan on aarch64 no longer aborts with the UBSan left-shift error

@kaahos kaahos added test:asan Run CI tests with AddressSanitizer configuration test:tsan Run CI tests with ThreadSanitizer configuration test:fuzz test:reliability labels Oct 9, 2026
@kaahos
kaahos marked this pull request as ready for review October 9, 2026 10:11
@kaahos
kaahos requested a review from a team as a code owner October 9, 2026 10:11
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 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-10-09T10:12:56.423302Z 803e1ed 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.

@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: 803e1edd5a

ℹ️ 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 thread ddprof-lib/src/main/cpp/hotspot/stubUnwindInfo.cpp

@datadog-prod-us1-4 datadog-prod-us1-4 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.

Bits Code Review: PASS

More details

Casting to uint64_t before shifting preserves ADRP page offsets, including negative immediates, while removing the signed-shift undefined behavior.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 803e1ed · @DataDog review to ask questions

@dd-octo-sts

dd-octo-sts Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #37919030165 | Commit: 39510de | Duration: 22m 30s (longest job)

✅ All 76 test jobs passed

Status Overview

JDK glibc-aarch64/asan glibc-aarch64/debug glibc-aarch64/tsan glibc-amd64/asan glibc-amd64/debug glibc-amd64/tsan 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: 76 | Passed: 76 | Failed: 0


Updated: 2026-10-09 11:07:08 UTC

@dd-octo-sts

dd-octo-sts Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ All 40 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 da2494ac

@dd-octo-sts

dd-octo-sts Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Reliability & Chaos Results

✅ All reliability & chaos checks passed Pipeline: https://gitlab.ddbuild.io/DataDog/java-profiler/-/pipelines/143670108

@kaahos
kaahos merged commit e3d4d35 into main Oct 9, 2026
207 checks passed
@kaahos
kaahos deleted the paul.fournillon/fix-adrp-ubsan-left-shift branch October 9, 2026 11:21
@github-actions github-actions Bot added this to the 1.52.0 milestone Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:asan Run CI tests with AddressSanitizer configuration test:fuzz test:reliability test:tsan Run CI tests with ThreadSanitizer configuration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant