Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mono]: Add PLT entry index validation mode for MONO_ARCH_CODE_EXEC_O…
…NLY. (dotnet#75464) * Add plt entry index validation mode for MONO_ARCH_CODE_EXEC_ONLY. When running with MONO_ATCH_CODE_EXEC_ONLY PLT entry index can't be read from call site (code only marked for execute), instead index is loaded into RAX and then used by patch trampolines. It is important that sequences of trampolines leading up to plt patch call won't clobber RAX, or it will cause incorrect patching with very hard to debug side effects. One such scenario was hit and solved by dotnet#70449 and to automatically detect these errors, this fix adds ability to validate that the index put into RAX has not been clobbered when hitting plt patch location. Fix adds a mode under MONO_ARCH_CODE_EXEC_ONLY define: MONO_VALIDATE_PLT_ENTRY_INDEX That will always load the index using full 64-bit RAX, were both lower and upper 32-bit is a copy of the index, and then AOT compiler will xor the complete 64-bit value with a xor key. At runtime, the plt patch logic could then validate that the value in RAX appears to be the anticipated index, by reverse the process and then compare the upper 32-bit with the lower 32-bit and if they don't match, assert. It is very unlikely that a random change of value in RAX would pass this test. The issue hitting dotnet#70449 was run using validation mode, and the assert trapped the error with the incorrect sequence of trampolines, directly pin point the issue to the location of the error, instead of patching wrong method in wrong plt slot leading to complete random behaviour later in execution when code would call through the incorrect patched plt.
- Loading branch information