-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix stack overflow protection mechanism #553
Fix stack overflow protection mechanism #553
Conversation
src/tbb/global_control.cpp
Outdated
ULONG_PTR hi, lo; | ||
GetCurrentThreadStackLimits(&lo, &hi); | ||
return std::size_t(hi - lo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To support Windows 7, consider using NtCurrentTeb
to query StackLimit
from NT_TIB
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it seems we can emulate GetCurrentThreadStackLimits
via TIB
, we should use DeallocationStack
(not
StackLimit
) for the real stack address. The implementation GetCurrentThreadStackLimits
does the same (x64 implementation):
mov r8,qword ptr gs:[30h] // get TIB
mov rax,qword ptr [r8+1478h] // TIB + 1478h is DeallocationStack
mov qword ptr [rcx],rax // return LowLimit
mov rax,qword ptr [r8+8] // TIB + 8h is StackBase
mov qword ptr [rdx],rax // return HighLimit
ret
So, on x86_32 the DeallocationStack
offset will be another and it seems the current approach is the lesser of two evils.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had no crashes on tests on Windows 7 (x86 and x64) after applying this patch.
The simple 1 MB limit works in all my Windows 7 environments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ULONG_PTR hi, lo; | |
GetCurrentThreadStackLimits(&lo, &hi); | |
return std::size_t(hi - lo); | |
ULONG_PTR hi, lo; | |
GetCurrentThreadStackLimits(&lo, &hi); | |
return static_cast<std::size_t>(hi - lo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe type cast is not needed here at whole, but if you wish...
Is there any progress? |
Thank you for the reminder, unfortunately, there is no any progress. |
Signed-off-by: Alexei Katranov <alexei.katranov@intel.com>
Co-authored-by: Anton Potapov <anton.potapov@intel.com>
Signed-off-by: Alexei Katranov <alexei.katranov@intel.com>
0a6f3f8
to
384fc99
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The stack size is incorrectly supposed to be 4 MB on Windows. However, MSDN states that "The default stack reservation size used by the linker is 1 MB". It leads to two issues:
The fix changes the assumption to 1 MB on Windows. If compiled with modern Windows, the system API is used to query stack size instead of the assumption.