fix(ddsession): keep path and status buffers off the wrapper fast path (#3071)

dd_descriptor_unlink, dd_descriptor_rmdir and dd_descriptor_rename put
one or two PATH_MAX buffers on their own frame (12 KB, 24 KB), and
dd_status_without_tracer put its 16 KB status buffer there, even on the
common path that only calls through to libc. Threads with small stacks,
such as .NET or Wine threads near their guard page, could overflow in
an otherwise plain unlink, rename or open.

The wrappers now do only the cheap checks and call the real function;
the buffers live in noinline helpers that run only when the descriptor
store or the status rewrite is actually needed. A test compiles both
sources with -fstack-usage and keeps each wrapper frame under 1 KB.

Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
MaxsTechReviewandKurt Himebauch authored and GitHub committed 2026-11-24 17:19:24 -05:00
1 parent 7d942367fd
commit 7630173b24
3 files changed
+74 -19

No files matched your search

+8 -4
View File
@@ -72,15 +72,12 @@ static int read_only_copy(const char *data, size_t len, int flags) {
return ro;
}
__attribute__((visibility("hidden"))) int dd_status_without_tracer(const char *path, int flags, const void *caller) {
static __attribute__((noinline)) int status_copy(const char *path, int flags, long pid) {
char text[STATUS_MAX];
size_t len = 0;
int saved = errno;
int out = -1;
long pid;
if ((flags & O_ACCMODE) != O_RDONLY || (pid = status_pid(path)) < 0 || is_web_helper(caller) || dd_from_ntdll(caller))
return -1;
// through the next open(): the native userland's hook gives the app's ids as root's there
static int (*next_open)(const char *, int, ...) = NULL;
if (!next_open) next_open = (int (*)(const char *, int, ...))dlsym(RTLD_NEXT, "open");
@@ -116,3 +113,10 @@ done:
errno = saved;
return out;
}
__attribute__((visibility("hidden"))) int dd_status_without_tracer(const char *path, int flags, const void *caller) {
long pid;
if ((flags & O_ACCMODE) != O_RDONLY || (pid = status_pid(path)) < 0 || is_web_helper(caller) || dd_from_ntdll(caller))
return -1;
return status_copy(path, flags, pid);
}