Search code examples
pythonsandboxstatpypy

Is fstat() a safe (sandboxed) operation?


I'm currently writing a Python sandbox using sandboxed PyPy. Basically, the sandbox works by providing a "controller" that maps system library calls to a specified function instead. After following the instructions found at codespeak (which walk through the set up process), I realized that the default controller does not include a replacement for os.fstat(), and therefore crashes when I call open(). Specifically, the included pypy/translator/sandbox/sandlib.py does not contain a definition for do_ll_os__ll_os_fstat.

So far, I've implemented it as:

def do_ll_os__ll_os_fstat(self, fd):
    return os.fstat(fd)

which seems to work fine. Is this safe? Will this create a hole in the sandbox?


Solution

  • The fstat call can reveal certain information which you may or may not want to keep secret. Among other things:

    • Whether two file descriptors are on the same filesystem
    • The block size of the underlying filesystem
    • Numeric UID/GIDs of file owners
    • Modification/access times of files

    However, it will not modify anything, so if you don't mind this (relatively minor) information leak, no problem. You could also alter some of the results to mask information you want to hide (set owner UIDs/GIDs to 0, for example)