Skip to content

Commit 5695a8a

Browse files
Constellationpgorszkowski-igalia
authored andcommitted
[JSC] Opportunistically exclude environment variable from stack scanning on Linux
https://bugs.webkit.org/show_bug.cgi?id=289774 rdar://147017776 Reviewed by Justin Michaud. As it is suggested in https://webkit.slack.com/archives/CTV4FGWF4/p1737380355218399, we should leverage Linux's ELF loader's stack setup mechanism to exclude environment variables from the stack. * Source/WTF/wtf/StackBounds.cpp: (WTF::StackBounds::currentThreadStackBoundsInternal): Canonical link: https://commits.webkit.org/292171@main
1 parent 4b3faa7 commit 5695a8a

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

Source/WTF/wtf/StackBounds.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,19 @@ StackBounds StackBounds::currentThreadStackBoundsInternal()
132132
// account for a guard page
133133
size -= static_cast<rlim_t>(sysconf(_SC_PAGESIZE));
134134
void* bound = static_cast<char*>(origin) - size;
135-
return StackBounds { origin, bound };
135+
136+
static char** oldestEnviron = environ;
137+
138+
// In 32bit architecture, it is possible that environment variables are having a characters which looks like a pointer,
139+
// and conservative GC will find it as a live pointer. We would like to avoid that to precisely exclude non user stack
140+
// data region from this stack bounds. As the article (https://lwn.net/Articles/631631/) and the elf loader implementation
141+
// explain how Linux main thread stack is organized, environment variables vector is placed on the stack, so we can exclude
142+
// environment variables if we use `environ` global variable as a origin of the stack.
143+
// But `setenv` / `putenv` may alter `environ` variable's content. So we record the oldest `environ` variable content, and use it.
144+
StackBounds stackBounds { origin, bound };
145+
if (stackBounds.contains(oldestEnviron))
146+
stackBounds = { oldestEnviron, bound };
147+
return stackBounds;
136148
}
137149
#endif
138150
return ret;

0 commit comments

Comments
 (0)