From 7d152b7bc9a23a96929d818dded0854bcc943aac Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 10 Aug 2020 18:22:13 -0700 Subject: [PATCH] Suppress GS cookie checks in method epilogs (#40637) The information about end of GS cookie scope recorded in GC info is not accurate and it cannot even be made accurate without redesign that is not worth it. Detect end of GS cookie scope by comparing it with current SP instead. Fixes #13041 --- src/coreclr/src/vm/eetwain.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/coreclr/src/vm/eetwain.cpp b/src/coreclr/src/vm/eetwain.cpp index 41008aac175..88ba0a6b6f7 100644 --- a/src/coreclr/src/vm/eetwain.cpp +++ b/src/coreclr/src/vm/eetwain.cpp @@ -5626,11 +5626,14 @@ void * EECodeManager::GetGSCookieAddr(PREGDISPLAY pContext, INT32 spOffsetGSCookie = gcInfoDecoder.GetGSCookieStackSlot(); if (spOffsetGSCookie != NO_GS_COOKIE) { - if(relOffset >= gcInfoDecoder.GetGSCookieValidRangeStart() - && relOffset < gcInfoDecoder.GetGSCookieValidRangeEnd()) + if(relOffset >= gcInfoDecoder.GetGSCookieValidRangeStart()) { - SIZE_T baseStackSlot = GetCallerSp(pContext); - return (LPVOID)( spOffsetGSCookie + baseStackSlot ); + TADDR ptr = GetCallerSp(pContext) + spOffsetGSCookie; + + // Detect the end of GS cookie scope by comparing its address with SP + // gcInfoDecoder.GetGSCookieValidRangeEnd() is not accurate. It does not + // account for GS cookie going out of scope inside epilog or multiple epilogs. + return (LPVOID) ((ptr >= pContext->SP) ? ptr : NULL); } } return NULL; -- 2.34.1