Repository navigation
Make ilverify respect IgnoresAccessChecksToAttribute - #130978
JulieLeeMSFT with Copilot wants to merge 3 commits into
Conversation
|
Azure Pipelines: 15 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Co-authored-by: JulieLeeMSFT <63486087+JulieLeeMSFT@users.noreply.github.com>
Co-authored-by: JulieLeeMSFT <63486087+JulieLeeMSFT@users.noreply.github.com>
|
The test can be in C# but using separate ref and impl assemblies differing by member accessibility, it might be cleaner that way. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib |
| var currentTypeDef = (MetadataType)currentClass.GetTypeDefinition(); | ||
| var targetTypeDef = (EcmaType)targetClass.GetTypeDefinition(); | ||
|
|
||
| // The accessing assembly can waive all access checks to the target assembly via [IgnoresAccessChecksTo]. |
There was a problem hiding this comment.
This is very rare case - check of last resort, and it is somewhat expensive due to custom attribute lookup and parsing. It should be done last when all other ways to prove accessibility failed.
There was a problem hiding this comment.
Does ILVerify performance matter to this extent? I'd have assumed the overhead to be fine enough for it.
There was a problem hiding this comment.
It is also about matching the runtime behavior. Runtime checks both IgnoresAccessChecksTo and InternalsVisibleTo attributes last. It is not obvious that checking this attribute first is going to match the runtime behavior in all cases.
|
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
ilverifyonly honoredInternalsVisibleToAttributefor cross-assembly access checks, so IL that legitimately accesses another assembly's internal/private members via[assembly: IgnoresAccessChecksTo("...")]was incorrectly reported as invalid. This alignsilverifywith CoreCLR runtime behavior, where an assembly declaringIgnoresAccessChecksTomay bypass all access checks (private, family, assembly) to the named target — stronger thanInternalsVisibleTo.Changes
AccessVerificationHelpers.csIgnoresAccessChecksTo(this ModuleDesc accessing, ModuleDesc accessed)which decodesSystem.Runtime.CompilerServices.IgnoresAccessChecksToAttributeon the accessing assembly and matches the accessed assembly by simple name — mirroring the runtime'sFriendAssemblyDescriptor::IsAssemblyOnList/RefMatchesDef(name-only match when the declared name omits a public key token).CanAccess(after the generic-instantiation checks, so third-assembly instantiation arguments are still validated) and inCanAccessMember, covering type, method, and field access.Tests — new
AccessTestsIgnoreChecks.il/.ilprojtest assembly declaring[IgnoresAccessChecksTo("AccessTests")](defining the attribute type itself, as real consumers likeIgnoresAccessChecksToGeneratordo), with 11 cases exercising private/family/assembly classes, nested types, methods, and fields. Confirmed the cases fail without the fix and pass with it.