Delegate to a dynamic method created from another dynamic method does not gc-reference the target method - by atykhyy

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


0
0
Sign in
to vote
ID 389514 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 12/24/2008 12:13:05 AM
Access Restriction Public

Description

When a dynamic method creates a delegate targeting a different dynamic method using the delegate's constructor, the new delegate works, but it's internal _methodBase field is null. As a result, the delegate does not gc-reference the target dynamic method. If the dynamic method is garbage-collected and its memory overwritten before it is invoked, various bugs and crashes result, the commonest of them being Access Violation (0xc0000005) in mscorwks.dll.

The attached sample demonstrates this issue and workaround.

NB: this issue is found in .NET 2.0, 3.5, 3.5 SP1.
Sign in to post a comment.
Posted by Microsoft on 2/16/2009 at 10:45 AM
After careful consideration, we decided that this is a known limitation. And since you can only do this with DynamicILInfo which requires full trust, this is not a security hole. If we decide to enalbe this scenario for ILGenerator we will certainly need to fix this GC hole.

Thanks for your feedback!
Posted by atykhyy on 1/5/2009 at 6:38 AM
Update: if the code in mscorwks which compiles dynamic methods is fully-trusted, this issue might be a potential security hole, since it's possible to use dynamic methods in a restricted environment. Exploit method would be similar to well-known methods used with heap corruption bugs.
Posted by Microsoft on 12/24/2008 at 6:40 PM
Thanks for your feedback.

We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you,
Visual Studio Product Team