remove thread unsafe debug code causing FreeBSD double free panic#18140
Merged
behlendorf merged 1 commit intoopenzfs:masterfrom Jan 21, 2026
Merged
remove thread unsafe debug code causing FreeBSD double free panic#18140behlendorf merged 1 commit intoopenzfs:masterfrom
behlendorf merged 1 commit intoopenzfs:masterfrom
Conversation
Signed-off-by: Alek Pinchuk <apinchuk@axcient.com>
There was a problem hiding this comment.
Pull request overview
This pull request fixes a critical thread-safety bug in FreeBSD's ZFS crypto implementation that could lead to double-free panics. The bug was caused by thread-unsafe debug code in the error path of zio_do_crypt_data() that attempted to save failed decryption buffers to global variables without proper synchronization.
Changes:
- Removed duplicate global variable declarations (
failed_decrypt_bufandfailed_decrypt_size/faile_decrypt_size) - Removed thread-unsafe debug code in the error handling path that caused race conditions leading to double-free panics
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
asomers
approved these changes
Jan 16, 2026
Contributor
asomers
left a comment
There was a problem hiding this comment.
Could probably be fixed with an atomic pointer swap. But removing it looks good to me too. I don't think it's needed.
behlendorf
approved these changes
Jan 20, 2026
amotin
pushed a commit
to amotin/zfs
that referenced
this pull request
Jan 29, 2026
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alan Somers <asomers@gmail.com> Signed-off-by: Alek Pinchuk <apinchuk@axcient.com> Closes openzfs#18140
mcmilk
pushed a commit
to mcmilk/zfs
that referenced
this pull request
Jan 31, 2026
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alan Somers <asomers@gmail.com> Signed-off-by: Alek Pinchuk <apinchuk@axcient.com> Closes openzfs#18140
amotin
pushed a commit
to amotin/zfs
that referenced
this pull request
Feb 3, 2026
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alan Somers <asomers@gmail.com> Signed-off-by: Alek Pinchuk <apinchuk@axcient.com> Closes openzfs#18140
amotin
pushed a commit
to amotin/zfs
that referenced
this pull request
Feb 3, 2026
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alan Somers <asomers@gmail.com> Signed-off-by: Alek Pinchuk <apinchuk@axcient.com> Closes openzfs#18140
lundman
pushed a commit
to openzfsonosx/openzfs-fork
that referenced
this pull request
Feb 5, 2026
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alan Somers <asomers@gmail.com> Signed-off-by: Alek Pinchuk <apinchuk@axcient.com> Closes openzfs#18140
tonyhutter
pushed a commit
that referenced
this pull request
Feb 5, 2026
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alan Somers <asomers@gmail.com> Signed-off-by: Alek Pinchuk <apinchuk@axcient.com> Closes #18140
tonyhutter
pushed a commit
to tonyhutter/zfs
that referenced
this pull request
Feb 12, 2026
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alan Somers <asomers@gmail.com> Signed-off-by: Alek Pinchuk <apinchuk@axcient.com> Closes openzfs#18140
lundman
pushed a commit
to openzfsonwindows/openzfs
that referenced
this pull request
Feb 23, 2026
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alan Somers <asomers@gmail.com> Signed-off-by: Alek Pinchuk <apinchuk@axcient.com> Closes openzfs#18140
lundman
pushed a commit
to openzfsonwindows/openzfs
that referenced
this pull request
Feb 23, 2026
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alan Somers <asomers@gmail.com> Signed-off-by: Alek Pinchuk <apinchuk@axcient.com> Closes openzfs#18140
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.
Motivation and Context
While attempting to teach scrub to do a "thorough" scrub where it decompresses and decrypts scrubbed blocks #17630, I encountered a reproducible panic. It turns out that in FreeBSD, a ZFS crypto function
zio_do_crypt_data()includes thread-unsafe code in an error path, which can lead to a double-free panic.Description
If ZFS attempts to decrypt data and decryption fails, the code enters an error-handling path. In
module/os/freebsd/zfs/zio_crypt.c, this error path contains thread-unsafe debug logic that attempts to save the failed decryption buffer to a global variable (failed_decrypt_buf) without any locking.With multiple threads encountering errors concurrently, this can lead to a race condition where multiple threads attempt to free the same global pointer, resulting in a duplicate-free panic with the following stack trace:
This patch removes the thread-unsafe debug logic to prevent this panic.
How Has This Been Tested?
I've tested this by running the reproducing workload again after the patch was implemented, and the panic was successfully avoided.
I've also run the zfs-tests suite with good results.
Types of changes
Checklist:
Signed-off-by.