cms-dev / cms-dev/cms

Sandbox does not restrict file access and execution

Open
#376 9 comments 1 reaction 0 assignees View on GitHub

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 restrict writing to local files and allows access to a large part of the directory tree, in particular everything in /usr/. Here are some examples how this can be exploited:

  • In the Batch task type (but not restricted to Batch), linking the solution file to the output file can trick the system.

    #include <unistd.h>
    int main() {
      return symlink("output.txt", "res.txt");
    }
    

    When res.txt gets copied to the sandbox directory, it overwrites the output.txt file. This can be fixed in Sandbox.py, see this patch for a possible fix. I have not checked if this fix breaks other task types, but those who are, are vulnerable to this attack anyway. Whitelisting files as proposed in #309 would also work.

    This is also a privilege escalation, because the path linked to does not need to exist. It is perfectly fine to link to /tmp/i_was_here (or any other path) and the EvaluationService process will happily write to that file.

  • Execute installed binaries and load installed libraries. For example, running a Python interpreter from C, even if Python is not an allowed language:

    #include <unistd.h>
    static const char *code = "print(eval('+'.join(raw_input().split())))";
    int main() {
      return execl("/usr/bin/python2", "/usr/bin/python2", "-S", "-c", code, NULL);
    }
    

    This is possible because execl does not start a new process, it just replaces the old one.

    On a similar note, one could submit a source file that contains a Base64-encoding of a binary file that makes use of "unallowed features" such as being compiling with -O3 or -pthread, using a bigint library -lgmp or similar. This data can be written to a file and executed like above.

  • Access to all header files in /usr/include. This is more of a gray zone. Is it allowed to #include <boost/graph/dijkstra_shortest_paths.hpp>? While those files should not be available in the first place, it would be nice to be able to whitelist only the standard library headers and their dependencies for compiling.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Sandbox.py and the Batch task path described in the issue, then trace how files are copied and how EvaluationService launches submissions. Review the linked patch and issue #309 for the proposed approaches. Done means submissions cannot overwrite or write arbitrary files, access unintended system paths, or execute unallowed binaries and libraries across task types.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
operating-systems, security
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.