HDFS-16021. heap-use-after-free in hdfsThreadDestructor - #8739
Open
aajisaka wants to merge 2 commits into
Open
Conversation
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)
ayushtkn
self-requested a review
September 13, 2026 05:49
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
💔 -1 overall
This message was automatically generated. |
ayushtkn
approved these changes
Sep 14, 2026
ayushtkn
left a comment
Member
There was a problem hiding this comment.
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
Member
Author
I had disabled GitHub Actions in my fork. I enabled it and now it's running. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.
LICENSE,LICENSE-binary,NOTICE-binaryfiles?AI Tooling
If an AI tool was used:
where is the name of the AI tool used.
https://www.apache.org/legal/generative-tooling.html