Skip to content

HDFS-16021. heap-use-after-free in hdfsThreadDestructor - #8739

Open
aajisaka wants to merge 2 commits into
apache:trunkfrom
aajisaka:HDFS-16021
Open

HDFS-16021. heap-use-after-free in hdfsThreadDestructor#8739
aajisaka wants to merge 2 commits into
apache:trunkfrom
aajisaka:HDFS-16021

Conversation

@aajisaka

Copy link
Copy Markdown
Member

Description of PR

libhdfs registers a pthread TLS destructor, hdfsThreadDestructor, that detaches the current thread from the JVM whenever it finds a cached JNIEnv. It does so regardless of who attached the thread. When the JVM (or an embedding application) attached the thread, the JNIEnv it still holds may already have been freed by the time the destructor runs, so dereferencing it reads freed memory (heap-use-after-free, SIGSEGV).

Track in ThreadLocalState whether libhdfs attached the thread itself, determined in getGlobalJNIEnv via GetEnv before attaching, and skip the JNI detach in hdfsThreadDestructor for threads libhdfs did not attach.

The original patch is authored by Jeremy Coulon.
Assisted-by: OpenCode (GLM-5.3-Flash)

JIRA: HDFS-16021

How was this patch tested?

The same fix is reviewed in Apache DataFusion Comet side: apache/datafusion-comet#5890

For code changes:

  • Does the title of this PR start with the corresponding JIRA issue id (e.g. 'HADOOP-17799. Your PR title ...')?
  • Object storage: Have the integration tests been executed and the endpoint
    declared according to the connector-specific documentation? Note: Automated CI
    testing doesn't cover all cases so manual testing with cloud storage is still
    required.
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE, LICENSE-binary, NOTICE-binary files?

AI Tooling

If an AI tool was used:

libhdfs registers a pthread TLS destructor, hdfsThreadDestructor, that
detaches the current thread from the JVM whenever it finds a cached
JNIEnv.  It does so regardless of who attached the thread.  When the
JVM (or an embedding application) attached the thread, the JNIEnv it
still holds may already have been freed by the time the destructor
runs, so dereferencing it reads freed memory (heap-use-after-free,
SIGSEGV).

Track in ThreadLocalState whether libhdfs attached the thread itself,
determined in getGlobalJNIEnv via GetEnv before attaching, and skip
the JNI detach in hdfsThreadDestructor for threads libhdfs did not
attach.

Contributed-by: Jeremy Coulon
Assisted-by: OpenCode (GLM-5.3-Flash)

@peterxcli peterxcli 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.

LGTM thanks! 🚀

@ayushtkn
ayushtkn self-requested a review September 13, 2026 05:49
@hadoop-yetus

This comment was marked as outdated.

@hadoop-yetus

This comment was marked as outdated.

@hadoop-yetus

Copy link
Copy Markdown

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 1m 3s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
-1 ❌ test4tests 0m 0s The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.
_ trunk Compile Tests _
+1 💚 mvninstall 36m 11s trunk passed
+1 💚 compile 3m 39s trunk passed with JDK Ubuntu-21.0.12+8-1-24.04-Ubuntu
+1 💚 compile 3m 41s trunk passed with JDK Ubuntu-17.0.20+8-1-24.04-Ubuntu
+1 💚 mvnsite 0m 51s trunk passed
+1 💚 shadedclient 73m 48s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 3m 10s the patch passed
+1 💚 compile 3m 10s the patch passed with JDK Ubuntu-21.0.12+8-1-24.04-Ubuntu
+1 💚 cc 3m 10s the patch passed
+1 💚 golang 3m 10s the patch passed
+1 💚 javac 3m 10s the patch passed
+1 💚 compile 3m 13s the patch passed with JDK Ubuntu-17.0.20+8-1-24.04-Ubuntu
+1 💚 cc 3m 13s the patch passed
+1 💚 golang 3m 13s the patch passed
+1 💚 javac 3m 13s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 mvnsite 0m 18s the patch passed
+1 💚 shadedclient 27m 7s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 9m 54s hadoop-hdfs-native-client in the patch passed.
+1 💚 asflicense 0m 35s The patch does not generate ASF License warnings.
125m 16s
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8739/1/artifact/out/Dockerfile
GITHUB PR #8739
Optional Tests dupname asflicense compile cc mvnsite javac unit codespell detsecrets golang
uname Linux 8c219e44ea42 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / f9aaa3a
Default Java Ubuntu-17.0.20+8-1-24.04-Ubuntu
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.12+8-1-24.04-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.20+8-1-24.04-Ubuntu
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8739/1/testReport/
Max. process+thread count 633 (vs. ulimit of 10000)
modules C: hadoop-hdfs-project/hadoop-hdfs-native-client U: hadoop-hdfs-project/hadoop-hdfs-native-client
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8739/1/console
versions git=2.43.0 maven=3.9.15
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

@ayushtkn ayushtkn 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.

LGTM

I am not sure what is this failure being referenced here: https://github.com/apache/hadoop/pull/8739/checks?check_run_id=103675831551

Please check once on those before merging

@aajisaka

aajisaka commented Sep 14, 2026

Copy link
Copy Markdown
Member Author

I am not sure what is this failure being referenced here: https://github.com/apache/hadoop/pull/8739/checks?check_run_id=103675831551

I had disabled GitHub Actions in my fork. I enabled it and now it's running.

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.

4 participants