Open adv-sw opened 5 years ago
I think I've found the exact place to make a hacky version of this for the JIT/AOT backend. Interpreter would need it's own thing. Confirming now.
The proper place to do this is probably an IL preprocessor, not the runtime.
I agree with @vargaz there that the highest quality way to surface this would be through the linker or something.
You can always break that though using SRE, so you need some kind of assertion at the very least.
Looks like you can filter here on the assembly that method
belong to:
--- a/mono/mini/method-to-ir.c
+++ b/mono/mini/method-to-ir.c
@@ -7053,6 +7053,10 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
} else if (fsig->pinvoke) {
MonoMethod *wrapper = mono_marshal_get_native_wrapper (cmethod, TRUE, cfg->compile_aot);
fsig = mono_method_signature_internal (wrapper);
+
+ if (m_class_get_image (method->klass) != mono_defaults.corlib)
+ g_error (stderr, "JIT-making a call to %s from %s %s\n", cmethod->name, m_class_get_image (method->klass)->assembly_name, method->name);
+
} else if (constrained_class) {
} else {
fsig = mono_method_get_signature_checked (cmethod, image, token, generic_context, &cfg->error);
(END)
Which means that this mode would amount to:
Thanks guys. Appreciate the prompt attention you've given this.
Is extending this whitelist to block any other form of unsafe operation straightforward enough ?
If so, please add that to the spec.
Configuration on a per MonoDomain basis please. That delivers maximum flexibility without hopefully complicating anything. Thanks again, appreciating the rapid turnaround on this.
@adv-sw the question of how to expose the option to the end user is going to be 90% of the labor, if my triage of it seems accurate. How do you hope to use this?
We're developing a 3D web browser with mono/.net assembly as secure scripting engine, moving to web assembly at some point.
By default third party scripts will be secure - no p/invoke. no unsafe. Our bootstrap will be trusted & will be able to p/invoke as required for managed wrapper pattern. Hence whitelist required.
End users will be able to trust third party scripts to perform unsafe operations in the same way they can trust unmanaged code plugins if they want to, but they'll have to opt into this - globally or on a case by case basis, via UI that we'll provide.
We're new so we don't have legacy install bases that'll break. You'll have to leave safe mode turned off by default for existing apps so they don't break & their developers will have to enable & integrate as they see fit going forwards.
Hope that answers the question. We need mono secure to use it as a next-gen web scripting engine. The web is secure by default.
I intend to integrate the moment you have a working build I can compile, so you'll gain immediate feedback as to whether the solution we seek has been delivered.
Once again, sincere thanks.
I think it makes sense then to add this as a configure flag that disables it by default, and then have a short list of allowed images.
I would do this:
This ensures that the method doesn't compile. If it doesn't compile, it can't run You mean from the intermediate language I assume. Other compilers can compile to intermediate without the safeguard you propose otherwise.
Logging should be an exception so runtime can know assembly wanted to do something it's blocked from doing so app can inform user "app tried to do x do you want to let it" or similar.
System overview : [native_app] <---> [trusted custom managed bootstrap assembly] <---> [untrusted managed app assemblies]
There should be a white list of assemblies which can p/invoke which should initially be configured to be all trusted system assemblies, which can be amended under C API control to configure mono runtime as desired.
Current Behavior: All assemblies can make p/invoke calls.
Expected Behavior: When running in secure mode, only trusted assemblies should be able to make p/invoke calls.
Assembly format feature required on :
.NET assemblies. Web Assembly.
Platforms : All.
Version: Feature not yet present.
As discussed on https://gitter.im/mono/mono today (11th June, 2019).