Protection and security
แนะนำใหม่
6:44
ระบบปฏิบัติการ
An operating system turns one processor into many machines. The first three units build the illusions of the processor: processes, taking turns, and safe…
บรรยายภาษาอังกฤษ · สลับคำบรรยายภาษาอังกฤษและภาษาจีนได้
ในบทเรียนนี้
| English | ความหมาย |
|---|---|
| rings/rɪŋz/ | ระดับสิทธิ์ (rings) |
| User mode/ˈjuːzə məʊd/ | the restricted processor mode in which applications run |
| Kernel mode/ˈkɜːnl məʊd/ | the privileged processor mode in which the operating system runs |
| system calls/ˈsɪstəm kɔːlz/ | |
| Least privilege/liːst ˈprɪvɪlɪdʒ/ | giving each user or program only the rights it needs for its task |
| confused deputy/kənˈfjuːzd ˈdepjuːti/ | a privileged program tricked into misusing its rights on behalf of a less privileged caller |
| capabilities/ˌkeɪpəˈbɪlɪtiz/ | unforgeable tokens that carry specific access rights to an object |
| salted/ˈsɒltɪd/ | (of a password hash) combined with a random value before hashing, so equal passwords give different hashes |
| hash/hæʃ/ | a fixed-length digest of data that anyone can compute; it shows change but not who made it |
| Address space layout randomisation/əˈdres speɪs ˈleɪaʊt ˌrændəmaɪˈzeɪʃn/ | Placing a program's code, stack and libraries at random addresses each run, so an attacker cannot predict where to jump. |
Two rings, one door
- User mode 用户态 runs application code. Kernel mode 内核态 runs the OS and may touch devices and page tables. A mode bit in the CPU enforces these rings 特权级.
- System calls 系统调用 are controlled entry points from user code to kernel services. Hardware interrupts and processor exceptions can also transfer control to the kernel.

User code reaches kernel services only through —
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
The mode bit walls the rings; syscalls are the only doors.
One crossing, priced
open("/notes/x")from user mode: the trap sets the mode bit, saves the user registers and jumps to a fixed address in the kernel. The kernel checks the path and fills in a descriptor; then the mode bit is set back.- Each system call crosses twice, at about 100 ns each. A program that makes $10^6$ system calls pays $0.2$ s, which is why libraries buffer and batch them.
One syscall costs two crossings of about 100 ns; a million syscalls cost —
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
1e6 x 2 x 100 ns = 0.2 s — why libraries batch.
Least privilege, and the confused deputy
- Least privilege 最小权限 gives each process only what it needs. Page tables do this per process, file permissions per user ($9$ bits: read, write and execute for owner, group and other), and capabilities 能力凭证 per object.
- A printer daemon with high privilege is asked to print
/salary.db. It uses its own authority, not the user's: this is the confused deputy 混淆代理. - The fix is to pass capabilities (open descriptors), not names. Check every crossing; a smaller privileged core is a smaller target.
The confused deputy is fixed by passing —
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Capabilities (open descriptors) let the deputy use only what it was handed.
Storing passwords
- Never store a password, only a salted 加盐, slow hash 哈希. A random salt for each user means two equal passwords give different hashes, and tables computed in advance are useless. The salt is stored in plain text next to the hash: it is not a secret.
- Slowness is the defence. Eight lowercase letters give $26^8 \approx 2.09 \times 10^{11}$ guesses: about $21$ s at $10^{10}$ fast hashes a second, but about $242$ days at the $10^4$ a second of a tuned bcrypt or Argon2.
At 10^10 guesses a second, how many seconds does it take to try every 8-letter lowercase password? (Answer to 1 decimal place.)
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
26^8 = 208 827 064 576, divided by 10^10 is about 20.9 s.
A salt must be kept secret to protect the passwords.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
The salt is stored openly; its job is to make each hash unique, so precomputed tables fail.
Permission bits in octal
- Owner, group and other each get three bits: read 4, write 2, execute 1.
rwxr-x---is $7, 5, 0$: mode 750. chmod 640 notes.txtgivesrw-r-----: the owner reads and writes, the group reads, and others get nothing. For a directory, x means "may enter", so a 644 directory cannot be entered by anyone except root.
Permissions rwxr-x--- as an octal mode?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
เจ้าของ $4 + 2 + 1 = 7$, group $4 + 1 = 5$, other 0.
chmod 640 gives:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
6 is read and write, 4 is read, 0 is nothing.
Worked example: what ASLR buys
- Address space layout randomisation 地址空间布局随机化 (ASLR) puts code and stack at random addresses, so an attack must guess where to jump. With 8 bits of randomness, a guess succeeds 1 time in 256: about 128 tries on average.
- With 28 bits it is 1 in $2^{28}$, about 134 million tries on average, and each wrong guess usually crashes the target and is noticed. Randomness turns a reliable attack into a lottery.
ASLR with 8 bits of entropy and a fixed address: if distinct addresses are guessed in random order, what is the average number of guesses to hit the right address?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Half of $2^8 = 256$.
Marks that slip away
- A fast hash for passwords. Eight lowercase letters fall in about $21$ s at $10^{10}$ hashes a second; at bcrypt speed it takes about $242$ days.
- Hiding the salt. The salt is not secret. Its job is to make equal passwords hash differently and to make tables computed in advance useless.
- Passing names to a privileged program. The daemon then acts with its own authority: the confused deputy. Pass an open descriptor instead.
Recap
- User mode and kernel mode; system calls, interrupts and exceptions can transfer control to the kernel.
- Two crossings per system call at about 100 ns: $10^6$ calls cost $0.2$ s.
- Least privilege; pass capabilities, not names, to avoid the confused deputy.
- Slow, salted hashes make guessing expensive. All $26^8$ eight-letter lowercase passwords:
| Hash | Guesses/s | Try all |
|---|---|---|
| Fast | $10^{10}$ | ~21 s |
| bcrypt | $10^{4}$ | ~242 days |
เกิดปัญหาอะไรขึ้น? เฉพาะทีมเว็บไซต์เท่านั้นที่เห็นข้อมูลนี้