CSE Roadmap

Common tier · about 3 hours · 7 parts

Part 5 of 7 · 2 min read

The smallest change

Think of a plumber who is asked to restore the water to one room. Replacing the whole building's pipes would fix it, and would also cause a flood. The smallest change is the one valve that was closed. The analogy stops in one place: a valve is either open or shut, while a permission change can be wider than intended without any sign.

In plain words: The fix grants exactly the missing right and no more (the principle of page 4). Here the missing right is only the search bit for "other" on private. Read and write for "other" on that directory are not needed, because nobody needs to look up one name, not to list or change the directory.

A worked example. Add the search bit for other, and test again:

$ chmod 701 /tmp/l8/l10/cs/proj/private
$ setpriv --reuid=65534 --regid=65534 --clear-groups cat .../report.txt
top
$ namei -m .../report.txt          (last two lines)
 drwx---r-x private
 -rw-r--r-- report.txt

Mode 701 means the owner has all rights and the others have x only. nobody can read the file because its own mode lets others read, and it cannot list private (no r) or create files in it (no w). The wider fix chmod 755 would also let every user list the directory, and chmod 777 would let every user delete the report. Two other choices exist: put nobody in a group that owns private (page 2), or move the file to a directory that the job may search. Each one is wider or narrower, and the choice depends on who else needs access.

The key lines. After the change, run the same test as the same user and see that it passes. Then run a test that should still fail, such as listing private as nobody, to make sure that the fix did not open more than planned.

Smallest sufficient change

The smallest sufficient change is the narrowest permission change that makes the failing access work and nothing more. It follows the principle of least privilege (page 4), and it is checked by one test that must now pass and one that must still fail.

Example: adding x for others on a directory, in place of making the directory writable by everyone.

Common mistake

Running chmod -R 777 to make a problem disappear. It hides the cause, opens the files to every user and every taken-over service, and removes any later chance to find the real rule that was wrong.

Check yourself: 1. What does mode 701 allow for the others? 2. Why is chmod 777 a bad fix? 3. Which second test confirms that the fix was narrow?