Disallow thread creation in AppDomain

I installed a small example when I loaded the assembly into a new AppDomain without permission. This works great, the assembly cannot access the file system and cannot listen to sockets.

But there is one more thing I want to prevent: creating a theme. What for? Theoretically, theoretically, this assembly can create a thread that creates even more threads and floods my memory.

I thought of (in my opinion) the best way: AppDomain memory limitation. Is it possible? And if not, what can I do to avoid creating threads?

This code is used to create a stream.

Thread t = new Thread(this.DoWork); t.Start(); 

And this code is for AppDomain

  PermissionSet set = new PermissionSet(PermissionState.None); set.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution)); set.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery, this.path)); AppDomainSetup info = new AppDomainSetup { ApplicationBase = this.path }; this.domain = AppDomain.CreateDomain("Sandbox", null, info, set, null); 

(Well, I gave access to the file system in the folder where I want to load the assembly, it's just because StrongName fullTrustAssembly = typeof(SecureInstance).Assembly.Evidence.GetHostEvidence<StrongName>(); does not work for me either.

Hope s / o can help. (

+6
source share
1 answer

There seems to be no easy answer for this. What you can do is use the .NET Profiling API to check memory usage in AppDomain. You can learn more about this here, but you will need to do a digging: http://msdn.microsoft.com/en-us/library/bb384493.aspx

In any case, is it not better to run everything that you want to run in a separate process with a lower priority, so if it comes with a wild memory allocation, it does not affect your process, the OS kills it, and it does not affect your main process?

+2
source

Source: https://habr.com/ru/post/904527/


All Articles