Sandbox does not set file size limit
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1k
- Forks
- 412
- Avg merge
- 6d 10h
- Merged PRs (30d)
- 3
Description
The sandbox does not set a limit on the size of the files created by the solution. This can lead to various problems.
- Causing an out-of-memory situation for the worker, if the sandboxes are kept in a big enough tmpfs (which happens in a lot of distributions that mount a tmpfs in /tmp).
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#define BS 8192
int main() {
int fd = open("output.txt", O_CREAT | O_WRONLY | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
char buf[BS] = {};
while(1)
write(fd, buf, BS);
}
- Allowing the user to somewhat bypass memory limits by creating a big file, then mmapping parts of it and using it as extra memory.
- Leaving a very big output.txt file, causing the worker to fail if there is no space left on the device, or to eat up a lot of memory (~4 times the size of the file). Using fallocate allows a program to allocate a lot of space in a very short time. For example, the following program
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
int main() {
int fd = open("output.txt", O_CREAT | O_WRONLY | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
fallocate(fd, 0, 0, 10*1024*1024*1024l);
}
takes only two seconds to complete on my computer and creates a 10GB file.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the sandbox implementation and its existing resource-limit handling, then use the two C reproductions in the issue to verify unbounded writes and fallocate-based allocation. Done means sandbox-created files have a defined size limit and these cases can no longer exhaust worker memory or disk space.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, python
- Domain
- operating-systems, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100