Part 3 of 7 · 2 min read
Protection domains
Think of a visitor badge. One badge opens the lobby and the meeting rooms, and another opens the lobby and the server room. The person is the same, and the rights depend on the badge worn. The analogy stops in one place: a badge can be taken off in a second, while a process changes its domain only by defined means.
In plain words: A protection domain is the set of objects that a process can access, and the operations it may do on each. On Unix, the domain of a process is mostly decided by its user ID and its group IDs, and, since Linux 2.2, by a set of capabilities (page 4) that split the power of the superuser into parts. A process starts in the domain of the user who ran it. Some programs must change domain for a short time, for example to let a user change a password in a protected file. Page 2 shows how setuid does this.
A worked example. The program id and the file /proc/self/status show the domain of the current process. On the test machine the commands ran as root, and then as nobody through setpriv.
$ id
uid=0(root) gid=0(root) groups=0(root)
$ setpriv --reuid=65534 --regid=65534 --clear-groups id
uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
$ setpriv --reuid=65534 --regid=65534 --clear-groups sh -c 'grep -E "^(Uid|Gid|CapEff)" /proc/self/status'
Uid: 65534 65534 65534 65534
Gid: 65534 65534 65534 65534
CapEff: 0000000000000000
The first process has user 0, the superuser. The second has user 65534. Its four Uid numbers are the real, effective, saved and file-system user IDs, and here they are equal. Its effective capability set (CapEff) is all zeros: it has none of the special powers of root. Dropping from the first domain to the second takes rights away, and a process cannot take them back.
The key lines. A domain can be a user, a process, or a part of a process. A web server that needs to open port 80 as root and then serves pages as an ordinary user is a good design, because the part that does the risky work has the fewest rights.
Protection domain
A protection domain is the set of access rights that a process holds at a time: the objects it can reach and the operations it may do on each. On Linux it is determined mainly by the process's user and group IDs and its capabilities.
Example: a process that runs as nobody with no capabilities has a smaller domain than one that runs as root.
Check yourself:
1. What does a domain consist of?
2. What are the four Uid numbers in /proc/self/status?
3. Why can a process that dropped its rights not get them back?