cms-dev / isolate

Sandbox for securly executing untrusted programs - DEPRECATED, use: https://github.com/ioi/isolate
47 stars 14 forks source link

Support a soft memory limit for Memory Limit Exceeded errors. #14

Open jamiees2 opened 9 years ago

jamiees2 commented 9 years ago

We required the ability for isolate to result in MLE, instead of either RTE or TLE when it hit a memory cap. We implemented this by adding moreoless the same code as mooshak's safeexec program runs, but adapted to make the most of the functions already in place.

This adds a new parameter --soft-mem which is a memory limit which is not hard; there is more memory available, but it cannot be used. This way the program can actually attempt to allocate more memory, but it is detected and the program is terminated. Just make sure that --mem or --cg-mem is set to something higher if at all.

For this to be added, the wait4 loop had to be changed, so that instead of letting wait4 block execution, a do-while loop with regular sleep intervals handles that.

For getting the current memory usage, the data section of /proc/<pid>/statm is read. That is, the total memory usage of the process is considered to be VmData + VmStk.

Although this is a cap, it is enforced somewhat lightly, and in theory atleast, a program could allocate too much memory in less than 67ms and then immediately exit, therefore bypassing the check. In a contest environment however, this will rarely be the case, and any overflow will be handled by a hard upper limit like --cg-mem.

giomasce commented 9 years ago

Hi.

Thanks for your contibution and sorry for the long delay before replaying.

Since at the moment this feature is not required in CMS and we do not like very much the polling mechanism, we are not including in our repository for now.