Skip to content
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

Loading denied assemblies via Assembly.LoadFrom can cause issues, eg. for VSMac #8726

Closed
radical opened this issue May 16, 2018 · 17 comments · Fixed by #8737
Closed

Loading denied assemblies via Assembly.LoadFrom can cause issues, eg. for VSMac #8726

radical opened this issue May 16, 2018 · 17 comments · Fixed by #8737
Assignees
Labels
area-Runtime: Loader Any assembly loading/binding issue

Comments

@radical
Copy link
Member

radical commented May 16, 2018

Usually, if an assembly depends on a known "bad"(windows specific implementation) assembly then the mono runtime can deny loading
it. But if the load is initiated explicitly like via Assembly.LoadFrom, then the assembly gets loaded (https://github.com/mono/mono/blob/2018-02/mono/metadata/image.c#L1363-L1365)
with a Loading problematic image ....

For example, take System.Runtime.InteropServices.RuntimeInformation.dll. It's RuntimeInformation.IsOSPlatform API's response
depends on what platform it was built was for. So, a windows specific version would return true even it is running on macOS. Normally,
this gets caught and denied loading. But if it is explicitly loaded via Assembly.LoadFrom, then that will break
any subsequent code that depends on that API!

This can show up in VSMac, if some addin loads the bad assembly before the good copy has been loaded into the app domain. Then the
subsequent use of msbuild APIs that depend on IsOSPlatform break:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Microsoft.Build.Collections.MSBuildNameIgnoreCaseComparer' threw an exception. ---> System.EntryPointNotFoundException: GetSystemInfo
  at (wrapper managed-to-native) Microsoft.Build.Shared.NativeMethodsShared.GetSystemInfo(Microsoft.Build.Shared.NativeMethodsShared/SYSTEM_INFO&)

Here the windows specific code path runs on macOS, because of the IsOSPlatform's result!

Related: mono/monodevelop#4788

@radical radical assigned kumpera and lambdageek and unassigned kumpera and lambdageek May 16, 2018
@radical
Copy link
Member Author

radical commented May 16, 2018

@Therzok
Copy link
Contributor

Therzok commented May 16, 2018

Nice find!

@marek-safar marek-safar added the area-Runtime: Loader Any assembly loading/binding issue label May 16, 2018
@marek-safar marek-safar added this to the 2018-04 (5.14.xx) milestone May 16, 2018
@marek-safar
Copy link
Member

@lambdageek did your context load changes fix the problem?

@lambdageek
Copy link
Member

@marek-safar No: the load context work did nothing about "problematic images" - that's an entirely orthogonal concept.

The load context work changes the semantics of Assembly.LoadFrom so that it is now subject to binding redirection via app.config or policy config files, but I don't think that would help here - our System.Runtime.InteropServices.RuntimeInformation.dll has the same version and public key token as the .NET Framework one - binding redirection wouldn't help.


What's not clear to me is what should Assembly.LoadFrom do if you try to open a problematic image?

The simple answer is: fail - in that case we can just drop theif and only keep the else case:

mono/mono/metadata/image.c

Lines 1364 to 1370 in 3d8125e

if (image->load_from_context) {
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY, "Loading problematic image %s", image->name);
} else {
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY, "Denying load of problematic image %s", image->name);
*status = MONO_IMAGE_IMAGE_INVALID;
goto invalid_image;
}

But that will break all callers of Assembly.LoadFrom - like whatever Monodevelop is doing in the bug that @radical mentioned.

A better answer might be - "Assembly.LoadFrom should silently redirect to find our preferred version of the problematic image". That's... doable but messy (because the loader is a mess) I wouldn't want to backport that to an imminent release.

So let me know what it should do.

@mhutch
Copy link
Member

mhutch commented May 16, 2018

Rewinding and adding full context :)

NuGet packagers assume that ".net framework" means "windows", so folks end up with windows-specific assemblies (often transitive dependencies) copied into their output folder without even realizing it, which then breaks on Windows. This is an issue with several very common system.* packages, so we have the Load deny mechanism for these specifically.

The problem in this case is that VSMac uses LoadFrom to load extensions' assemblies, and the deny mechanism only works with Load, not LoadFrom.

I think silently redirecting LoadFrom to load the good variant when an image is denied is entirely reasonable and consistent. This isn't totally general, so scope is limited. It's just swapping out specific known bad assemblies for good replacements that are bundled with Mono.

One could argue that the extensions shouldn't be shipping these assemblies. For the assemblies that are included in MD core that's definitely true, and perhaps VSMac could add special handling to avoid loading them from extensions. However, for assemblies that are not bundled in MD core, the extension needs to bundle them to work on .NET Framework.

I understand the concern about backporting the patch. As a stopgap, we could implement the same blocklist in Mono.Addins so MD doesn't get broken by extensions. We've seen this breakage in the wild with the stable 7.5 release. /cc @slluis.

@lambdageek lambdageek self-assigned this May 16, 2018
lambdageek added a commit to lambdageek/mono that referenced this issue May 17, 2018
The "problematic images" are Windows-specific assemblies that are often
included with applications that do not work on Mono, but for which Mono has its
own implementation.

Previously (9ec8ec5) we changed mono to deny
loading problematic images using Assembly.Load or when one assembly references
another and we find a problematic image using the usual assembly search.

For Assembly.LoadFrom, we used to emit a warning and then load the assembly anyway.

In this commit, we change the behavior: If Assembly.LoadFrom tries to open a
problematic image, we will instead probe for an assembly of that name in the
default context.  That should eventually end up opening Mono's version of that
assembly.

Example:
  Suppose a problematic System.Runtime.InteropServices.RuntimeInformation.dll
  is in the application bin path: /home/user/myapp/bin

  1. User code does (for whatever reason)
  Assembly.LoadFrom ("/home/user/myapp/bin/System.Runtime.InteropServices.RuntimeInformation.dll")

  2. We find the image and try to open it; add it to the images absfpath to
  image hash; note that there are no binding redirects; but that it is a
  problematic image.  We extract the assembly
  name ("System.Runtime.InteropServices.RuntimeInformation", version x.y.z.w
  and public key token 123456789a) from the problematic image.

  3. We probe for "System.Runtime.InteropServices.RuntimeInformation version
  x.y.z.w public key token 123456789a" in the default context.

  4. We find
  /home/user/myapp/bin/System.Runtime.InteropServices.RuntimeInformation.dll in
  the application bin path; we try to open it, we see it's already in the
  images hash, but it's a problematic image,  and we're not in a loadfrom
  context (we re-probed with default!) so we keep probing

  5. We find
  <prefix>/lib/mono/4.5/Facaded/System.Runtime.InteropServices.RuntimeInformation.dll,
  it's not a problematic image, so we open that and return it to (3)

  6. We return to (2) and close the problematic image and return the good one
  instead.

  7. Assembly.LoadFrom returns with the good image.

Fixes mono#8726
@marek-safar
Copy link
Member

@lambdageek I certainly prefer consistent behaviour in this case and we should use same logic as we do when loading the assembly using other API. That leaves use with only reflection context APIs behaving differently but that sounds reasonable to me.

I'd like to see this in 2018-04 because we are still testing the release and we can take it out if necessary. I agree that backporting to earlier versions (15.8 and before) might be problematic but we'd have to find a different workaround in that case.

lambdageek added a commit to lambdageek/mono that referenced this issue May 17, 2018
The "problematic images" are Windows-specific assemblies that are often
included with applications that do not work on Mono, but for which Mono has its
own implementation.

Previously (9ec8ec5) we changed mono to deny
loading problematic images using Assembly.Load or when one assembly references
another and we find a problematic image using the usual assembly search.

For Assembly.LoadFrom, we used to emit a warning and then load the assembly anyway.

In this commit, we change the behavior: If Assembly.LoadFrom tries to open a
problematic image, we will instead probe for an assembly of that name in the
default context.  That should eventually end up opening Mono's version of that
assembly.

Example:
  Suppose a problematic System.Runtime.InteropServices.RuntimeInformation.dll
  is in the application bin path: /home/user/myapp/bin

  1. User code does (for whatever reason)
  Assembly.LoadFrom ("/home/user/myapp/bin/System.Runtime.InteropServices.RuntimeInformation.dll")

  2. We find the image and try to open it; add it to the images absfpath to
  image hash; note that there are no binding redirects; but that it is a
  problematic image.  We extract the assembly
  name ("System.Runtime.InteropServices.RuntimeInformation", version x.y.z.w
  and public key token 123456789a) from the problematic image.

  3. We probe for "System.Runtime.InteropServices.RuntimeInformation version
  x.y.z.w public key token 123456789a" in the default context.

  4. We find
  /home/user/myapp/bin/System.Runtime.InteropServices.RuntimeInformation.dll in
  the application bin path; we try to open it, we see it's already in the
  images hash, but it's a problematic image,  and we're not in a loadfrom
  context (we re-probed with default!) so we keep probing

  5. We find
  <prefix>/lib/mono/4.5/Facaded/System.Runtime.InteropServices.RuntimeInformation.dll,
  it's not a problematic image, so we open that and return it to (3)

  6. We return to (2) and close the problematic image and return the good one
  instead.

  7. Assembly.LoadFrom returns with the good image.

Fixes mono#8726
marek-safar pushed a commit that referenced this issue May 23, 2018
The "problematic images" are Windows-specific assemblies that are often
included with applications that do not work on Mono, but for which Mono has its
own implementation.

Previously (9ec8ec5) we changed mono to deny
loading problematic images using Assembly.Load or when one assembly references
another and we find a problematic image using the usual assembly search.

For Assembly.LoadFrom, we used to emit a warning and then load the assembly anyway.

In this commit, we change the behavior: If Assembly.LoadFrom tries to open a
problematic image, we will instead probe for an assembly of that name in the
default context.  That should eventually end up opening Mono's version of that
assembly.

Example:
  Suppose a problematic System.Runtime.InteropServices.RuntimeInformation.dll
  is in the application bin path: /home/user/myapp/bin

  1. User code does (for whatever reason)
  Assembly.LoadFrom ("/home/user/myapp/bin/System.Runtime.InteropServices.RuntimeInformation.dll")

  2. We find the image and try to open it; add it to the images absfpath to
  image hash; note that there are no binding redirects; but that it is a
  problematic image.  We extract the assembly
  name ("System.Runtime.InteropServices.RuntimeInformation", version x.y.z.w
  and public key token 123456789a) from the problematic image.

  3. We probe for "System.Runtime.InteropServices.RuntimeInformation version
  x.y.z.w public key token 123456789a" in the default context.

  4. We find
  /home/user/myapp/bin/System.Runtime.InteropServices.RuntimeInformation.dll in
  the application bin path; we try to open it, we see it's already in the
  images hash, but it's a problematic image,  and we're not in a loadfrom
  context (we re-probed with default!) so we keep probing

  5. We find
  <prefix>/lib/mono/4.5/Facaded/System.Runtime.InteropServices.RuntimeInformation.dll,
  it's not a problematic image, so we open that and return it to (3)

  6. We return to (2) and close the problematic image and return the good one
  instead.

  7. Assembly.LoadFrom returns with the good image.

Fixes #8726
marek-safar pushed a commit that referenced this issue May 23, 2018
The "problematic images" are Windows-specific assemblies that are often
included with applications that do not work on Mono, but for which Mono has its
own implementation.

Previously (9ec8ec5) we changed mono to deny
loading problematic images using Assembly.Load or when one assembly references
another and we find a problematic image using the usual assembly search.

For Assembly.LoadFrom, we used to emit a warning and then load the assembly anyway.

In this commit, we change the behavior: If Assembly.LoadFrom tries to open a
problematic image, we will instead probe for an assembly of that name in the
default context.  That should eventually end up opening Mono's version of that
assembly.

Example:
  Suppose a problematic System.Runtime.InteropServices.RuntimeInformation.dll
  is in the application bin path: /home/user/myapp/bin

  1. User code does (for whatever reason)
  Assembly.LoadFrom ("/home/user/myapp/bin/System.Runtime.InteropServices.RuntimeInformation.dll")

  2. We find the image and try to open it; add it to the images absfpath to
  image hash; note that there are no binding redirects; but that it is a
  problematic image.  We extract the assembly
  name ("System.Runtime.InteropServices.RuntimeInformation", version x.y.z.w
  and public key token 123456789a) from the problematic image.

  3. We probe for "System.Runtime.InteropServices.RuntimeInformation version
  x.y.z.w public key token 123456789a" in the default context.

  4. We find
  /home/user/myapp/bin/System.Runtime.InteropServices.RuntimeInformation.dll in
  the application bin path; we try to open it, we see it's already in the
  images hash, but it's a problematic image,  and we're not in a loadfrom
  context (we re-probed with default!) so we keep probing

  5. We find
  <prefix>/lib/mono/4.5/Facaded/System.Runtime.InteropServices.RuntimeInformation.dll,
  it's not a problematic image, so we open that and return it to (3)

  6. We return to (2) and close the problematic image and return the good one
  instead.

  7. Assembly.LoadFrom returns with the good image.

