-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A potential out-of-bound read in RuntimeInvokeHostAssemblyResolver
#104466
Comments
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov |
I saw this was to improve the name validation for reflection dynamic assemblies. FYI, I also encountered same kind of confusion exception saying name isn't match when I try to reproduce with |
…Assembly to ensure type safety Fixes dotnet#104466
Description
In
AssemblyLoadContext
, there is a check to avoid the loaded assembly to be reflection emitted assembly. However, the native code checking this seems to be contains a potential out-of-bound memory read, caused by the mismatching betweenRuntimeAssembly
andRuntimeAssemblyBuilder
.Here is the code analysis:
runtime/src/coreclr/vm/appdomain.cpp
Lines 4546 to 4548 in 0dac635
This code here
_gcRefs.oRefLoadedAssembly
could be returned fromAssemblyLoadContext.Load
which is controlled by user, so_gcRefs.oRefLoadedAssembly
of typeAssembly
could actually beRuntimeAssemblyBuilder
.But
->GetDomainAssembly()
access offset 0x20 of theAssembly
object, whereRuntimeAssemblyBuilder
has only a size of 0x20(don't count header). So access domain assembly onRuntimeAssemblyBuilder
cause it reads the end of the objects, which normally is the header of_internalAssembly
ofRuntimeAssemblyBuilder
, but potentially be any object's header or even something else if a GC happens between this lines code.If that happens, following access of
DomainAssembly
causes a memory access violation.runtime/src/coreclr/vm/appdomain.cpp
Lines 4551 to 4558 in 0dac635
Reproduction Steps
Result:
Expected behavior
The check within
RuntimeInvokeHostAssemblyResolver
should aware that_gcRefs.oRefLoadedAssembly
could be any type inherited fromAssembly
Actual behavior
Code in
RuntimeInvokeHostAssemblyResolver
assume_gcRefs.oRefLoadedAssembly
to beRuntimeAssembly
or has a simlar memory layout.Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: