sio2project / sio2jail

A tool for supervising execution of programs submitted in algorithmic competitions
MIT License
29 stars 10 forks source link

Fixed memory limit bypass using mremap #42

Closed mikimasn closed 5 months ago

mikimasn commented 5 months ago

Due to MemoryLimitListener only validating memory usage on mmap it was possible to use mremap to bypass memory limit.

Wolf480pl commented 5 months ago

Have you managed to actually bypass memory limit with it?

AFAIU your VmPeak would still exceed the limit after your program exits, so sio2jail would count that as MLE. The only concern is that a big mremap could file due to the rlimit, so unless the program handles memory allocation failure correctly (most programs don't), it'd result in a different error (most likely segfault, abort, or non-zero exit, possibly also wrong answer) that wouldn't communicate that the memory limit was the root cause, which could cause confusion.

Your PR didn't look quite right, but I think the overall direction was good. I can review it and give you a detailed feedback, if you want to continue working on it. I think after some small improvements this could be merged.

Also, why did you close it?

mikimasn commented 5 months ago

I closed it because I didn't bypass the memory limit.

I assumed there exists a default memory limit because my attempt to simply mmap table with size 1e7 failed with memory limit exceeded but an attempt to mmap with size 1e6 succeeded. About 20 minutes after submitting the PR I realized my mistake and decided to close the PR because it was invalid.

I would like to continue with PR(but under another, valid name) and fix a bug that at the beginning resulted in a memory limit exceeded error while running my program without any memory limit.

mikimasn commented 5 months ago

I opened new PR #43