CSE Roadmap

Common tier · about 3 hours · 7 parts

Part 7 of 7 · 3 min read

Exercises

Easy

Easy 1: Soft and hard (20 minutes)

A process has soft 1024 and hard 4096 for open files. What is the most it can set its soft limit to without extra power, and can it set the hard limit to 8192?

Done when: 4096, and no (it needs CAP_SYS_RESOURCE).

Hint

the soft limit may rise to the hard limit.

Easy 2: Which wall (20 minutes)

Name the wall for each: limits file descriptors, hides /etc, blocks connect, applies an admin policy.

Done when: rlimit, chroot, seccomp, MAC.

Hint

one wall per question.

Easy 3: Error names (20 minutes)

What error did the soft limit give, and what did the seccomp filter give, in section 2?

Done when: Too many open files (EMFILE) and Operation not permitted (EPERM).

Hint

read the output of the program.

Medium

Medium 1: Run it (45 minutes)

Compile and run the program of section 2 as root. Change the soft limit to 4 and report when open first succeeds.

Done when: a statement that with 3 descriptors in use, a limit of 4 allows one more open and a limit of 3 allows none.

Hint

standard input, output and error use 3 slots.

Medium 2: Block another call (45 minutes)

Change the filter to block SYS_getpid with EPERM instead of openat, and call getpid() before and after.

Done when: getpid returns a number before the filter and -1 with EPERM after.

Hint

use SYS_getpid in the jump test and syscall(SYS_getpid) to call it.

Medium 3: The jail path (45 minutes)

Create /tmp/jail/etc/hostname with some text, run the program of section 4 again, and report the output.

Done when: open succeeds after chroot, and a sentence that explains it opened the jail's own copy.

Hint

mkdir -p /tmp/jail/etc first.

Hard

Hard 1: Allow list (90 minutes)

Write a filter that allows only read, write, exit_group and rt_sigreturn, and kills the process otherwise (SECCOMP_RET_KILL_PROCESS). Test with a program that writes a line and then calls open.

Done when: the line is printed and the process is killed at open (the shell shows "Bad system call" and exit status 159).

Hint

the end of the program also needs exit_group to be allowed.

Hard 2: Fork bomb limit (90 minutes)

Using RLIMIT_NPROC for a non-root user (with setuid first), show that a loop of fork calls stops with EAGAIN at the limit. Use a small limit such as 20 and count the successful forks.

Done when: 19 successful forks with a limit of 20 (the parent counts as one process), and Resource temporarily unavailable printed.

Hint

drop to a non-root user first, since root ignores RLIMIT_NPROC.

Hard 3: Design a sandbox (90 minutes)

Design the sandbox for a program that resizes uploaded pictures: list the user, capabilities, limits, allowed system calls, root directory and MAC rule. Say which gap each layer covers.

Done when: a table of five layers, each with a setting and the gap it closes.

Hint

copy the example in section 1 and fill each layer.