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

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.

@hadoop-yetus

Copy link
Copy Markdown

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 1m 2s 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 46m 25s trunk passed
+1 💚 compile 5m 9s trunk passed with JDK Red Hat, Inc.-21.0.12.1+1-LTS
+1 💚 compile 5m 12s trunk passed with JDK Red Hat, Inc.-17.0.20.1+1-LTS
+1 💚 mvnsite 1m 55s trunk passed
+1 💚 shadedclient 90m 7s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 3m 51s the patch passed
+1 💚 compile 3m 50s the patch passed with JDK Red Hat, Inc.-21.0.12.1+1-LTS
+1 💚 cc 3m 50s the patch passed
+1 💚 golang 3m 50s the patch passed
+1 💚 javac 3m 50s the patch passed
+1 💚 compile 3m 56s the patch passed with JDK Red Hat, Inc.-17.0.20.1+1-LTS
+1 💚 cc 3m 56s the patch passed
+1 💚 golang 3m 56s the patch passed
+1 💚 javac 3m 56s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 mvnsite 0m 35s the patch passed
+1 💚 shadedclient 28m 10s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 10m 32s hadoop-hdfs-native-client in the patch passed.
+1 💚 asflicense 1m 1s The patch does not generate ASF License warnings.
146m 25s
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8739/2/artifact/out/Dockerfile
GITHUB PR #8739
Optional Tests dupname asflicense compile cc mvnsite javac unit codespell detsecrets golang
uname Linux fc1b76b34ccc 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 / 65a4e7b
Default Java Red Hat, Inc.-17.0.20.1+1-LTS
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-21.0.12.1.1-1.1.el8_10.x86_64:Red Hat, Inc.-21.0.12.1+1-LTS /usr/lib/jvm/java-17-openjdk-17.0.20.1.1-1.1.el8_10.x86_64:Red Hat, Inc.-17.0.20.1+1-LTS
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8739/2/testReport/
Max. process+thread count 609 (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/2/console
versions git=2.43.7 maven=3.9.15
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

@hadoop-yetus

Copy link
Copy Markdown

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 1m 0s 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 35m 41s trunk passed
+1 💚 compile 3m 45s trunk passed
+1 💚 mvnsite 0m 50s trunk passed
+1 💚 shadedclient 69m 14s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 3m 13s the patch passed
+1 💚 compile 3m 14s the patch passed
+1 💚 cc 3m 14s the patch passed
+1 💚 golang 3m 14s the patch passed
+1 💚 javac 3m 14s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 mvnsite 0m 20s the patch passed
+1 💚 shadedclient 28m 2s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 9m 44s hadoop-hdfs-native-client in the patch passed.
+1 💚 asflicense 0m 35s The patch does not generate ASF License warnings.
118m 16s
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8739/2/artifact/out/Dockerfile
GITHUB PR #8739
Optional Tests dupname asflicense compile cc mvnsite javac unit codespell detsecrets golang
uname Linux b43163fc52d2 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 65a4e7b
Default Java Debian-25.0.4.1+1-1-deb13u1-Debian
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8739/2/testReport/
Max. process+thread count 604 (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/2/console
versions git=2.47.3 maven=3.9.15
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

@hadoop-yetus

Copy link
Copy Markdown

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 1m 1s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 1s 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 20s trunk passed
+1 💚 compile 4m 2s trunk passed with JDK Ubuntu-21.0.12+8-1-24.04-Ubuntu
+1 💚 compile 4m 16s trunk passed with JDK Ubuntu-17.0.20+8-1-24.04-Ubuntu
+1 💚 mvnsite 0m 56s trunk passed
+1 💚 shadedclient 81m 20s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 3m 12s the patch passed
+1 💚 compile 3m 11s the patch passed with JDK Ubuntu-21.0.12+8-1-24.04-Ubuntu
+1 💚 cc 3m 11s the patch passed
+1 💚 golang 3m 11s the patch passed
+1 💚 javac 3m 11s the patch passed
+1 💚 compile 3m 11s the patch passed with JDK Ubuntu-17.0.20+8-1-24.04-Ubuntu
+1 💚 cc 3m 11s the patch passed
+1 💚 golang 3m 11s the patch passed
+1 💚 javac 3m 11s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 mvnsite 0m 20s the patch passed
+1 💚 shadedclient 27m 27s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 9m 52s hadoop-hdfs-native-client in the patch passed.
+1 💚 asflicense 0m 34s The patch does not generate ASF License warnings.
133m 11s
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8739/2/artifact/out/Dockerfile
GITHUB PR #8739
Optional Tests dupname asflicense compile cc mvnsite javac unit codespell detsecrets golang
uname Linux 50bd8f98415b 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 / 65a4e7b
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/2/testReport/
Max. process+thread count 636 (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/2/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.

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