Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 06 · How Computers Work · Build the machine's software · about 17 min to read

Play it as a journeyTutor comes with a plan

Who is allowed: users, root and capabilities

Processes Threads and the Kernel
Processes Threads and the Kernel · Open board

: the kernel sitting between every program and the machine. This lesson is about the question the kernel asks at that door: who is asking, and are they allowed?

You run a small web server. Web browsers expect it on port 80, and Linux lets only root open a port below 1024. So you start the server as root. Months later a bug in the server lets a stranger send it a strange request. The stranger now controls a program that is root, so the stranger can read every file and change every setting on the machine. One small bug has cost you the whole computer.

By the end you will be able to read the numbers the kernel checks (who you are and what you may do), explain why a program like passwd can change a file you cannot touch, and give a server only the one power it needs instead of all of root.

The history (optional)

On 9 July 1973 Dennis Ritchie of Bell Labs filed a patent for a small idea: an extra permission bit on an executable file. When the bit is set, a person who runs the file takes on the identity of the file’s owner for as long as it runs. The US patent office granted it as number 4,135,240 on 16 January 1979. That bit is the setuid bit in this lesson.

Bob Coggeshall and Cliff Spencer wrote sudo around 1980 at SUNY Buffalo. Sources give only “around 1980”.

In June 2000 a Linux bug showed what goes wrong when the powers of root are split badly. Wojciech Purczynski found that a local user could set things up so that a setuid program, such as sendmail, could not give up its powers when it tried to. Alan Cox checked it and patched the kernel, and Linux 2.2.16 fixed it (CVE-2000-0506).

Before you start. A process is one running program, and the kernel is the program underneath all of them (Processes, Threads & the Kernel). In The tap on the shoulder a process could send a signal to another, and kill was one way to send it. This lesson explains who is allowed to do that. A fork copies a process and an exec loads a new program into it (The program that starts programs). Both come back in the setuid section.

Lesson 35 of 41 in How Computers Work

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • UID: the number the kernel checks
  • The setuid bit: a program that runs as its owner
  • sudo: a setuid program that asks first
  • A capability: one power of root, taken alone
  • A user namespace: a preview of a fake root

Terms it explains: UID, root, setuid bit, effective UID, capability, user namespace, context switch, fork/exec, init/systemd, kernel, MMU + page table, namespaces + cgroups, page (~4KB) / frame, page fault, PID, preemption, process, scheduler, segfault, swap, syscall, thread, user vs kernel mode (ring 3/0), virtual memory.

Lab

The program needs twelve pages at once. What happens when it gets eleven frames?

Drag Frames of real memory from 24 down to 11, then back to 12, and watch Time spent working.

Open The working set

Three long jobs are running when you press a key. How long until the keypress gets the CPU?

Click Take turns, drag How long one turn lasts from 100 ms down to 1 ms, and watch The keypress waits.

Open The time slice

How many workers should a pool have, and why does the answer flip when the tasks mostly wait?

Drag Workers on shift down to the core count, then push Share of each task spent waiting to 90% and watch Finished each second.

Open The thread pool

Related papers

Review How Computers Work