[Mono-dev] Why does Mono's CoreCLR blocks internal method reflection from transparent code ?

nelson nelson.cabral at gmail.com
Sun Mar 24 18:08:59 UTC 2013


I'm checking that code, at
https://github.com/mono/mono/blob/master/mono/metadata/security-core-clr.c.

If to "ensure that the specified method can be used with reflection since
Transparent code cannot call Critical methods" is fine with me, why does
CoreCLR also prevents transparent code to call internal transparent methods
or properties through reflection ?

I'm not a security expert, and am curious to know if removing this check
affects mono clr's security.
I'm comparing the code below to this page about CoreCLR :
http://www.mono-project.com/Moonlight2CoreCLR .

Details : 

/*
 * mono_security_core_clr_ensure_reflection_access_method:
 *
 *  Ensure that the specified method can be used with reflection since
 *  Transparent code cannot call Critical methods and can only call them
 *  if they are visible from it's point of view.
 *
 *  A MethodAccessException is thrown if the field is cannot be accessed.
 */
void
mono_security_core_clr_ensure_reflection_access_method (MonoMethod *method)
{
    MonoMethod *caller = get_reflection_caller ();
    /* CoreCLR restrictions applies to Transparent code/caller */
    if (mono_security_core_clr_method_level (caller, TRUE) !=
MONO_SECURITY_CORE_CLR_TRANSPARENT)
        return;

    if (mono_security_core_clr_get_options () &
MONO_SECURITY_CORE_CLR_OPTIONS_RELAX_REFLECTION) {
        if (!mono_security_core_clr_is_platform_image
(method->klass->image))
            return;
    }

    /* Transparent code cannot invoke, even using reflection, Critical code
*/
    if (mono_security_core_clr_method_level (method, TRUE) ==
MONO_SECURITY_CORE_CLR_CRITICAL) {
        mono_raise_exception (get_method_access_exception (
            "Transparent method %s cannot invoke Critical method %s.", 
            caller, method));
    }

    /* also it cannot invoke a method that is not visible from it's (caller)
point of view */
    if (!check_method_access (caller, method)) {
        mono_raise_exception (get_method_access_exception (
            "Transparent method %s cannot invoke private/internal method
%s.", 
            caller, method));
    }
}

Hope someone can answer me...



--
View this message in context: http://mono.1490590.n4.nabble.com/Why-does-Mono-s-CoreCLR-blocks-internal-method-reflection-from-transparent-code-tp4659140.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list