LoongFire · 龙火 firewall · eBPF 防火墙 · eBPF

Teaching BPF to Fail Any Kernel Function

让 BPF 能让任意内核函数失败

Alexei Starovoitov's fmod_ret scan series raises attachable error-returning functions from 1,290 to 12,096 — and spends most of its cover letter arguing that the kernel survives it.

Alexei Starovoitov 的 fmod_ret 扫描补丁集,把可挂载的"返回错误码的函数"从 1,290 个提升到 12,096 个——而 cover letter 的大部分篇幅,都在论证内核承受得住。

The short version

On 14 November 2026 Alexei Starovoitov posted a patch series that is superficially modest and structurally large: it teaches the kernel build to find every function that returns an error, and lets a privileged BPF program make any of them fail on demand.

Today a BPF program can intercept about 1,290 kernel functions. After this series, on an x86-64 clang build, the number is 12,096. A program may then skip any one of those calls and hand the caller back an error code the function could genuinely have produced.

Why we care at LoongFire: this is the same instinct behind our XDP SYNPROXY stopgap for CVE-2026-98432 — reach into the kernel's packet path and refuse the dangerous case before the buggy code is ever reached. This series asks the more general question: what if you could do that to almost any kernel function, not just the handful on an allowlist?

The answer is "yes, at a measurable price." The rest of this post is the price.

What an fmod_ret program already does

BPF has a program type called fmod_ret — "function modify return." It runs at the top of a kernel function, before the function body. Its return value is not data, it is a verdict:

  • return 0 — let the real function run; the caller gets the function's own result.
  • return an error — skip the function entirely; the caller gets that error as if the function had failed.
How an fmod_ret program intercepts a kernel call A caller invokes vfs_fallocate. A BPF program runs first. Returning zero lets the call proceed and its result is used. Returning an error skips the function and that error is used instead. Caller err = vfs_fallocate(fd, …) fmod_ret program runs before the call returns 0 call it, err = its result returns -EFBIG skip it, err = -EFBIG
One program, two verdicts. The kernel function is either called normally, or never called at all.

The intended use is a guard rail. A real program from the cover letter:

SEC("fmod_ret/vfs_fallocate")
int guard_fallocate(struct file *f, int mode, loff_t off, loff_t len)
{
        return len > MAX_LEN ? -EFBIG : 0;
}

If the requested length is absurd, refuse the call with -EFBIG. If it is sane, return 0 and get out of the way. The function's own error handling never changes; the guard just makes one particular call impossible.

The catch is the allowlist. Today fmod_ret attaches to roughly 1,000 syscall entries, the security_*() LSM hooks, and about 20 other functions. That is a small island in a kernel with tens of thousands of functions.

Why anyone wants this

It is an emergency brake for security bugs.

Suppose a fixable-tomorrow bug lands in vfs_fallocate. You cannot patch ten thousand appliances tonight. You can load a BPF program that fails that specific call before the buggy code runs — a virtual patch, applied in seconds, removed when the real fix arrives. No reboot, no reflash, no maintenance window.

The problem is coverage. Of 417 real fixes from one year that added a new failing check to a kernel function, only 1% landed on a function you were allowed to attach to. The mechanism exists and is nearly useless in practice.

Anton Protopopov's earlier series raised that to 17%. This one claims 50%.

Note what is not being claimed. A program that switches off part of netfilter to keep a bug out of reach is working as designed. "Loss of function" is the feature. The question the series argues about is not whether a program can disable kernel functionality — of course it can — but whether it can crash the kernel while doing so.

Who may load does not change: CAP_BPF plus CAP_PERFMON, or a BPF token. Attaching does not taint the kernel, same as today.

The rule, and the trap underneath it

The rule is deliberately narrow, and it is the whole design:

The rule. A function f() that returns errors is a target. A program may return 0, or an error that f() itself returns. Nothing else.

That second clause is what makes this safe enough to consider at all. Without it, a BPF program could invent return values the caller never handles — -ENOSYS from a function that only ever returns 0 or -ENOMEM, or worse, a value that lands in a switch statement's default branch in a way the author never tested.

So the build computes, per function, the exact set of error constants that can reach its return register, and stores that set as metadata. The verifier then enforces it at load time: at every exit, R0 must be 0 or a member of that set. The program cannot lie about how the function fails, because the kernel wrote the list from the function's own machine code.

Then comes the trap, and it is subtle enough that it killed the obvious version of this idea:

Skipping a function is not the same as the function failing.

A function's error path usually does work the caller depends on. Unlock, put, free, tear down. If the function fails itself, that work happened. If you skip it, that work never happened — but the caller still receives a perfectly plausible error code and carries on as if the cleanup were done.

The exception

The canonical example is do_dup2() in fs/file.c, reached from ksys_dup3(), which takes files->file_lock and ends with return do_dup2(…). Inside do_dup2():

static int do_dup2(…) __releases(&files->file_lock)
…
Ebusy:
        spin_unlock(&files->file_lock);
        return -EBUSY;
Skipping a function versus letting it fail When do_dup2 fails on its own, it releases the file lock before returning EBUSY. When a BPF program skips it, the unlock never executes and the lock stays held. do_dup2() fails on its own caller holds file_lock spin_unlock(&file_lock) returns -EBUSY, lock free do_dup2() is skipped caller holds file_lock unlock never runs returns -EBUSY, lock held
Same error code, two different kernels. The caller cannot tell them apart, and one of them deadlocks.

Fail the function and the lock is released. Skip the function and the lock is still held — but dup2() returns -EBUSY either way, so the caller proceeds and the next operation on that file table hangs.

This is why the series needs a second rule:

The exception. An error is disallowed if every path leading to return -E calls a void function taking a pointer derived from one of f()'s arguments (or &arg->member — specifically not a loaded pointer). If no error survives, f() is not a target at all.

The reasoning is clean: a void function cannot be the thing that failed. If it ran, its work is done. Unlock, put, free and init are almost all void. A function that returns a value can be the failure point, so it does not count.

And the beauty of it is that the compiler already proved the types. The tool needs no name list, no __releases() annotation, no per-subsystem cooperation — it just looks at the machine code:

mov  %rdi,%r13            r13 = files         (a pointer argument)
lea  0xc0(%r13),%rdi      rdi = &files->file_lock   (no load)
call _raw_spin_unlock     BTF says: void, takes a pointer
mov  $0xfffffff0,%eax     -EBUSY  — every path here has that call

do_dup2() therefore ends up with no tag at all: a program cannot attach to it, and the verifier does not have to know why.

How the targets are found

Everything happens at link time, inside a tool the kernel already has. resolve_btfids normally just fixes up BTF IDs; here it grows a second job.

The link-time scanning pipeline Machine code from vmlinux and modules is decoded and analysed by resolve_btfids, which writes a BTF tag listing each function's error values. The verifier reads that tag at program load time. vmlinux, *.ko GCC or clang resolve_btfids reads the code BTF tag the error list verifier checks R0 at load decode → data flow → tag
One pass at link time produces the list; the verifier consumes it at load time.

Three steps inside resolve_btfids:

  1. Decode. LLVM's MC layer decodes the machine code and reports instruction lengths, branches, and which registers each instruction reads and writes.
  2. Analyse. A backward data flow pass, deliberately "may" rather than "must" (like a liveness analysis), collects the constants in the range −4095..−1 that can reach the return value register. A forward pass asks whether any path to that return avoids the exception's cleanup call.
  3. Tag. Write the surviving set onto the function as a BTF DECL_TAG.
DECL_TAG 'bpf_fmodret_retval:-95,-29,-27,-26,-22,-21,-19,-9,-1'
    on FUNC 'vfs_fallocate'

That tag is the rule, made concrete: these are the ways this function is allowed to fail, and a BPF program may pick any of them or none.

Why machine code instead of compiler IR

Because it is compiler-agnostic and post-inlining. Anton's series used a clang plugin reading LLVM IR — elegant, but clang-only, no LTO, and blind to what GCC actually emitted. Reading the final machine code works for both compilers and after the optimizer has rearranged everything.

The price is a hard build dependency: LLVM 17 or newer development headers and libraries must be present on the build host, even for a GCC build. LLVM's C++ API and opcode names churn between releases, so a newer LLVM can hard-fail the build of an older kernel with the option enabled. The series says so openly rather than hiding it.

Does it hold up?

They built an injection harness: one BPF program per tagged function, returning exactly one error at exactly one call site, then ran 530 tests and scripts (mostly kernel selftests) against an x86-64 GCC kernel with KASAN, lockdep, kmemleak and a wide config.

4,401 functions in net, fs and mm were exercised with one injection each. 50 caused kernel damage — a panic, a BUG, a hang, or a lockdep splat — which is 1.1%. The exception rule removes 27 of those, leaving 23 of 4,111: about one function in 180.

AreaFunctions testedDamage casesRate
net2,716250.9%
fs1,307181.4%
mm37871.9%
total4,401501.1%

Two findings make that number more defensible than it first sounds.

First, the blast radius is mostly theoretical. Of all 8,027 injections, 48% merely returned an error to user space and 50% did nothing at all. Only a small residue reaches anything that can break.

Second, of the 50 damage cases, at most 2 are genuine kernel bugs. The other 48 are the skip-versus-fail artifact — a real failure of f() at that call site would not have produced the damage. That is exactly what the exception targets, and it closes 26 of the 38 skip-caused cases.

ApproachAttachable functionsDamage per injectionBuild must read
Today's allowlist1,290not measured—
Anton's series4,4570.2%LLVM IR, clang plugin
This series12,0960.6–0.7%machine code, LLVM MC

The honest counterpoint is in the column nobody quotes: Anton's rule is roughly four times safer per function. It just covers a fifth as much — 903 of the 4,111 functions overlap. This series deliberately trades per-function safety for reach, and says so.

(Counts vary by compiler and architecture: 12,096 tags in an x86-64 clang kernel, 11,432 for GCC, 10,954 on arm64.)

What it costs

  • A Kconfig symbol, CONFIG_BPF_FMODRET_SCAN, with no default and not present in defconfig. allmodconfig and allyesconfig have no BTF, so they cannot enable it either. Nobody gets it by accident.
  • LLVM 17+ development files on every build host, plus a C++17 compiler. Even for GCC builds.
  • Build time: +0.9 s for the tool on vmlinux, after 4.3 s of pahole; +3 ms per Kconfig run.
  • Size: BTF grows from 8.02 MB to 8.24 MB (+2.8%); kernel memory +0.31 MB for the BTF and its index.
  • Architectures: x86-64 and arm64 only.
  • Footprint in the tree: nothing outside BPF's entries in MAINTAINERS. No file of net, fs or mm changes — which is clearly part of the sales pitch, and also means no subsystem maintainer has to review any of it.

What a reviewer will push on

The deny list is missing

114 functions still cause kernel damage after the exception — 55 of them in net, fs and mm. The proposed answer is a deny list by name, and that list is not in this series. This is the weakest joint in the argument: a hardcoded list of "do not attach here" is precisely the thing that rots, and it is the same name-matching approach the author criticises in today's security_*() targets — where 47 are SELinux internals, 59 return void, and 12 are hooks BPF LSM refuses outright.

Loss of function is a supported feature now

A privileged program can switch off part of netfilter to keep a bug out of reach. That is the intended use, and the author says so plainly. Loading still requires CAP_BPF + CAP_PERFMON or a BPF token, and attaching does not taint the kernel. The position is that this privilege tier is already effectively root.

Reasonable people will still note what has changed: the kernel would now have a supported, untainted, documented mechanism for silently disabling kernel functionality at runtime. A deny list is not a security boundary against that — it is a bug list.

It is a rework of someone else's work

Anton Protopopov's 18-patch series supplied the idea, the placement in resolve_btfids, the tag format, the verifier check, the tests, and the question that produced the exception rule. Alexei's contribution is the rule itself, the machine-code reader, and the safety data. The attribution throughout is scrupulous, which is worth noting in a discussion that will inevitably be framed as a maintainer overriding a contributor.

Scope

The v2 patches that treat the intercepted function's arguments as untrusted pointers were pulled out into a separate series (along with fentry/fexit arguments). So this set widens what you can attach to without, in the same series, tightening what a program can do with the arguments it receives.

What it actually is

A proposal to turn BPF from something that observes the kernel into a general-purpose, load-time-verified override layer for error returns — with the safety boundary drawn by static analysis over machine code rather than by hand-maintained allowlists.

The measured cost is about half a percent of functions being turnable into a crash by someone who already holds BPF privileges. Whether that is acceptable is the real question on the list, and it is not a technical one.

Two things will probably change before it lands: the build-time LLVM dependency (it is the objection with no counter-argument), and the missing deny list.

For LoongArch specifically: this series does not cover us. The decoder is a per-architecture opcode table — 142 lines for x86-64, 127 for arm64 — plus LLVM MC support for the target. LoongArch would need its own table and its own validation against llvm-mc. Worth watching, not yet worth porting.

Sources: the cover letter at lore.kernel.org; Anton Protopopov's earlier attempt at v2 of this series. All numbers above are the author's own measurements, not independently verified.

简要版

2026 年 11 月 14 日,Alexei Starovoitov 提交了一组补丁。它表面上改动不大,结构上却很大:让内核构建过程自己去发现所有"会返回错误码"的函数,然后允许一个特权 BPF 程序让其中任意一个函数按需失败。

今天,BPF 程序大约只能拦截 1,290 个内核函数。这组补丁之后,在一个 x86-64 clang 构建的内核上,这个数字是 12,096。程序可以跳过其中任意一次调用,并把一个该函数"本来就可能返回"的错误码交还给调用者。

为什么 LoongFire 关心这个:这和我们为 CVE-2026-98432 做的 XDP SYNPROXY 临时缓解是同一种直觉——伸手进内核的数据包路径,在漏洞代码被触达之前就把危险的那一次调用挡掉。这组补丁问的是一个更一般的问题:如果这件事可以对几乎任何内核函数做,而不只是白名单上的那几十个,会怎样?

答案是"可以,但有可测量的代价"。本文剩下的部分讲的就是这个代价。

fmod_ret 程序现在能做什么

BPF 有一种程序类型叫 fmod_ret,即"修改返回值"(function modify return)。它运行在内核函数的入口处、函数体之前。它的返回值不是数据,而是判决:

  • 返回 0 —— 让真正的函数跑,调用者拿到函数自己的结果。
  • 返回错误码 —— 整个跳过这个函数,调用者拿到这个错误码,就像函数自己失败了一样。
fmod_ret 程序如何拦截一次内核调用 调用者调用 vfs_fallocate。BPF 程序先运行。返回 0 则照常执行并使用其返回值;返回错误码则跳过该函数,直接用这个错误码作为结果。 调用者 err = vfs_fallocate(fd, …) fmod_ret 程序 在函数体之前运行 返回 0 执行函数,取返回值 返回 -EFBIG 跳过函数,err = 该值
一个程序,两种判决。内核函数要么照常被调用,要么根本不被调用。

它的本意是一道护栏。cover letter 里给了一段真实程序:

SEC("fmod_ret/vfs_fallocate")
int guard_fallocate(struct file *f, int mode, loff_t off, loff_t len)
{
        return len > MAX_LEN ? -EFBIG : 0;
}

如果请求的长度离谱,就用 -EFBIG 拒绝这次调用;如果长度正常,返回 0 让开。函数本身的错误处理完全没有变化——护栏只是让"某一种特定调用"变得不可能发生。

问题出在白名单上。今天 fmod_ret 只能挂到大约 1,000 个系统调用入口、security_*() 这类 LSM 钩子,以及另外约 20 个函数上。在一个拥有数万个函数的内核里,这只是一座小岛。

为什么有人想要这个

它是针对安全漏洞的紧急刹车。

假设 vfs_fallocate 里出了一个"明天就能修好"的漏洞。你不可能今晚给一万台设备打补丁。但你可以加载一个 BPF 程序,让那次特定调用在进入有漏洞的代码之前就失败——一个虚拟补丁,几秒钟内部署完成,真正的修复到位后再撤掉。不用重启,不用重刷固件,不需要维护窗口。

问题在于覆盖率。在过去一年里,有 417 个真实修复是"给某个内核函数新增一处失败检查",其中只有 1% 落在你被允许挂载的函数上。机制存在,实践中几乎无法使用。

Anton Protopopov 早先的一组补丁把这个比例提到 17%。这一组声称能做到 50%。

注意作者没有主张什么。一个程序关掉 netfilter 的一部分、把漏洞挡在够不着的地方,这是按设计工作。"功能丧失"本身就是特性。这组补丁真正争论的不是"程序能不能关掉内核功能"——当然能——而是它在这么做的同时,会不会把内核弄崩。

谁能加载并没有改变:仍然是 CAP_BPF 加 CAP_PERFMON,或者一个 BPF token。挂载不会给内核打上 taint 标记,和今天一样。

规则,以及规则下面的陷阱

规则刻意收得很窄,而它就是这个设计的全部:

规则。会返回错误码的函数 f() 是目标函数。程序只能返回 0,或者 f() 自己会返回的某个错误码。别的都不行。

正是后半句让这件事"值得考虑"。没有它,BPF 程序可以凭空造出调用者从未处理过的返回值——从一个只会返回 0 或 -ENOMEM 的函数里返回 -ENOSYS;更糟的是,某个值正好落进调用者 switch 语句的默认分支,而那条分支作者从未测过。

所以构建过程会逐个函数算出"哪些错误常量能到达返回值寄存器",把这个集合存进元数据。校验器在加载时强制执行:每一条退出路径上,R0 必须是 0 或该集合的成员。程序没法在"这个函数怎么失败"上撒谎,因为清单是内核从函数自己的机器码里读出来的。

然后就到了陷阱。它足够隐蔽,以至于直接杀死了这个想法最朴素的版本:

跳过函数,不等于函数失败。

函数的错误路径通常做了调用者所依赖的事情:解锁、put、释放、拆除。如果函数自己失败,这些事已经做了。如果你跳过它,这些事根本没发生——但调用者依然收到一个看起来完全合理的错误码,然后当清理已经完成一样继续往下走。

例外规则

最典型的例子是 fs/file.c 里的 do_dup2()。它由 ksys_dup3() 调用,后者先拿到 files->file_lock,最后 return do_dup2(…)。而 do_dup2() 内部:

static int do_dup2(…) __releases(&files->file_lock)
…
Ebusy:
        spin_unlock(&files->file_lock);
        return -EBUSY;
跳过函数与让函数失败的差别 do_dup2 自己失败时会在返回 EBUSY 之前释放文件锁。当 BPF 程序跳过它时,解锁从未执行,锁仍然被持有。 do_dup2() 自己失败 调用者持有 file_lock spin_unlock(&file_lock) 返回 -EBUSY,锁已释放 do_dup2() 被跳过 调用者持有 file_lock 解锁从未执行 返回 -EBUSY,锁仍持有
同样的错误码,两个不同的内核状态。调用者分辨不出区别,而其中一种会死锁。

让函数失败,锁会被释放。跳过函数,锁还在——但 dup2() 两种情况都返回 -EBUSY,于是调用者继续走,下一次操作这张文件表时就挂住了。

这就是为什么还需要第二条规则:

例外规则。如果通往 return -E 的每一条路径都调用了一个 void 函数,而该函数的指针参数来自 f() 的某个参数(或 &arg->member,明确不是解引用载入的指针),那么这个错误码就不被允许。如果没有错误码活下来,f() 就不是目标函数。

理由很干净:void 函数不可能是"失败的那一个"。它跑了,它的工作就完成了。解锁、put、释放、初始化,几乎全是 void。而一个带返回值的函数有可能是失败点,所以它不算数。

妙处在于,类型信息编译器早就证明过了。工具不需要名字清单,不需要 __releases() 注解,也不需要任何子系统的配合——它只看机器码:

mov  %rdi,%r13            r13 = files          (一个指针参数)
lea  0xc0(%r13),%rdi      rdi = &files->file_lock   (没有载入)
call _raw_spin_unlock     BTF 说:返回 void,收一个指针
mov  $0xfffffff0,%eax     -EBUSY  —— 每条路径上都有这次调用

于是 do_dup2() 最终连标签都没有:程序挂不上去,而校验器根本不需要知道原因。

目标函数是怎么找出来的

全部发生在链接阶段,用的还是内核里已有的那个工具。resolve_btfids 平时只负责修补 BTF ID,这里多了一份工作。

链接期的扫描流水线 vmlinux 与模块的机器码由 resolve_btfids 解码并分析,写出记录每个函数错误码集合的 BTF 标签。校验器在程序加载时读取该标签。 vmlinux, *.ko GCC 或 clang resolve_btfids 读取机器码 BTF 标签 错误码清单 校验器 加载时检查 R0 解码 → 数据流分析 → 打标签
链接期一趟扫描产出清单,加载期校验器消费它。

resolve_btfids 里做三件事:

  1. 解码。用 LLVM 的 MC 层解码机器码,得到每条指令的长度、分支,以及它读写了哪些寄存器。
  2. 分析。一趟反向数据流,刻意用"可能"(may)而不是"必定"(must),类似活跃变量分析,收集所有能到达返回值寄存器、且落在 −4095..−1 区间内的常量。再跑一趟正向分析,问"有没有哪条通往该 return 的路径绕开了例外规则要看的清理调用"。
  3. 打标签。把存活的集合写成函数上的 BTF DECL_TAG。
DECL_TAG 'bpf_fmodret_retval:-95,-29,-27,-26,-22,-21,-19,-9,-1'
    on FUNC 'vfs_fallocate'

这个标签就是规则的具体形式:这些是这个函数被允许的失败方式,BPF 程序可以选其中任意一个,或者一个都不选。

为什么读机器码,而不是编译器 IR

因为它与编译器无关,而且发生在内联之后。Anton 的那组补丁用 clang 插件读 LLVM IR——很优雅,但只支持 clang,不支持 LTO,而且看不见 GCC 实际生成了什么。读最终的机器码,两个编译器都能覆盖,而且是在优化器把一切重排之后。

代价是一个硬性的构建依赖:构建主机上必须存在 LLVM 17 或更新的开发头文件和库,哪怕是纯 GCC 构建。LLVM 的 C++ API 和 opcode 名字在版本之间会变,所以一个更新的 LLVM 可能让一个旧内核在这个选项打开时直接构建失败。这组补丁对此说得很坦白,没有藏。

它站得住脚吗?

作者搭了一套注入测试台:每个被打上标签的函数配一个 BPF 程序,在恰好一个调用点返回恰好一个错误码,然后在一个开了 KASAN、lockdep、kmemleak 和宽配置的 x86-64 GCC 内核上跑 530 个测试与脚本(主要是内核自测)。

net、fs、mm 三个目录下 4,401 个函数各注入一次,50 个造成了内核损坏——panic、BUG、卡死,或 lockdep 报告——占 1.1%。例外规则去掉了其中 27 个,剩下 4,111 个里的 23 个:大约每 180 个函数里有 1 个。

子系统测试函数数损坏数比例
net2,716250.9%
fs1,307181.4%
mm37871.9%
合计4,401501.1%

有两个发现让这个数字比初看时更站得住。

第一,影响面大部分是理论上的。全部 8,027 次注入里,48% 只是给用户态返回了一个错误,50% 什么也没发生。真正能搞坏东西的只是很小一部分。

第二,50 个损坏案例里,最多只有 2 个是内核本身的 bug。其余 48 个都是"跳过 ≠ 失败"的产物——如果 f() 在那个调用点真的自己失败了,并不会造成这种损坏。这正是例外规则瞄准的东西,而它关掉了 38 个"跳过型"案例中的 26 个。

方案可挂载函数单次注入损坏率构建期需要读
今天的白名单1,290未测量—
Anton 的方案4,4570.2%LLVM IR(clang 插件)
本方案12,0960.6–0.7%机器码(LLVM MC)

诚实的反方论据在没人引用的那一列:Anton 的规则按单个函数算,安全性大约是本方案的四倍。只是覆盖面只有五分之一——4,111 个函数里重叠 903 个。本方案是刻意用"单函数安全性"换"覆盖面",而且它自己也这么说了。

(数字随编译器与架构变化:x86-64 clang 内核 12,096 个标签,GCC 11,432 个,arm64 10,954 个。)

代价是什么

  • 一个 Kconfig 符号:CONFIG_BPF_FMODRET_SCAN,没有默认值,不在 defconfig 里。allmodconfig 和 allyesconfig 没有 BTF,也开不了。没人会不小心打开它。
  • 每台构建主机都要有 LLVM 17+ 的开发文件,外加一个 C++17 编译器。哪怕你是纯 GCC 构建。
  • 构建时间:工具在 vmlinux 上多 0.9 秒(在 pahole 的 4.3 秒之后);每次 Kconfig 运行多 3 毫秒。
  • 体积:BTF 从 8.02 MB 涨到 8.24 MB(+2.8%);内核内存多 0.31 MB(BTF 及其索引)。
  • 架构:只支持 x86-64 和 arm64。
  • 在代码树里的足迹:除了 MAINTAINERS 里 BPF 自己的条目,什么都没改。net、fs、mm 一行都没动——这显然是推销话术的一部分,也意味着没有任何子系统维护者需要 review 它。

评审会揪住的几个点

黑名单不见了

例外规则之后,仍有 114 个函数能把内核搞坏——其中 55 个在 net、fs、mm。作者给出的答案是"按名字列黑名单",而这份名单不在这组补丁里。这是整个论证最薄弱的接缝:一份硬编码的"不许挂这里",恰恰是最容易腐烂的东西;而且这正是作者用来批评今天 security_*() 目标的同一种按名字匹配的做法——那里面 47 个是 SELinux 内部函数,59 个返回 void,12 个是 BPF LSM 直接拒绝的钩子。

"功能丧失"现在是被支持的特性

一个特权程序可以关掉 netfilter 的一部分,把漏洞挡在够不着的地方。这就是预期用法,作者说得很明白。加载仍然需要 CAP_BPF + CAP_PERFMON 或一个 BPF token,挂载也不会打 taint 标记。其立场是:这个权限层级本来就等同于 root。

但合理的人仍会指出变了什么:内核从此有了一个受支持、不留痕迹、有文档的机制,可以在运行时悄悄关掉内核功能。黑名单挡不住这件事——它只是一份 bug 清单,不是安全边界。

这是对别人工作的重写

Anton Protopopov 的 18 个补丁提供了想法、resolve_btfids 这个位置、标签格式、校验器检查、测试,以及那个最终催生例外规则的问题。Alexei 的贡献是规则本身、机器码读取器,以及那套安全数据。全文的署名极其克制——在一场注定会被描述成"维护者压过贡献者"的讨论里,这一点值得记下来。

范围

v2 里把被拦截函数的参数当作不可信指针的那几个补丁,被拆到了另一组(和 fentry/fexit 的参数一起)。所以这一组扩大了"能挂到哪里",但并没有在同一组里收紧"程序能拿这些参数做什么"。

它本质上是什么

它要把 BPF 从"观察内核的东西",变成一层通用的、加载时经过校验的错误返回值覆写层——而且安全边界是用对机器码的静态分析画出来的,不是靠人工维护的白名单。

实测代价是:大约 0.5% 的函数,可以被一个已经握有 BPF 特权的人变成一次崩溃。这个代价是否可接受,才是邮件列表上真正的问题,而它不是技术问题。

落地之前大概会有两处改动:构建期的 LLVM 依赖(这是唯一没有反方论据的反对意见),以及那份缺失的黑名单。

具体到 LoongArch:这组补丁不覆盖我们。解码器是一张按架构划分的 opcode 表——x86-64 142 行、arm64 127 行——外加 LLVM MC 对该目标的支持。LoongArch 需要自己的表,以及对着 llvm-mc 的独立校验。值得关注,但还不值得移植。

来源:lore.kernel.org 上的 cover letter;Anton Protopopov 的早期方案见本系列的 v2。文中所有数字均来自作者自测,未经独立验证。

All posts全部文章 Home首页