sio2project / sio2jail

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

Add rules for `mmap` and `dup` #41

Open MasloMaslane opened 7 months ago

MasloMaslane commented 7 months ago

Now mmap is allowed to read only from fd > 2, and dup isn't allowed to use fd < 3

Wolf480pl commented 7 months ago

I wonder if we should add tests for this kinda stuff

MasloMaslane commented 7 months ago

Ughh, Python for some reason dups file descriptors 0-2, so the tests fail (for example test/src/sum_python3.9.py)

MasloMaslane commented 7 months ago

And when dup returns EACCES, python fails with runtime error 1

Wolf480pl commented 7 months ago

Looks like Python 3.9 in its infinite wisdom uses dup to check if an FD is valid.

https://github.com/python/cpython/blob/v3.9.18/Python/pylifecycle.c#L1735-L1765

Looks like they changed it to fcntl in 3.11 and later https://github.com/python/cpython/commit/f87ea0350286837e9e96de03f8bfa215176c2928

But if python 3.9 specifically is used in some contests then we can't drop support for that by forbidding dup....

MasloMaslane commented 7 months ago

OIJ and Szkopuł use python3.9, so I guess for now we have to allow mmap for fd < 3