From d8d1cf2e35d674502bfa2512ded21f7f9b421318 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Sat, 16 Apr 2016 22:45:16 +0200 Subject: [PATCH] Added patch to trigger stack overflow exception earlier on x86_64. --- ...ack-overflow-exception-earlier-on-x8.patch | 29 +++++++++++++++++++ patches/ntdll-Stack_Overflow/definition | 1 + patches/patchinstall.sh | 16 ++++++++++ 3 files changed, 46 insertions(+) create mode 100644 patches/ntdll-Stack_Overflow/0001-ntdll-Trigger-stack-overflow-exception-earlier-on-x8.patch create mode 100644 patches/ntdll-Stack_Overflow/definition diff --git a/patches/ntdll-Stack_Overflow/0001-ntdll-Trigger-stack-overflow-exception-earlier-on-x8.patch b/patches/ntdll-Stack_Overflow/0001-ntdll-Trigger-stack-overflow-exception-earlier-on-x8.patch new file mode 100644 index 00000000..7ae36d89 --- /dev/null +++ b/patches/ntdll-Stack_Overflow/0001-ntdll-Trigger-stack-overflow-exception-earlier-on-x8.patch @@ -0,0 +1,29 @@ +From a679044828d05cd420b1fb4a0dc43fb49da8d665 Mon Sep 17 00:00:00 2001 +From: Sebastian Lackner +Date: Sat, 16 Apr 2016 22:29:12 +0200 +Subject: ntdll: Trigger stack overflow exception earlier on x86_64. + +The Cygwin/MSYS2 exception handler seems to exceed one page, +which breaks handling of stack faults. +--- + dlls/ntdll/signal_x86_64.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c +index 94157bb..81d1758 100644 +--- a/dlls/ntdll/signal_x86_64.c ++++ b/dlls/ntdll/signal_x86_64.c +@@ -2600,8 +2600,9 @@ static void segv_handler( int signal, siginfo_t *siginfo, void *sigcontext ) + virtual_handle_stack_fault( siginfo->si_addr )) + { + /* check if this was the last guard page */ +- if ((char *)siginfo->si_addr < (char *)NtCurrentTeb()->DeallocationStack + 2*4096) ++ if ((char *)siginfo->si_addr < (char *)NtCurrentTeb()->DeallocationStack + 3*4096) + { ++ virtual_handle_stack_fault( (char *)siginfo->si_addr - 4096 ); + rec = setup_exception( sigcontext, raise_segv_exception ); + rec->ExceptionCode = EXCEPTION_STACK_OVERFLOW; + } +-- +2.7.1 + diff --git a/patches/ntdll-Stack_Overflow/definition b/patches/ntdll-Stack_Overflow/definition new file mode 100644 index 00000000..0099150c --- /dev/null +++ b/patches/ntdll-Stack_Overflow/definition @@ -0,0 +1 @@ +Fixes: Trigger stack overflow exception earlier on x86_64 diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh index 07413ef5..cc90a780 100755 --- a/patches/patchinstall.sh +++ b/patches/patchinstall.sh @@ -224,6 +224,7 @@ patch_enable_all () enable_ntdll_RtlIpStringToAddress_Tests="$1" enable_ntdll_RtlQueryPackageIdentity="$1" enable_ntdll_Serial_Port_Detection="$1" + enable_ntdll_Stack_Overflow="$1" enable_ntdll_Status_Mapping="$1" enable_ntdll_Syscall_Wrappers="$1" enable_ntdll_SystemInterruptInformation="$1" @@ -846,6 +847,9 @@ patch_enable () ntdll-Serial_Port_Detection) enable_ntdll_Serial_Port_Detection="$2" ;; + ntdll-Stack_Overflow) + enable_ntdll_Stack_Overflow="$2" + ;; ntdll-Status_Mapping) enable_ntdll_Status_Mapping="$2" ;; @@ -5032,6 +5036,18 @@ if test "$enable_ntdll_Serial_Port_Detection" -eq 1; then ) >> "$patchlist" fi +# Patchset ntdll-Stack_Overflow +# | +# | Modified files: +# | * dlls/ntdll/signal_x86_64.c +# | +if test "$enable_ntdll_Stack_Overflow" -eq 1; then + patch_apply ntdll-Stack_Overflow/0001-ntdll-Trigger-stack-overflow-exception-earlier-on-x8.patch + ( + echo '+ { "Sebastian Lackner", "ntdll: Trigger stack overflow exception earlier on x86_64.", 1 },'; + ) >> "$patchlist" +fi + # Patchset ntdll-Status_Mapping # | # | Modified files: