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

+27 -15
View File
@@ -31,7 +31,7 @@ static int store_root(char *out, size_t size) {
return n > 0 && (size_t)n < size ? n : -1;
}
static int store_exists(void) {
static __attribute__((noinline)) int store_exists(void) {
char root[PATH_MAX];
if (store_seen) return 1;
@@ -223,10 +223,18 @@ int fremovexattr(int fd, const char *name) {
return 0;
}
static int watched(void) {
int saved = errno, found;
found = dd_is_wineserver() && store_exists();
errno = saved;
return found;
}
static int tracked(const char *path, char *out, size_t size) {
int saved = errno, found;
found = dd_is_wineserver() && store_exists() && resolved(path, out, size) == 0;
found = resolved(path, out, size) == 0;
errno = saved;
return found;
}
@@ -258,22 +266,30 @@ static void follow(const char *from, const char *to) {
errno = saved;
}
__attribute__((visibility("hidden")))
int dd_descriptor_unlink(const char *path, int (*real)(const char *)) {
static __attribute__((noinline)) int removed(const char *path, int (*real)(const char *), int folder) {
char target[PATH_MAX];
int known = tracked(path, target, sizeof(target)), result = real(path);
if (result == 0 && known) forget(target, 0);
if (result == 0 && known) forget(target, folder);
return result;
}
static __attribute__((noinline)) int moved(const char *from, const char *to, int (*real)(const char *, const char *)) {
char old[PATH_MAX], new[PATH_MAX];
int known = tracked(from, old, sizeof(old)), result = real(from, to);
if (result == 0 && known && tracked(to, new, sizeof(new))) follow(old, new);
return result;
}
__attribute__((visibility("hidden")))
int dd_descriptor_rmdir(const char *path, int (*real)(const char *)) {
char target[PATH_MAX];
int known = tracked(path, target, sizeof(target)), result = real(path);
int dd_descriptor_unlink(const char *path, int (*real)(const char *)) {
return watched() ? removed(path, real, 0) : real(path);
}
if (result == 0 && known) forget(target, 1);
return result;
__attribute__((visibility("hidden")))
int dd_descriptor_rmdir(const char *path, int (*real)(const char *)) {
return watched() ? removed(path, real, 1) : real(path);
}
__attribute__((visibility("hidden")))
@@ -283,9 +299,5 @@ int dd_descriptor_remove(const char *path, int (*real)(const char *)) {
__attribute__((visibility("hidden")))
int dd_descriptor_rename(const char *from, const char *to, int (*real)(const char *, const char *)) {
char old[PATH_MAX], new[PATH_MAX];
int known = tracked(from, old, sizeof(old)), result = real(from, to);
if (result == 0 && known && tracked(to, new, sizeof(new))) follow(old, new);
return result;
return watched() ? moved(from, to, real) : real(from, to);
}