Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Landlock support #871

Open
3 of 4 tasks
Xyene opened this issue Aug 28, 2021 · 0 comments
Open
3 of 4 tasks

Landlock support #871

Xyene opened this issue Aug 28, 2021 · 0 comments

Comments

@Xyene
Copy link
Member

Xyene commented Aug 28, 2021

Linux 5.13 introduced a new security subsystem, Landlock, that we can make use of in cptbox for filesystem sandboxing.

Currently, cptbox in the standard configuration makes use of seccomp to whitelist syscalls, and trap into ptrace for syscalls that need either sanitization or unconditional failure with an error code (e.g., socket). The latter can already be done by seccomp; we just don't do so currently out of laziness. Landlock would allow us to drop ptrace entirely, and let the kernel do more of the heavy lifting. A ptrace-less implementation would also remove the need for multiprocessed programs to take a performance hit.

A non-exhaustive checklist of things that need to happen:

  • Filesystem filters need to be rewritten to not use regex. Landlock provides "allow file read" and "allow (recursive) directory read" primitives; these are sufficient for our purposes (and can be converted to regex for the ptrace + seccomp backend). A first step would be to get this working with the ptrace + seccomp backend, before starting work on the Landlock bits.

BASE_FILESYSTEM is currently defined as

BASE_FILESYSTEM = [
    '/dev/(?:null|tty|zero|u?random)$',
    '/usr/(?!home)',
    '/lib(?:32|64)?/',
    '/opt/',
    '/etc$',
    '/etc/(?:localtime|timezone)$',
    '/usr$',
    '/tmp$',
    '/$',
]

A Landlock-friendly version could look something like

BASE_FILESYSTEM = Root((
    Dir("usr", (
        Self(),
        *(Dir(d, (All(),)) for d in os.listdir("/usr") if d != "home")
    )),
    Dir("tmp", (Self(),)),
    Dir("etc", (
        Self(),
        File("localtime"),
        File("timezone"),
    )),
    Dir("dev", (
        File("null"),
        File("tty"),
        File("zero"),
        File("urandom"),
        File("random"),
    )),
    Dir("lib", (All(),))
    Dir("lib32", (All(),))
    Dir("lib64", (All(),))
    Dir("opt", (All(),))
))

These objects should support composition:

a = Root((
    Dir("etc", (
        File("nsswitch.conf")))))
b = Root((
    Dir("etc", (
        File("passwd")))))
a + b

should be equivalent to

Root((
    Dir("etc", (
        File("nsswitch.conf"),
        File("passwd")))))
  • Drop support DMOJ_USE_SECCOMP=no, and clean up any fallback paths. We do not want to maintain all three {ptrace only, ptrace + seccomp, seccomp + landlock} backends, given we'd only be running the latter in production.
  • Add a DMOJ_USE_LANDLOCK toggle. We'd probably want to default this to no for now.
  • Return errno directly with seccomp filters #793
Xyene added a commit to Xyene/judge that referenced this issue Aug 28, 2021
We won't be able to support these with Landlock, but it looks like no
runtime we currently support require them.

Ref DMOJ#871.
Xyene added a commit to Xyene/judge that referenced this issue Aug 28, 2021
We won't be able to support these with Landlock, but it looks like no
runtime we currently support require them.

Ref DMOJ#871.
Xyene added a commit to Xyene/judge that referenced this issue Aug 28, 2021
We won't be able to support these with Landlock, but it looks like no
runtime we currently support require them.

Ref DMOJ#871.
Xyene added a commit that referenced this issue Aug 28, 2021
We won't be able to support these with Landlock, but it looks like no
runtime we currently support require them.

Ref #871.
Riolku added a commit to Riolku/judge-server that referenced this issue Aug 30, 2021
Riolku added a commit to Riolku/judge-server that referenced this issue Aug 30, 2021
Riolku added a commit to Riolku/judge-server that referenced this issue Aug 30, 2021
Riolku added a commit to Riolku/judge-server that referenced this issue Sep 5, 2021
Riolku added a commit to Riolku/judge-server that referenced this issue Sep 5, 2021
Riolku added a commit to Riolku/judge-server that referenced this issue Sep 5, 2021
Riolku added a commit to Riolku/judge-server that referenced this issue Sep 5, 2021
Riolku added a commit to Riolku/judge-server that referenced this issue Sep 5, 2021
Riolku added a commit to Riolku/judge-server that referenced this issue Sep 5, 2021
Riolku added a commit to Riolku/judge-server that referenced this issue Sep 5, 2021
Riolku added a commit to Riolku/judge-server that referenced this issue Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant