[PATCH OLK-6.6 0/2] CVE-2026-98800
Florent Revest (Anthropic) (1): bpf: Wait for an RCU tasks grace period before freeing trampoline progs Pu Lehui (1): bpf: Fix kabi breakage in struct bpf_prog_aux include/linux/bpf.h | 1 + kernel/bpf/syscall.c | 19 ++++++++++++++++++- kernel/bpf/trampoline.c | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) -- 2.34.1
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://atomgit.com/openeuler/kernel/merge_requests/30118 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/6TQ... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://atomgit.com/openeuler/kernel/merge_requests/30118 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/6TQ...
From: "Florent Revest (Anthropic)" <florent.revest@linux.dev> mainline inclusion from mainline-v7.3-rc6 commit 0fb5751a6e411b1b466c06e50021818d9391df98 category: bugfix bugzilla: https://atomgit.com/src-openeuler/kernel/issues/20408 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=... -------------------------------- When a prog is detached from a trampoline, it is freed after an RCU grace period, or an RCU tasks trace one if it is sleepable. This covers the tasks that are running the prog, since the prog's enter helper takes the matching read lock before the prog is called. On a preemptible kernel, it doesn't cover a task that was preempted in the trampoline just before the enter helper. That task holds no lock yet, and it calls the prog after it was freed: BUG: KASAN: vmalloc-out-of-bounds in __bpf_prog_enter_recur+0x3a5/0x3f0 Read of size 8 at addr ffffc90000055040 by task candidate/110 CPU: 1 UID: 0 PID: 110 Comm: candidate Not tainted 7.3.0-rc2-00014-g15071f2a1263-dirty #2 PREEMPT(full) Call Trace: <TASK> __bpf_prog_enter_recur+0x3a5/0x3f0 bpf_trampoline_6442509193+0x37/0xf1 __x64_sys_futex+0x9/0x410 do_syscall_64+0xb0/0x530 ... Wait for an RCU tasks grace period before the existing one when freeing a prog that was linked to a trampoline. An RCU tasks grace period only ends once the tasks that were preempted have run again, and bpf_tramp_image_put() already relies on it to free the image. It doesn't wait for tasks that sleep in the trampoline, the next commit takes care of those. Only progs that were linked to a trampoline can be called this way, so bpf_trampoline_add_prog() marks them and other progs are still freed as before. Fixes: e21aa341785c ("bpf: Fix fexit trampoline.") Reported-by: Junseo Lim <zirajs7@gmail.com> Signed-off-by: Florent Revest (Anthropic) <florent.revest@linux.dev> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20260926135605.1217928-2-florent.revest@linux.dev Closes: https://lore.kernel.org/bpf/aqdrwVpanH3WGurX@omen-arch/ Conflicts: include/linux/bpf.h kernel/bpf/syscall.c kernel/bpf/trampoline.c [minor issue] Signed-off-by: Pu Lehui <pulehui@huawei.com> --- include/linux/bpf.h | 1 + kernel/bpf/syscall.c | 19 ++++++++++++++++++- kernel/bpf/trampoline.c | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index de601dff733e..e6271a2656d2 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1562,6 +1562,7 @@ struct bpf_prog_aux { bool dev_bound; /* Program is bound to the netdev. */ bool offload_requested; /* Program is bound and offloaded to the netdev. */ bool attach_btf_trace; /* true if attaching to BTF-enabled raw tp */ + bool tramp_linked; /* true if it was ever linked to a trampoline */ bool func_proto_unreliable; KABI_DEPRECATE(bool, sleepable) bool tail_call_reachable; diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 78e6104a8287..b462be488724 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2159,6 +2159,21 @@ static void __bpf_prog_put_rcu(struct rcu_head *rcu) bpf_prog_free(aux->prog); } +/* + * Progs called from a trampoline can also be reached by a task that was + * preempted in the trampoline before the prog's enter helper took its RCU + * read lock, wait for those first. + */ +static void __bpf_prog_put_rcu_tasks(struct rcu_head *rcu) +{ + struct bpf_prog *prog = container_of(rcu, struct bpf_prog_aux, rcu)->prog; + + if (prog->sleepable) + call_rcu_tasks_trace(rcu, __bpf_prog_put_rcu); + else + call_rcu(rcu, __bpf_prog_put_rcu); +} + static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred) { bpf_prog_kallsyms_del_all(prog); @@ -2171,7 +2186,9 @@ static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred) btf_put(prog->aux->attach_btf); if (deferred) { - if (prog->sleepable) + if (IS_ENABLED(CONFIG_TASKS_RCU) && prog->aux->tramp_linked) + call_rcu_tasks(&prog->aux->rcu, __bpf_prog_put_rcu_tasks); + else if (prog->sleepable) call_rcu_tasks_trace(&prog->aux->rcu, __bpf_prog_put_rcu); else call_rcu(&prog->aux->rcu, __bpf_prog_put_rcu); diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index fd23fdbdcf00..4ba86acb98e6 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -591,6 +591,7 @@ static int __bpf_trampoline_link_prog(struct bpf_tramp_link *link, } hlist_add_head(&link->tramp_hlist, &tr->progs_hlist[kind]); + link->link.prog->aux->tramp_linked = true; tr->progs_cnt[kind]++; err = bpf_trampoline_update(tr, true /* lock_direct_mutex */); if (err) { -- 2.34.1
hulk inclusion category: bugfix bugzilla: https://atomgit.com/src-openeuler/kernel/issues/20408 -------------------------------- Fix kabi breakage in struct bpf_prog_aux. Add KABI_FILL_HOLE for tramp_linked, as there has 2 byte hole for it. struct bpf_prog_aux { atomic64_t refcnt; /* 0 8 */ u32 used_map_cnt; /* 8 4 */ u32 used_btf_cnt; /* 12 4 */ u32 max_ctx_offset; /* 16 4 */ u32 max_pkt_offset; /* 20 4 */ u32 max_tp_access; /* 24 4 */ u32 stack_depth; /* 28 4 */ u32 id; /* 32 4 */ u32 func_cnt; /* 36 4 */ u32 func_idx; /* 40 4 */ u32 attach_btf_id; /* 44 4 */ u32 ctx_arg_info_size; /* 48 4 */ u32 max_rdonly_access; /* 52 4 */ u32 max_rdwr_access; /* 56 4 */ bool is_extended; /* 60 1 */ bool changes_pkt_data; /* 61 1 */ /* XXX 2 bytes hole, try to pack */ /* --- cacheline 1 boundary (64 bytes) --- */ struct btf * attach_btf; /* 64 8 */ const struct bpf_ctx_arg_aux * ctx_arg_info; /* 72 8 */ struct mutex dst_mutex; /* 80 144 */ /* --- cacheline 3 boundary (192 bytes) was 32 bytes ago --- */ struct bpf_prog * dst_prog; /* 224 8 */ struct bpf_trampoline * dst_trampoline; /* 232 8 */ Fixes: c7ac135a792c ("bpf: Wait for an RCU tasks grace period before freeing trampoline progs") Signed-off-by: Pu Lehui <pulehui@huawei.com> --- include/linux/bpf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index e6271a2656d2..b9f187d02d4e 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1551,6 +1551,7 @@ struct bpf_prog_aux { u32 max_rdwr_access; KABI_FILL_HOLE(bool is_extended) /* true if extended by freplace program */ KABI_FILL_HOLE(bool changes_pkt_data) + KABI_FILL_HOLE(bool tramp_linked) /* true if it was ever linked to a trampoline */ struct btf *attach_btf; const struct bpf_ctx_arg_aux *ctx_arg_info; struct mutex dst_mutex; /* protects dst_* pointers below, *after* prog becomes visible */ @@ -1562,7 +1563,6 @@ struct bpf_prog_aux { bool dev_bound; /* Program is bound to the netdev. */ bool offload_requested; /* Program is bound and offloaded to the netdev. */ bool attach_btf_trace; /* true if attaching to BTF-enabled raw tp */ - bool tramp_linked; /* true if it was ever linked to a trampoline */ bool func_proto_unreliable; KABI_DEPRECATE(bool, sleepable) bool tail_call_reachable; -- 2.34.1
participants (2)
-
patchwork bot -
Pu Lehui