Fixes #8726
@marek-safar
Copy link
Member

@lambdageek how confident are you to landing this to 2018-02?

lambdageek added a commit to lambdageek/mono that referenced this issue May 23, 2018
The "problematic images" are Windows-specific assemblies that are often
included with applications that do not work on Mono, but for which Mono has its
own implementation.

Previously (9ec8ec5) we changed mono to deny
loading problematic images using Assembly.Load or when one assembly references
another and we find a problematic image using the usual assembly search.

For Assembly.LoadFrom, we used to emit a warning and then load the assembly anyway.

In this commit, we change the behavior: If Assembly.LoadFrom tries to open a
problematic image, we will instead probe for an assembly of that name in the
default context.  That should eventually end up opening Mono's version of that
assembly.

Example:
  Suppose a problematic System.Runtime.InteropServices.RuntimeInformation.dll
  is in the application bin path: /home/user/myapp/bin

  1. User code does (for whatever reason)
  Assembly.LoadFrom ("/home/user/myapp/bin/System.Runtime.InteropServices.RuntimeInformation.dll")

  2. We find the image and try to open it; add it to the images absfpath to
  image hash; note that there are no binding redirects; but that it is a
  problematic image.  We extract the assembly
  name ("System.Runtime.InteropServices.RuntimeInformation", version x.y.z.w
  and public key token 123456789a) from the problematic image.

  3. We probe for "System.Runtime.InteropServices.RuntimeInformation version
  x.y.z.w public key token 123456789a" in the default context.

  4. We find
  /home/user/myapp/bin/System.Runtime.InteropServices.RuntimeInformation.dll in
  the application bin path; we try to open it, we see it's already in the
  images hash, but it's a problematic image,  and we're not in a loadfrom
  context (we re-probed with default!) so we keep probing

  5. We find
  <prefix>/lib/mono/4.5/Facaded/System.Runtime.InteropServices.RuntimeInformation.dll,
  it's not a problematic image, so we open that and return it to (3)

  6. We return to (2) and close the problematic image and return the good one
  instead.

  7. Assembly.LoadFrom returns with the good image.

Fixes mono#8726
@lambdageek
Copy link
Member

@marek-safar I think it's probably worth backporting. It's not too disruptive. #8845

@lambdageek
Copy link
Member

We had to revert the fix for this issue on 2018-06 and 2018-04. It's fixed on master (need at least 60f06e6 to both fix this issue and also not break MSBuild).

@lambdageek lambdageek reopened this Jun 15, 2018
@mhutch
Copy link
Member

mhutch commented Jun 15, 2018

@lambageek is that a temporary revert or do we need to think about alternative workarounds for MD running on those releases?

/cc @slluis

@lambdageek
Copy link
Member

lambdageek commented Jun 15, 2018

@mhutch The main motivation for the reverts was to unblock XI and XA moving to 2018-04 and to re-enable nightly CI builds of the MDK. The corrected fix for 2018-06 is in PR #9170. I'm going to do the 2018-04 updated PR imminently. The corrected 2018-04 fix is in #9171

@lambdageek
Copy link
Member

Ok, this should be fixed (again) on 2018-04 (commit f22c8b7) and 2018-06 (commit 9ec4d30).

Closing.

@Therzok
Copy link
Contributor

Therzok commented Jun 26, 2018

What about 2018-02 (5.12 series)?

@lambdageek
Copy link
Member

We can do a backport to 2018-02, but it is unlikely to make it into any stable release.

@slluis
Copy link
Member

slluis commented Jun 28, 2018

@lambdageek why not? 2018-02 is part of the 15.8 release.

