Part 7 of 7 · 3 min read
Exercises
Easy
Easy 1: Read the code (20 minutes)
Name the family of cause for each: EACCES, EPERM, ENOENT, EMFILE.
Done when: a mode, list or policy refusal; a capability or filter; a missing name in the view; a resource limit.
Hint
use the table in section 1.
Easy 2: Mode classes (20 minutes)
A directory has mode 700 and belongs to root. Which class is the user nobody in, and which rights does that class have?
Done when: other, with no rights.
Hint
the owner is root, so nobody is in other.
Easy 3: Which field (20 minutes)
Which line of /proc/PID/status shows the capability mask, and which shows whether a seccomp filter is active?
Done when: CapEff and Seccomp (2 means a filter).
Hint
grep the two names in /proc/PID/status.
Medium
Medium 1: Reproduce (45 minutes)
As root, create proj/private/report.txt with a directory of mode 700 and a file of mode 644. Test as nobody with setpriv, run namei -l, then add the search bit for others and test again.
Done when: the output matches section 2 and section 4.
Hint
setpriv --reuid=65534 --regid=65534 --clear-groups cat FILE.
Medium 2: Root versus nobody (45 minutes)
Create a file with mode 000. Read it as root and as nobody. Explain both results.
Done when: root reads it (CAP_DAC_OVERRIDE), nobody gets Permission denied.
Hint
run cat once with and once without setpriv.
Medium 3: Group route (45 minutes)
Fix the report problem a second way: make private owned by a new group, give the group x, and add nobody to the group. Test the result, and list one risk of the group route compared with mode 701.
Done when: the read works, and the risk is that every member of the group can search the directory, and that the group must be kept up to date.
Hint
groupadd, chgrp, chmod 710, usermod -aG, and start a new process after the change.
Hard
Hard 1: A diagnosis script (90 minutes)
Write a shell script whycant PID PATH that prints namei -l PATH, the Uid, Gid, Groups, CapEff, NoNewPrivs and Seccomp fields of /proc/PID/status, and the mount namespace of the process next to your own.
Done when: the script runs on a test process and the output has all the fields.
Hint
readlink /proc/PID/ns/mnt and readlink /proc/self/ns/mnt.
Hard 2: Three failures (90 minutes)
Create three failing cases for one process: a directory without search (EACCES), a seccomp filter on openat (EPERM, page 6), and a chroot without the file (ENOENT). For each, name the check of section 5 that finds it.
Done when: three outputs with different error texts, and the check numbers 2, 5 and 6.
Hint
reuse the programs of page 6.
Hard 3: A runbook (90 minutes)
Write a one-page runbook for the on-call team with the checklist of section 5, the commands to run and the signs that each step gives. Add the rule about the narrowest fix.
Done when: nine steps, each with a command and the sign it gives, and a closing note on testing a pass and a still-fail.
Hint
copy the table of section 5 and add a column for the sign.