Skip to content

Debugger: Prevent Abort on Invalid Virtual Method #2115

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

Conversation

scott-ferguson-unity
Copy link
Collaborator

If the debugger is asked to invoke an interface or virtual method on a class the mono_object_get_virtual_method_internal will assert & abort (or crash).

mono_object_get_virtual_method_internal assumes that it is being asked to invoke a virtual method on an instance that implements it. If that's not true it will assert & abort or access invalid memory if assertions are disabled.

To protect against this we check if the this_arg can be cast to the interface or base class type. If it can then we should be safe to call mono_object_get_virtual_method_internal.

  • Should this pull request have release notes?
    • Yes
    • No
  • Do these changes need to be back ported?
    • Yes
    • No
  • Do these changes need to be upstreamed to mono/mono or dotnet/runtime repositories?
    • Yes
    • No

Reviewers: please consider these questions as well! ❤️

Release notes

Fixed UUM-97917 @scott-ferguson-unity
Mono: Prevent debugger crash when watching or evaluating an interface property or method without an instance (i.e. nameof(IInterface.Property).

@UnityAlex
Copy link
Collaborator

Were you able to reproduce this issue with the upstream mono in dotnet/runtime? It doesn't look like this change is there so it might be worthwhile upstreaming the change unless they've fixed it in some other way.

@@ -6545,6 +6545,10 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8
PRINT_DEBUG_MSG (1, "[%p] Error: Interface method invoked without this argument.\n", (gpointer) (gsize) mono_native_thread_id_get ());
return ERR_INVALID_ARGUMENT;
}
if (!mono_object_isinst(this_arg, m->klass)) {
PRINT_DEBUG_MSG (1, "[%p] Error: Interface method invoked on object that doesn't implement the interface.\n", (gpointer) (gsize) mono_native_thread_id_get ());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, should the message include more info like type and interface/and method name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches the existing error messages in the file so I'm not planning on changing this.

@scott-ferguson-unity scott-ferguson-unity force-pushed the prevent-abort-when-debugger-invokes-method-on-invalid-type branch from a595a75 to 64d1d37 Compare April 22, 2025 12:03
If the debugger is asked to invoke an interface or virtual
method on a class the mono_object_get_virtual_method_internal
will assert & abort (or crash).

mono_object_get_virtual_method_internal assumes that
it is being asked to invoke a virtual method on an instance
that implements it.  If that's not true it will assert & abort or
access invalid memory if assertions are disabled.

To protect against this we check if the this_arg can be cast to
the interface or base class type.  If it can then we should be
safe to call mono_object_get_virtual_method_internal.
@scott-ferguson-unity scott-ferguson-unity force-pushed the prevent-abort-when-debugger-invokes-method-on-invalid-type branch from 64d1d37 to aa9587d Compare April 23, 2025 15:57
@scott-ferguson-unity scott-ferguson-unity merged commit 7d4005a into unity-main Apr 23, 2025
10 checks passed
@scott-ferguson-unity scott-ferguson-unity deleted the prevent-abort-when-debugger-invokes-method-on-invalid-type branch April 23, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants