[PATCH] Cygwin: Fixing the math behind rounding down ch.stacklimit to page size

Sergejs Lukanihins slukanihin@gmail.com
Fri May 25 16:43:00 GMT 2018


Looks like ch.stacklimit wasn't being page-aligned correctly in
fork.cc; you need to subtract 1 from page_size to do it correctly (see
the attached patch).

As a result, this was causing stack-overflow exceptions whenever the
stack needed to grow beyond the stacklimit value. When the stack grows
beyond stacklimit value, Windows uses ntdll!_chkstk() function to
check the stack and map in additional stack pages. However, it expects
stacklimit to be page aligned, and the function does not work
correctly if it is not (it triggers STATUS_STACK_OVERFLOW, even if
there is enough stack space).

Normally, this was not causing any issues, as the stack never really
needs to grow, but it was causing issues when AV software was being
injected into the process (specifically, HitmanPro.Alert being
injected into git’s sh.exe process). Due to function hooks, it lead to
a bigger callstack, and more stack space being required. Making the
change specified in the patch actually resolves the issue.

I am providing my patches to the Cygwin sources under the 2-clause BSD license.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Cygwin-Fixing-the-math-behind-rounding-down-ch.stack.patch
Type: application/octet-stream
Size: 1043 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20180525/35ad3a8b/attachment.obj>

More information about the Cygwin-patches mailing list