@lambdageek
Copy link
Member

@slluis @Therzok Was this a regression?

Backport for 2018-02 is at #9367

/cc @luhenry

@Therzok
Copy link
Contributor

Therzok commented Jul 4, 2018

Our MSBuild builder just started crashing, so yes, it was a regression.

jonpryor pushed a commit to dotnet/android that referenced this issue Aug 8, 2018
Fixes: #1130
Fixes: #1561 (comment)
Fixes: #1845
Fixes: #1951

Context: https://bugzilla.xamarin.com/show_bug.cgi?id=10087
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=11771
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=12850
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=18941
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=19436
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=25444
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=33208
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=58413
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=59184
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=59400
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=59779
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=60065
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=60843
Context: mono/mono#6174
Context: mono/mono#6178
Context: mono/mono#6180
Context: mono/mono#6181
Context: mono/mono#6186
Context: mono/mono#6187
Context: mono/mono#6211
Context: mono/mono#6266
Context: mono/mono#6579
Context: mono/mono#6666
Context: mono/mono#6752
Context: mono/mono#6801
Context: mono/mono#6812
Context: mono/mono#6848
Context: mono/mono#6940
Context: mono/mono#6948
Context: mono/mono#6998
Context: mono/mono#6999
Context: mono/mono#7016
Context: mono/mono#7085
Context: mono/mono#7086
Context: mono/mono#7095
Context: mono/mono#7134
Context: mono/mono#7137
Context: mono/mono#7145
Context: mono/mono#7184
Context: mono/mono#7240
Context: mono/mono#7262
Context: mono/mono#7289
Context: mono/mono#7338
Context: mono/mono#7356
Context: mono/mono#7364
Context: mono/mono#7378
Context: mono/mono#7389
Context: mono/mono#7449
Context: mono/mono#7460
Context: mono/mono#7535
Context: mono/mono#7536
Context: mono/mono#7537
Context: mono/mono#7565
Context: mono/mono#7588
Context: mono/mono#7596
Context: mono/mono#7610
Context: mono/mono#7613
Context: mono/mono#7620
Context: mono/mono#7624
Context: mono/mono#7637
Context: mono/mono#7655
Context: mono/mono#7657
Context: mono/mono#7661
Context: mono/mono#7685
Context: mono/mono#7696
Context: mono/mono#7729
Context: mono/mono#7786
Context: mono/mono#7792
Context: mono/mono#7805
Context: mono/mono#7822
Context: mono/mono#7828
Context: mono/mono#7860
Context: mono/mono#7864
Context: mono/mono#7903
Context: mono/mono#7920
Context: mono/mono#8089
Context: mono/mono#8143
Context: mono/mono#8267
Context: mono/mono#8311
Context: mono/mono#8340
Context: mono/mono#8409
Context: mono/mono#8417
Context: mono/mono#8430
Context: mono/mono#8698
Context: mono/mono#8701
Context: mono/mono#8712
Context: mono/mono#8721
Context: mono/mono#8726
Context: mono/mono#8866
Context: mono/mono#9023
Context: mono/mono#9031
Context: mono/mono#9033
Context: mono/mono#9044
Context: mono/mono#9179
Context: mono/mono#9318
Context: mono/mono#9318
Context: xamarin/maccore#628
Context: xamarin/maccore#629
Context: xamarin/maccore#673
jonpryor pushed a commit to dotnet/android that referenced this issue Aug 13, 2018
Fixes: #1130
Fixes: #1561 (comment)
Fixes: #1845
Fixes: #1951

Context: https://bugzilla.xamarin.com/show_bug.cgi?id=10087
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=11771
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=12850
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=18941
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=19436
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=25444
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=33208
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=58413
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=59184
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=59400
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=59779
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=60065
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=60843
Context: mono/mono#6174
Context: mono/mono#6178
Context: mono/mono#6180
Context: mono/mono#6181
Context: mono/mono#6186
Context: mono/mono#6187
Context: mono/mono#6211
Context: mono/mono#6266
Context: mono/mono#6579
Context: mono/mono#6666
Context: mono/mono#6752
Context: mono/mono#6801
Context: mono/mono#6812
Context: mono/mono#6848
Context: mono/mono#6940
Context: mono/mono#6948
Context: mono/mono#6998
Context: mono/mono#6999
Context: mono/mono#7016
Context: mono/mono#7085
Context: mono/mono#7086
Context: mono/mono#7095
Context: mono/mono#7134
Context: mono/mono#7137
Context: mono/mono#7145
Context: mono/mono#7184
Context: mono/mono#7240
Context: mono/mono#7262
Context: mono/mono#7289
Context: mono/mono#7338
Context: mono/mono#7356
Context: mono/mono#7364
Context: mono/mono#7378
Context: mono/mono#7389
Context: mono/mono#7449
Context: mono/mono#7460
Context: mono/mono#7535
Context: mono/mono#7536
Context: mono/mono#7537
Context: mono/mono#7565
Context: mono/mono#7588
Context: mono/mono#7596
Context: mono/mono#7610
Context: mono/mono#7613
Context: mono/mono#7620
Context: mono/mono#7624
Context: mono/mono#7637
Context: mono/mono#7655
Context: mono/mono#7657
Context: mono/mono#7661
Context: mono/mono#7685
Context: mono/mono#7696
Context: mono/mono#7729
Context: mono/mono#7786
Context: mono/mono#7792
Context: mono/mono#7805
Context: mono/mono#7822
Context: mono/mono#7828
Context: mono/mono#7860
Context: mono/mono#7864
Context: mono/mono#7903
Context: mono/mono#7920
Context: mono/mono#8089
Context: mono/mono#8143
Context: mono/mono#8267
Context: mono/mono#8311
Context: mono/mono#8340
Context: mono/mono#8409
Context: mono/mono#8417
Context: mono/mono#8430
Context: mono/mono#8698
Context: mono/mono#8701
Context: mono/mono#8712
Context: mono/mono#8721
Context: mono/mono#8726
Context: mono/mono#8866
Context: mono/mono#9023
Context: mono/mono#9031
Context: mono/mono#9033
Context: mono/mono#9044
Context: mono/mono#9179
Context: mono/mono#9318
Context: mono/mono#9318
Context: xamarin/maccore#628
Context: xamarin/maccore#629
Context: xamarin/maccore#673
jonpryor pushed a commit to dotnet/android that referenced this issue Oct 9, 2018
Bumps to mono/llvm:release_60@117a508c
Bumps to xamarin/xamarin-android-api-compatibility:master@7ccb4802

	$ git diff --shortstat e1af6ea..ab3c897d       # mono
        1443 files changed, 66049 insertions(+), 45745 deletions(-)
	$ git diff --shortstat bdb3a116..117a508c      # llvm
	 26794 files changed, 4110589 insertions(+), 754376 deletions(-)
	$ git diff --shortstat c550d1bd..7ccb4802      # xamarin-android-api-compatibility
	 2 files changed, 16260 insertions(+), 12347 deletions(-)

