cmd/ztest: avoid PATH_MAX stack allocation in ztest_get_zdb_bin()#18085
Merged
Conversation
Calling realpath(path, buf) can trigger fortified header wrappers that allocate a PATH_MAX-sized temporary buffer on the stack, exceeding the 4 KiB frame limit on some systems. Use the heap-allocating realpath(path, NULL) form instead. Sponsored-by: ERNW Research GmbH - https://ernw-research.de/ Signed-off-by: Alexander Moch <amoch@ernw.de>
14 tasks
behlendorf
approved these changes
Dec 27, 2025
tonyhutter
approved these changes
Dec 29, 2025
mcmilk
pushed a commit
to mcmilk/zfs
that referenced
this pull request
Jan 31, 2026
…openzfs#18085) Calling realpath(path, buf) can trigger fortified header wrappers that allocate a PATH_MAX-sized temporary buffer on the stack, exceeding the 4 KiB frame limit on some systems. Use the heap-allocating realpath(path, NULL) form instead. Sponsored-by: ERNW Research GmbH - https://ernw-research.de/ Signed-off-by: Alexander Moch <amoch@ernw.de> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Tony Hutter <hutter2@llnl.gov>
lundman
pushed a commit
to openzfsonosx/openzfs-fork
that referenced
this pull request
Feb 5, 2026
…openzfs#18085) Calling realpath(path, buf) can trigger fortified header wrappers that allocate a PATH_MAX-sized temporary buffer on the stack, exceeding the 4 KiB frame limit on some systems. Use the heap-allocating realpath(path, NULL) form instead. Sponsored-by: ERNW Research GmbH - https://ernw-research.de/ Signed-off-by: Alexander Moch <amoch@ernw.de> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Tony Hutter <hutter2@llnl.gov>
tonyhutter
pushed a commit
to tonyhutter/zfs
that referenced
this pull request
Feb 11, 2026
…openzfs#18085) Calling realpath(path, buf) can trigger fortified header wrappers that allocate a PATH_MAX-sized temporary buffer on the stack, exceeding the 4 KiB frame limit on some systems. Use the heap-allocating realpath(path, NULL) form instead. Sponsored-by: ERNW Research GmbH - https://ernw-research.de/ Signed-off-by: Alexander Moch <amoch@ernw.de> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Tony Hutter <hutter2@llnl.gov>
lundman
pushed a commit
to openzfsonwindows/openzfs
that referenced
this pull request
Feb 23, 2026
…openzfs#18085) Calling realpath(path, buf) can trigger fortified header wrappers that allocate a PATH_MAX-sized temporary buffer on the stack, exceeding the 4 KiB frame limit on some systems. Use the heap-allocating realpath(path, NULL) form instead. Sponsored-by: ERNW Research GmbH - https://ernw-research.de/ Signed-off-by: Alexander Moch <amoch@ernw.de> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Tony Hutter <hutter2@llnl.gov>
lundman
pushed a commit
to openzfsonwindows/openzfs
that referenced
this pull request
Feb 23, 2026
…openzfs#18085) Calling realpath(path, buf) can trigger fortified header wrappers that allocate a PATH_MAX-sized temporary buffer on the stack, exceeding the 4 KiB frame limit on some systems. Use the heap-allocating realpath(path, NULL) form instead. Sponsored-by: ERNW Research GmbH - https://ernw-research.de/ Signed-off-by: Alexander Moch <amoch@ernw.de> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Tony Hutter <hutter2@llnl.gov>
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.
Calling
realpath(path, buf)can trigger fortified header wrappers that allocate aPATH_MAX-sized temporary buffer on the stack, exceeding the 4 KiB frame limit on some systems. Use the heap-allocatingrealpath(path, NULL)form instead.Motivation and Context
When building on Alpine Linux with fortified headers, the compiler emits a warning:
This occurs because the fortified
realpath(path, buf)wrapper allocates aPATH_MAX-sized temporary buffer on the stack (typically 4096 bytes), which when combined with the function's other local variables, exceeds the 4 KiB stack frame limit.Description
This change avoids the fortified wrapper path by using the heap-allocating
realpath(path, NULL)form. The resolved path is copied into the caller-provided buffer and freed immediately.This preserves the existing behavior while avoiding the large temporary stack allocation and keeping the stack frame size below the configured limit.
How Has This Been Tested?
Built on Alpine Linux where the warning was originally observed. The warning no longer appears after this change.
Types of changes
Checklist:
Signed-off-by.