Skip to content

[fault-injection] Unprotected access to JVM class loader data mutex and method list#678

Draft
zhengyu123 wants to merge 1 commit into
mainfrom
zgu/unprotected_cld_mutex
Draft

[fault-injection] Unprotected access to JVM class loader data mutex and method list#678
zhengyu123 wants to merge 1 commit into
mainfrom
zgu/unprotected_cld_mutex

Conversation

@zhengyu123

Copy link
Copy Markdown
Contributor

What does this PR do?:

Motivation:

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 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: [JIRA-XXXX]

Unsure? Have a question? Request a review!

Copilot AI review requested due to automatic review settings July 21, 2026 15:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens HotSpot ClassLoaderData interactions for fault-injection scenarios by moving offset-based reads behind centralized helpers, adding an RAII mutex locker, and switching selected field reads to SafeAccess to avoid crashes outside longjmp-protected regions.

Changes:

  • Refactored VMStructs::at() into vmStructs.inline.h and introduced VMStructs::load_at_offset() to support SafeAccess-based pointer loads.
  • Added VMClassLoaderDataMutexLocker (RAII) and updated the JDK-8062116 workaround path to use it instead of manual lock/unlock.
  • Added SafeAccess-protected accessors for VMClassLoaderData::mutex() / methodList() (but current API/usage is inconsistent and needs follow-up).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
ddprof-lib/src/main/cpp/hotspot/vmStructs.inline.h Defines VMStructs::at()/load_at_offset() and adds SafeAccess-based ClassLoaderData field loads.
ddprof-lib/src/main/cpp/hotspot/vmStructs.h Declares the new access helpers and introduces VMClassLoaderDataMutexLocker + updated ClassLoaderData accessor signatures.
ddprof-lib/src/main/cpp/hotspot/vmStructs.cpp Implements VMClassLoaderDataMutexLocker constructor/destructor.
ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Switches ClassLoaderData patching to RAII locking and updated method-list handling (currently does not type-check with new accessor signature).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +631 to +635
class VMClassLoaderDataMutexLocker : protected VMStructs {
private:
void* mutex() {
return *(void**) at(sizeof(uintptr_t) * 3);
}

void* _mutex;
public:
void lock() {
_lock_func(mutex());
}

void unlock() {
_unlock_func(mutex());
}
VMClassLoaderDataMutexLocker(void* mutex);
Comment on lines +1169 to +1179
VMClassLoaderDataMutexLocker::VMClassLoaderDataMutexLocker(void* mutex) : _mutex(mutex) {
if (_mutex != nullptr) {
_lock_func(_mutex);
}
}

VMClassLoaderDataMutexLocker::~VMClassLoaderDataMutexLocker() {
if (_mutex != nullptr) {
_unlock_func(_mutex);
}
}
Comment on lines +1267 to 1270
VMClassLoaderDataMutexLocker locker(cld->mutex());
for (int i = 0; i < method_count; i += MethodList::SIZE) {
*cld->methodList() = new MethodList(*cld->methodList());
*cld->methodList() = new MethodList(cld->methodList());
}
Comment on lines +214 to +221
// ClassLoaderData accesses are unprotected
void* VMClassLoaderData::mutex() {
return load_at_offset<void*, true /*safe*/>(sizeof(uintptr_t) * 3);
}

MethodList* VMClassLoaderData::methodList() {
return load_at_offset<MethodList*, true /*safe*/>(sizeof(uintptr_t) * 6 + 8);
}
@dd-octo-sts

dd-octo-sts Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #29842352361 | Commit: 2610a3f | Duration: 14m 33s (longest job)

4 of 32 test jobs failed

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

Failed Tests

musl-amd64/debug / 8-librca

Job: View logs

No detailed failure information available. Check the job logs.

musl-aarch64/debug / 8-librca

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 8-orcl

Job: View logs

No detailed failure information available. Check the job logs.

glibc-amd64/debug / 8

Job: View logs

No detailed failure information available. Check the job logs.

Summary: Total: 32 | Passed: 28 | Failed: 4


Updated: 2026-07-21 15:32:01 UTC

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Jul 21, 2026

Copy link
Copy Markdown

Tests

🔄 Datadog auto-retried 3 jobs - 0 passed on retry View in Datadog

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 6b61672 | Docs | Datadog PR Page | Give us feedback!

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.

2 participants