Incomplete summary of easily `grep`able fixes:

Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=11199
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=19436
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=23668
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=26983
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=33728
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=46917
fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=60065
Fixes: mono/mono#6173
Fixes: mono/mono#6466
Fixes: mono/mono#6647
Fixes: mono/mono#6834
Fixes: mono/mono#7058
Fixes: mono/mono#7137
Fixes: mono/mono#7260
Fixes: mono/mono#7305
Fixes: mono/mono#7402
Fixes: mono/mono#7525
Fixes: mono/mono#7610
Fixes: mono/mono#7649
Fixes: mono/mono#7655
Fixes: mono/mono#7683
Fixes: mono/mono#7685
Fixes: mono/mono#7716
Fixes: mono/mono#7731
Fixes: mono/mono#7785
Fixes: mono/mono#7828
Fixes: mono/mono#7944
Fixes: mono/mono#7947
Fixes: mono/mono#8036
Fixes: mono/mono#8074
Fixes: mono/mono#8089
Fixes: mono/mono#8112
Fixes: mono/mono#8122
Fixes: mono/mono#8143
Fixes: mono/mono#8149
Fixes: mono/mono#8152
Fixes: mono/mono#8175
Fixes: mono/mono#8177
Fixes: mono/mono#8250
Fixes: mono/mono#8267
Fixes: mono/mono#8273
Fixes: mono/mono#8282
Fixes: mono/mono#8310
Fixes: mono/mono#8311
Fixes: mono/mono#8329
Fixes: mono/mono#8340
Fixes: mono/mono#8372
Fixes: mono/mono#8407
Fixes: mono/mono#8409
Fixes: mono/mono#8422
Fixes: mono/mono#8430
Fixes: mono/mono#8439
fixes: mono/mono#8447
Fixes: mono/mono#8469
Fixes: mono/mono#8504
Fixes: mono/mono#8575
Fixes: mono/mono#8597
Fixes: mono/mono#8623
Fixes: mono/mono#8627
Fixes: mono/mono#8698
Fixes: mono/mono#8701
Fixes: mono/mono#8712
Fixes: mono/mono#8721
Fixes: mono/mono#8726
Fixes: mono/mono#8759
Fixes: mono/mono#8787
Fixes: mono/mono#8820
Fixes: mono/mono#8848
Fixes: mono/mono#8866
Fixes: mono/mono#8897
Fixes: mono/mono#8915
Fixes: mono/mono#8970
Fixes: mono/mono#8979
Fixes: mono/mono#9023
Fixes: mono/mono#9031
Fixes: mono/mono#9033
Fixes: mono/mono#9179
Fixes: mono/mono#9234
Fixes: mono/mono#9262
Fixes: mono/mono#9277
Fixes: mono/mono#9318
Fixes: mono/mono#9542
Fixes: mono/mono#9753
Fixes: mono/mono#9839
Fixes: mono/mono#9869
Fixes: mono/mono#9870
Fixes: mono/mono#9943
Fixes: mono/mono#9996
Fixes: mono/mono#10000
Fixes: mono/mono#10303
Fixes: mono/mono#10447
Fixes: mono/mono#10483
Fixes: mono/mono#10488
Fixes: xamarin/maccore#628
Fixes: xamarin/maccore#673
Fixes: #1561 (comment)
Fixes: #1845
Fixes: xamarin/xamarin-macios#4347
Fixes: xamarin/xamarin-macios#4617
Fixes: xamarin/xamarin-macios#4618
picenka21 pushed a commit to picenka21/runtime that referenced this issue Feb 18, 2022
The "problematic images" are Windows-specific assemblies that are often
included with applications that do not work on Mono, but for which Mono has its
own implementation.

Previously (mono/mono@9ec8ec5) we changed mono to deny
loading problematic images using Assembly.Load or when one assembly references
another and we find a problematic image using the usual assembly search.

For Assembly.LoadFrom, we used to emit a warning and then load the assembly anyway.

In this commit, we change the behavior: If Assembly.LoadFrom tries to open a
problematic image, we will instead probe for an assembly of that name in the
default context.  That should eventually end up opening Mono's version of that
assembly.

Example:
  Suppose a problematic System.Runtime.InteropServices.RuntimeInformation.dll
  is in the application bin path: /home/user/myapp/bin

  1. User code does (for whatever reason)
  Assembly.LoadFrom ("/home/user/myapp/bin/System.Runtime.InteropServices.RuntimeInformation.dll")

  2. We find the image and try to open it; add it to the images absfpath to
  image hash; note that there are no binding redirects; but that it is a
  problematic image.  We extract the assembly
  name ("System.Runtime.InteropServices.RuntimeInformation", version x.y.z.w
  and public key token 123456789a) from the problematic image.

  3. We probe for "System.Runtime.InteropServices.RuntimeInformation version
  x.y.z.w public key token 123456789a" in the default context.

  4. We find
  /home/user/myapp/bin/System.Runtime.InteropServices.RuntimeInformation.dll in
  the application bin path; we try to open it, we see it's already in the
  images hash, but it's a problematic image,  and we're not in a loadfrom
  context (we re-probed with default!) so we keep probing

  5. We find
  <prefix>/lib/mono/4.5/Facaded/System.Runtime.InteropServices.RuntimeInformation.dll,
  it's not a problematic image, so we open that and return it to (3)

  6. We return to (2) and close the problematic image and return the good one
  instead.

  7. Assembly.LoadFrom returns with the good image.

Fixes mono/mono#8726


Commit migrated from mono/mono@9ad5255
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Runtime: Loader Any assembly loading/binding issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants