今日重点:📖 阅读——安全类 cover letter 的黄金标准长什么样?本周这位是标准答案: Christian Brauner 的 [PATCH RFC v2 00/42] fs: don't use pseudo filesystem files as storage。42 个补丁的安全加固,他用机制 → 可复现演示 → 设计 三段讲完,全程没有一个术语是为吓人而用的。

📖 第一段:机制——loop 怎么把「安全门」绕过去

/ section
Loop happily takes any regular file with ->read_iter() as a backing file and any file that also has ->write_iter() as a writable one. A few examples: * /proc/kcore attaches read-only as a loop device the size of the kernel's virtual address space (64 PiB with 5-level paging) * sysfs attributes attach read-write as 4096 byte loop devices * using /sys/kernel/mm/transparent_hugepage/enabled for the loop device and writing a block to the loop device changes the THP setting It's not just silly. It's abusable (is that a word?). Loop calls ->read_iter() and ->write_iter() of the backing file directly from its kworker which runs with kernel credentials.

第一段的写法值得逐句拆:① 先给规则—— Loop happily takes any regular file with ->read_iter() as a backing file(loop 来者不拒:只要有 read_iter 就能当后端)。一句话把「合法行为」 说清楚,这是后面论证的地基。② 再给三个具体例子(* 列表): /proc/kcore 成了 64 PiB 的 loop 设备、sysfs 属性成了 4096 字节设备、改 THP 设置 只要往 loop 设备写个块——荒诞感自己会长出来,不需要形容词。 ③ 最后升格:It's not just silly. It's abusable. 「这不只是滑稽,是可利用」——从「好笑」转到「危险」,一句话完成定性。

机制的核心在最后一句:Loop calls ->read_iter() and ->write_iter() of the backing file directly from its kworker which runs with kernel credentials. ——loop 的后端读写发生在内核凭据的 kworker 里。而伪文件系统的 ->show()/->store() 方法本来是按调用者做权限检查的 (大量 sysfs 方法会调 capable())。两边一对接:检查按「你」做, 执行按「内核」做——权限检查被完全跳过。这就是整个漏洞的根。

📖 第二段:演示——uid 0 无任何 capabilities 也能杀进程

/ column
On v7.4-rc1 uid 0 without any capabilities can't kill a process of uid 1000 and can't poison its memory either: $ grep CapEff /proc/self/status CapEff: 0000000000000000 $ kill -9 327 bash: kill: (327) - Operation not permitted $ echo 0x220689000 > /sys/devices/system/memory/hard_offline_page bash: echo: write error: Operation not permitted But put hard_offline_page behind a loop device, write a block containing 0x220689000 to the loop device and the loop worker happily does it: Memory failure: 0x220689: recovery action for dirty LRU page: Recovered MCE: Killing victim:327 due to hardware memory corruption fault at 7f468e972000

演示段的结构是对照实验:先证明「正常路径走不通」—— CapEff: 0000000000000000 的 root 杀不了 uid 1000 的进程、 写 hard_offline_page 被拒(Operation not permitted); 再证明「绕道走得通」——把同一个文件塞到 loop 设备后面,写一个块,内核日志直接打出 MCE: Killing victim:327 due to hardware memory corruption fault。 注意作者的两个动作:① 用命令 transcript 当证据(不是「我们观察到」, 而是贴 shell 输出)——可复现性直接写进文本;② 同一句式复用: happily 在前后两段各出现一次(Loop happily takes... / the loop worker happily does it),同一个副词从「拟人」变成「讽刺」—— 读到这里,读者已经不需要作者再加一句「这很糟糕」。

📖 第三段:设计——一个标志位收口七个后端

/ column
So this series adds SB_I_PSEUDO to state that the regular files of a filesystem are kernel interfaces and not storage and makes all seven refuse such files. I didn't want to sprinkle SB_I_PSEUDO over all pseudo filesystems one by one. Instead there's now a common initialization point for all of them via fc_init_pseudo().

设计段的两个句子各干一件事:第一句给定义——SB_I_PSEUDO to state that the regular files of a filesystem are kernel interfaces and not storage(这个标志说明:这类文件是内核接口,不是 存储)。一句话把「什么能当什么」的边界写死。第二句讲实现—— I didn't want to sprinkle SB_I_PSEUDO over all pseudo filesystems one by one. Instead there's now a common initialization point ... via fc_init_pseudo():不想逐个撒标志位,于是做了统一初始化入口。 sprinkle ... one by one 这对口语化搭配,把「逐文件打补丁」的丑陋 说得很清楚,Instead 引出集中式方案——先吐槽旧方案,再给新方案, 是设计段最顺的讲法。

★ 阅读拆点 · 四个值得内化的信号

同 cover letter · 学会抓重点

A few examples: + 项目符号 论证「普遍性」的标准开场。不是举一个孤例,而是三个并列、递进荒诞度的例子——读者自己得出「这很严重」,比作者断言有效十倍。
It's not just X. It's Y.(定性升格) 从「滑稽」到「可利用」的转折句。安全类邮件的高频形态:先承认现象看起来可笑,再指出危害。读到这个句式就该警觉——后面要么是漏洞细节,要么是 PoC。
On v7.4-rc1 + 命令 transcript(证据化) 写明内核版本 + 贴 shell 输出 = 可复现性声明。评审不必追问「怎么复现」——作者把实验过程直接放进了论证里。
So this series adds X(方案句模板) So this series adds ... 用 So 承接整个论证,一句话落地修复。注意定义先行:先解释标志位的语义(state that ...),再说它让谁拒绝什么——语义在前,行为在后。

✍️ 今日练习

/ column
✍️ 阅读理解(基于上方三段原文回答,每题一句英文):① 漏洞的根因是什么?(提示:检查按谁做、执行按谁做)② 演示段用了哪两个对照?③ 作者为什么选择加统一初始化入口而不是逐文件加标志位?(提示:sprinkle 那句)④ SB_I_PSEUDO 想表达的语义是什么?
💡 显示答案
参考答案(仿写示例,言之成理即可):① Pseudo files enforce their access rules against the caller, but loop reads and writes their backing files from a kernel-credentialed kworker, so the capable() checks are skipped entirely. ② First that uid 0 without capabilities cannot kill a uid 1000 process or write hard_offline_page directly; then that the same write succeeds through a loop device and kills the victim via an MCE. ③ Because sprinkling the flag over every pseudo filesystem one by one would be tedious and error-prone, so a common initialization point (fc_init_pseudo()) is used instead. ④ It states that the regular files of a filesystem are kernel interfaces and not storage.
📖 原文:It's not just silly. It's abusable (is that a word?). Loop calls ->read_iter() and ->write_iter() of the backing file directly from its kworker which runs with kernel credentials. ... But pseudo files enforce part of their access rules at read and write against the caller. ... So this series adds SB_I_PSEUDO to state that the regular files of a filesystem are kernel interfaces and not storage and makes all seven refuse such files.
📎 原文引用

Mechanism, demo, design — a security cover letter is a three-act play, and the demo is the second act everyone remembers.

素材:lore.kernel.org linux-mm · loop-pseudo v2 cover letter(Christian Brauner,〔11-14 21:05 北京〕,经 lore git 协议逐字提取)· 内核英语 · 每日一篇