From cce74266d1176c10c3339bff168d384b7285e2e8 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Fri, 16 Jul 2021 14:56:33 +0200 Subject: [PATCH] Fix UMEntryThunkCache::GetUMEntryThunk The function was initializing UMThunkMarshInfo allocated from Stub heap without using the ExecutableWriterHolder. That causes a crash when a hosting application calls coreclr_create_delegate. This was discovered in .NET 6 Preview 6 when running a xamarin app that uses a special host. This code path is exercised only by coreclr_create_delegate. --- src/coreclr/vm/dllimportcallback.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/dllimportcallback.cpp b/src/coreclr/vm/dllimportcallback.cpp index 4f3cf879d10a4..11b63fa999992 100644 --- a/src/coreclr/vm/dllimportcallback.cpp +++ b/src/coreclr/vm/dllimportcallback.cpp @@ -163,7 +163,8 @@ UMEntryThunk *UMEntryThunkCache::GetUMEntryThunk(MethodDesc *pMD) Holder miHolder; miHolder.Assign(pMarshInfo); - pMarshInfo->LoadTimeInit(pMD); + ExecutableWriterHolder marshInfoWriterHolder(pMarshInfo, sizeof(UMThunkMarshInfo)); + marshInfoWriterHolder.GetRW()->LoadTimeInit(pMD); ExecutableWriterHolder thunkWriterHolder(pThunk, sizeof(UMEntryThunk)); thunkWriterHolder.GetRW()->LoadTimeInit(pThunk, NULL, NULL, pMarshInfo, pMD);