cmd/ztest: avoid PATH_MAX stack allocation in ztest_get_zdb_bin() (#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 commit is contained in:
Alexander Moch 2025-12-29 19:16:34 +00:00 committed by GitHub
parent f041375b52
commit e72f3054e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7144,6 +7144,7 @@ static void
ztest_get_zdb_bin(char *bin, int len)
{
char *zdb_path;
char *resolved;
/*
* Try to use $ZDB and in-tree zdb path. If not successful, just
* let popen to search through PATH.
@ -7157,7 +7158,11 @@ ztest_get_zdb_bin(char *bin, int len)
return;
}
VERIFY3P(realpath(getexecname(), bin), !=, NULL);
resolved = realpath(getexecname(), NULL);
VERIFY3P(resolved, !=, NULL);
strlcpy(bin, resolved, len);
free(resolved);
if (strstr(bin, ".libs/ztest")) {
strstr(bin, ".libs/ztest")[0] = '\0'; /* In-tree */
strcat(bin, "zdb");