Skip to content

cmd/ztest: avoid PATH_MAX stack allocation in ztest_get_zdb_bin()#18085

Merged
tonyhutter merged 1 commit into
openzfs:masterfrom
alex-moch:stack-frame
Dec 29, 2025
Merged

cmd/ztest: avoid PATH_MAX stack allocation in ztest_get_zdb_bin()#18085
tonyhutter merged 1 commit into
openzfs:masterfrom
alex-moch:stack-frame

Conversation

@alex-moch
Copy link
Copy Markdown
Contributor

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.


Motivation and Context

When building on Alpine Linux with fortified headers, the compiler emits a warning:

cmd/ztest.c: In function 'ztest_get_zdb_bin.constprop':
cmd/ztest.c:7168:1: warning: the frame size of 4256 bytes is larger than 4096 bytes [-Wframe-larger-than=]
 7168 | }
      | ^

This occurs because the fortified realpath(path, buf) wrapper allocates a PATH_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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Quality assurance (non-breaking change which makes the code more robust against bugs)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

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>
@tonyhutter tonyhutter merged commit e72f305 into openzfs:master Dec 29, 2025
40 of 42 checks passed
@alex-moch alex-moch deleted the stack-frame branch December 29, 2025 19:56
@behlendorf behlendorf added the Status: Accepted Ready to integrate (reviewed, tested) label 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Accepted Ready to integrate (reviewed, tested)

3 participants