* Re: [PATCH v2 bpf-next 4/7] resolve_btfids: Exclude a set of functions by name
2026-11-26 14:29 ` [PATCH v2 bpf-next 4/7] resolve_btfids: Exclude a set of functions by name Anton Protopopov
@ 2026-11-26 14:26 ` sashiko-bot
2026-11-26 14:44 ` Anton Protopopov
0 siblings, 1 reply; 15+ messages in thread
From: sashiko-bot @ 2026-11-26 14:26 UTC (permalink / raw)
To: Anton Protopopov, bpf
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] bpf: missing Fixes: trailer for fmodret_tag() function exclusion
fix
--
commit 2fc421479a0ddf21d6c174ca83ce8384475f3b9a
Author: Anton Protopopov <a.s.protopopov@gmail.com>
> resolve_btfids: Exclude a set of functions by name
>
> ftrace reads the code it patches with copy_from_kernel_nofault(). A
> program which makes it fail breaks the detach of fentry on x86:
>
> unregister_fentry()
> update_ftrace_direct_del() returns 0
> ftrace_replace_code() ftrace_bug(), no text poke
> ftrace_verify_code() -EFAULT
> bpf_tramp_image_put() the function still calls the freed image
>
> On arm64 ftrace reads and writes the code with aarch64_insn_read()
> and aarch64_insn_patch_text_nosync(), which calls
> aarch64_insn_write(). They are traceable without KPROBES. The same
> holds for them. Two more functions break BPF after a skip:
>
> target error after the skip
> ----------------------------- ------- ---------------------------------
> copy_to_kernel_nofault() -EFAULT arm64, with KPROBES too:
> __aarch64_insn_write() fails.
> ftrace_bug(), no text poke.
> text_poke_memcpy() ignores it.
> bpf_arch_text_copy() returns dst.
> The new prog is all BRK insns
> tracepoint_probe_unregister() -ENOENT bpf_raw_tp_link_release() ignores
> it. __bpf_trace_run() reads the
> freed link
>
> Do not tag these six.
>
> Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
[Severity: Low]
Since this fixes unsafe bpf_fmodret_retval tagging in fmodret_tag(), should
it include a Fixes: tag?
Fixes: 4dd950adacad ("resolve_btfids: Tag the functions that return errors")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126142915.1106330-1-a.s.protopopov@gmail.com?part=4
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 bpf-next 7/7] selftests/bpf: Test functions which must have no fmod_ret tag
2026-11-26 14:29 ` [PATCH v2 bpf-next 7/7] selftests/bpf: Test functions which must have no fmod_ret tag Anton Protopopov
@ 2026-11-26 14:27 ` sashiko-bot
2026-11-26 14:48 ` Anton Protopopov
0 siblings, 1 reply; 15+ messages in thread
From: sashiko-bot @ 2026-11-26 14:27 UTC (permalink / raw)
To: Anton Protopopov, bpf
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] selftests/bpf: fmodret_untagged.c duplicates fmodret_retval.c
BTF tag test
--
commit 6b9f59cbaa78b14e32ed408a9747440fae862df8
Author: Anton Protopopov <a.s.protopopov@gmail.com>
selftests/bpf: Test functions which must have no fmod_ret tag
This commit adds a BPF selftest that loads vmlinux BTF and verifies that
specific kernel functions are not tagged with bpf_fmodret_retval:.
> diff --git a/tools/testing/selftests/bpf/prog_tests/fmodret_untagged.c b/tools/testing/selftests/bpf/prog_tests/fmodret_untagged.c
> new file mode 100644
> index 0000000000000..9f4b0586fe8f0
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/fmodret_untagged.c
> @@ -0,0 +1,58 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Functions which return errors, but which the build must not tag as fmod_ret targets */
> +#include <test_progs.h>
> +#include <bpf/btf.h>
> +
> +#define TAG "bpf_fmodret_retval:"
[ ... ]
> +/* Has the build tagged the function FUNC_ID, or any function if FUNC_ID is 0? */
> +static bool tagged(const struct btf *btf, int func_id)
> +{
> + int id;
> +
> + for (id = 1; id < btf__type_cnt(btf); id++) {
> + const struct btf_type *t = btf__type_by_id(btf, id);
> + const char *name = btf__name_by_offset(btf, t->name_off);
> +
> + if (btf_is_decl_tag(t) && (!func_id || t->type == func_id) &&
> + !strncmp(name, TAG, strlen(TAG)))
> + return true;
> + }
> + return false;
> +}
> +
> +void test_fmodret_untagged(void)
> +{
> + struct btf *btf;
> + int i, id;
> +
> + btf = btf__load_vmlinux_btf();
> + if (!ASSERT_OK_PTR(btf, "btf__load_vmlinux_btf"))
> + return;
> + if (!tagged(btf, 0)) {
> + printf("%s:SKIP:no CONFIG_BPF_FMODRET_SCAN\n", __func__);
> + test__skip();
> + goto out;
> + }
> + for (i = 0; i < ARRAY_SIZE(funcs); i++) {
> + id = btf__find_by_name_kind(btf, funcs[i], BTF_KIND_FUNC);
> + if (ASSERT_GT(id, 0, funcs[i]))
> + ASSERT_FALSE(tagged(btf, id), funcs[i]);
> + }
> +out:
> + btf__free(btf);
> +}
[Severity: Low]
This isn't a bug, but could these untagged vmlinux function checks be folded
into tools/testing/selftests/bpf/prog_tests/fmodret_retval.c instead of adding
a separate standalone test file?
test_fmodret_retval() in that file already loads vmlinux_btf, checks for
CONFIG_BPF_FMODRET_SCAN, and scans BTF_KIND_DECL_TAG entries for
bpf_fmodret_retval: via tagged_errors(). Adjusting tagged_errors() to start at
id = btf__base_btf(btf) ? btf__type_cnt(btf__base_btf(btf)) : 1 would let
test_fmodret_retval() check these vmlinux functions directly without
duplicating the BTF load, tag lookup, and skip handling.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126142915.1106330-1-a.s.protopopov@gmail.com?part=7
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 bpf-next 2/7] resolve_btfids: Do not tag functions which work on BPF objects
2026-11-26 14:29 ` [PATCH v2 bpf-next 2/7] resolve_btfids: Do not tag functions which work on BPF objects Anton Protopopov
@ 2026-11-26 14:27 ` sashiko-bot
2026-11-26 14:42 ` Anton Protopopov
0 siblings, 1 reply; 15+ messages in thread
From: sashiko-bot @ 2026-11-26 14:27 UTC (permalink / raw)
To: Anton Protopopov, bpf
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] resolve_btfids: missing Fixes trailer for fmodret_tag() BPF type
exclusion
--
commit 22ec6a5284d69e95482c5c70ca4fae778848a0da
Author: Anton Protopopov <a.s.protopopov@gmail.com>
> resolve_btfids: Do not tag functions which work on BPF objects
>
> A program on tracing_iter_filter() which returns -EACCES makes the
> verifier miss that a global subprog throws. A function which takes or
> returns a bpf_* or btf_* type, or struct btf, works for BPF itself:
> for the verifier, a link or a map. Do not tag it.
>
> __sys_bpf() loses its tag. A program can still deny a bpf command on
> the syscall, which is on the error injection list, or on a
> security_bpf*() hook.
>
> Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
[Severity: Low]
This fixes the tagging of internal BPF functions in fmodret_tag(). Should
the commit message include a Fixes tag:
Fixes: 4dd950adacad ("resolve_btfids: Tag the functions that return errors")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126142915.1106330-1-a.s.protopopov@gmail.com?part=2
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 bpf-next 0/7] Do not tag selected functions as fmodret targets
@ 2026-11-26 14:29 Anton Protopopov
2026-11-26 14:29 ` [PATCH v2 bpf-next 1/7] selftests/bpf: Test the tag of vmlinux with do_epoll_create() Anton Protopopov
` (6 more replies)
0 siblings, 7 replies; 15+ messages in thread
From: Anton Protopopov @ 2026-11-26 14:29 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Jiri Olsa,
Alan Maguire, John Fastabend, bpf
Cc: Anton Protopopov
With CONFIG_BPF_FMODRET_SCAN=y the build tags the functions that
return errors, so that an fmod_ret program can attach to them. Among
them are functions which BPF itself relies on: the verifier, the
trampolines, kfuncs and helpers. As was suggested by Alexei in [1],
we shouldn't tag such functions.
Changes split into a few logcal pieces:
* Patch 1 fixes a selftest which will be otherwise broken by this series.
* Patch 2 excludes the functions which use BPF types.
* Patch 3 excludes kfuncs and helpers.
* Patch 4 adds a static list of functions to exclude,
which contains 6 functions for now.
* Patch 5 excludes bpf_*() and __bpf_*() of vmlinux.
* Patch 6 excludes the code of kernel/bpf/* and of JITs (x86 and arm64).
* Patch 7 adds a corresponding selftest.
In my arm64 vmlinux build this removes 795 tags, 13629 are left.
Precisely,
* Patch 2, BPF types: removes 575 targets
* Patch 3, kfuncs, helpers: removes another 130 targets
* Patch 4, by name: removes another 1 target
* Patch 5, by prefix: removes another 65 targets
* Patch 6, kernel/bpf, JITs: removes another 24 targets
One implementation note: in patch 6 gen-btf.sh lists the symbols with
${NM}, which reads what ${CC} writes, LTO bitcode included, and gives
them to resolve_btfids with --fmodret_deny.
v1 -> v2:
* New patch 1 to fix the selftest which have used the bpf_dummy_reg()
function, which patch 2 untags; use do_epoll_create() and also check that
the one of vmlinux has a tag (ci-bot)
* Add copy_to_kernel_nofault() and tracepoint_probe_unregister() (Alexei)
* Add aarch64_insn_read() and aarch64_insn_write() (bot)
* Drop the *_locked kfuncs, new patch covers them
* Exclude bpf_*() and __bpf_*() of vmlinux (Alexei)
* List the symbols in gen-btf.sh with ${NM} instead of
the llvm-nm of llvm-config, which can be older than
the compiler (Alexei, bot)
* Test functions which only one rule untags
v1: https://lore.kernel.org/bpf/20261125212849.868523-1-a.s.protopopov@gmail.com/
Links:
[1] https://lore.kernel.org/bpf/DN3P7509U44I.MLLYA1W3M3X9@gmail.com/
Anton Protopopov (7):
selftests/bpf: Test the tag of vmlinux with do_epoll_create()
resolve_btfids: Do not tag functions which work on BPF objects
resolve_btfids: Do not tag kfuncs and helpers
resolve_btfids: Exclude a set of functions by name
resolve_btfids: Exclude bpf_*() and __bpf_*() of vmlinux
resolve_btfids: Exclude the code of kernel/bpf and of the JIT
selftests/bpf: Test functions which must have no fmod_ret tag
scripts/gen-btf.sh | 10 ++
tools/bpf/resolve_btfids/fmodret.c | 138 +++++++++++++++++-
tools/bpf/resolve_btfids/fmodret.h | 4 +-
tools/bpf/resolve_btfids/main.c | 5 +-
tools/testing/selftests/bpf/config | 1 +
.../bpf/prog_tests/fmodret_untagged.c | 58 ++++++++
.../selftests/bpf/progs/fmodret_retval.c | 17 ++-
.../bpf/test_kmods/bpf_testmod_retval.c | 6 +
8 files changed, 230 insertions(+), 9 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/fmodret_untagged.c
--
2.43.0
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 bpf-next 1/7] selftests/bpf: Test the tag of vmlinux with do_epoll_create()
2026-11-26 14:29 [PATCH v2 bpf-next 0/7] Do not tag selected functions as fmodret targets Anton Protopopov
@ 2026-11-26 14:29 ` Anton Protopopov
2026-11-26 14:29 ` [PATCH v2 bpf-next 2/7] resolve_btfids: Do not tag functions which work on BPF objects Anton Protopopov
` (5 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Anton Protopopov @ 2026-11-26 14:29 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Jiri Olsa,
Alan Maguire, John Fastabend, bpf
Cc: Anton Protopopov
tag_of_vmlinux attaches to the bpf_dummy_reg() of bpf_testmod. It
shares the FUNC of vmlinux with a bpf_dummy_reg() which has a tag,
and the verifier must not take that tag. But the one of vmlinux takes
a struct bpf_link, and the build is going to stop tagging such
functions. The test would then pass without testing anything.
Use do_epoll_create() instead, and load a program on the one of
vmlinux: if it loses its tag, that test fails. It needs CONFIG_EPOLL,
add it to the config of the selftests. (It is on by default, but make
it explicit.)
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
tools/testing/selftests/bpf/config | 1 +
.../selftests/bpf/progs/fmodret_retval.c | 17 ++++++++++++-----
.../bpf/test_kmods/bpf_testmod_retval.c | 6 ++++++
3 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/bpf/config b/tools/testing/selftests/bpf/config
index 30b744844ef5..ce0db4be4d26 100644
--- a/tools/testing/selftests/bpf/config
+++ b/tools/testing/selftests/bpf/config
@@ -30,6 +30,7 @@ CONFIG_DMABUF_HEAPS=y
CONFIG_DMABUF_HEAPS_SYSTEM=y
CONFIG_DUMMY=y
CONFIG_DYNAMIC_FTRACE=y
+CONFIG_EPOLL=y
CONFIG_FPROBE=y
CONFIG_FTRACE_SYSCALLS=y
CONFIG_FUNCTION_ERROR_INJECTION=y
diff --git a/tools/testing/selftests/bpf/progs/fmodret_retval.c b/tools/testing/selftests/bpf/progs/fmodret_retval.c
index 112f1575ce1f..ae2332bff2f0 100644
--- a/tools/testing/selftests/bpf/progs/fmodret_retval.c
+++ b/tools/testing/selftests/bpf/progs/fmodret_retval.c
@@ -176,13 +176,20 @@ int BPF_PROG(not_a_target, int value, int ret)
return 0;
}
+SEC("fmod_ret/do_epoll_create")
+__success
+int BPF_PROG(tag_in_vmlinux, int flags, int ret)
+{
+ return 0;
+}
+
/*
- * vmlinux has a bpf_dummy_reg() of the same type, so the two share the FUNC of
- * vmlinux. That one returns an error and has a tag. This one returns only 0.
+ * The do_epoll_create() of bpf_testmod has the type of the one of vmlinux, so
+ * the two share the FUNC of vmlinux. This one returns only 0.
*/
-SEC("fmod_ret/bpf_testmod:bpf_dummy_reg")
-__failure __msg("bpf_dummy_reg() is not modifiable")
-int BPF_PROG(tag_of_vmlinux, void *kdata, struct bpf_link *link, int ret)
+SEC("fmod_ret/bpf_testmod:do_epoll_create")
+__failure __msg("do_epoll_create() is not modifiable")
+int BPF_PROG(tag_of_vmlinux, int flags, int ret)
{
return 0;
}
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_retval.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_retval.c
index 85722e48d34c..ba48f0f393f3 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_retval.c
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_retval.c
@@ -159,3 +159,9 @@ static __used noinline __init int bpf_testmod_retval_init(int value)
{
return value ? -EINVAL : -ENOMEM;
}
+
+/* vmlinux has a do_epoll_create() of this type, which returns errors */
+static __used noinline int do_epoll_create(int flags)
+{
+ return 0;
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 bpf-next 2/7] resolve_btfids: Do not tag functions which work on BPF objects
2026-11-26 14:29 [PATCH v2 bpf-next 0/7] Do not tag selected functions as fmodret targets Anton Protopopov
2026-11-26 14:29 ` [PATCH v2 bpf-next 1/7] selftests/bpf: Test the tag of vmlinux with do_epoll_create() Anton Protopopov
@ 2026-11-26 14:29 ` Anton Protopopov
2026-11-26 14:27 ` sashiko-bot
2026-11-26 14:29 ` [PATCH v2 bpf-next 3/7] resolve_btfids: Do not tag kfuncs and helpers Anton Protopopov
` (4 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Anton Protopopov @ 2026-11-26 14:29 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Jiri Olsa,
Alan Maguire, John Fastabend, bpf
Cc: Anton Protopopov
A program on tracing_iter_filter() which returns -EACCES makes the
verifier miss that a global subprog throws. A function which takes or
returns a bpf_* or btf_* type, or struct btf, works for BPF itself:
for the verifier, a link or a map. Do not tag it.
__sys_bpf() loses its tag. A program can still deny a bpf command on
the syscall, which is on the error injection list, or on a
security_bpf*() hook.
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
tools/bpf/resolve_btfids/fmodret.c | 34 ++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/tools/bpf/resolve_btfids/fmodret.c b/tools/bpf/resolve_btfids/fmodret.c
index e1afdb6dedd5..aaff58718da3 100644
--- a/tools/bpf/resolve_btfids/fmodret.c
+++ b/tools/bpf/resolve_btfids/fmodret.c
@@ -56,6 +56,37 @@ static bool fits_trampoline(const struct btf *btf, const struct btf_type *func)
return btf_vlen(t) <= 12;
}
+static bool is_bpf_type(const struct btf *btf, __u32 type)
+{
+ while (type) {
+ const struct btf_type *t = btf__type_by_id(btf, type);
+ const char *name = btf__name_by_offset(btf, t->name_off);
+
+ if (!strncmp(name, "bpf_", 4) || !strcmp(name, "btf") || !strncmp(name, "btf_", 4))
+ return true;
+ if (btf_is_array(t))
+ type = btf_array(t)->type;
+ else if (btf_is_ptr(t) || btf_is_mod(t) || btf_is_typedef(t))
+ type = t->type;
+ else
+ return false;
+ }
+ return false;
+}
+
+static bool has_bpf_types(const struct btf *btf, const struct btf_type *func)
+{
+ const struct btf_type *proto = btf__type_by_id(btf, func->type);
+ unsigned int i;
+
+ if (is_bpf_type(btf, proto->type))
+ return true;
+ for (i = 0; i < btf_vlen(proto); i++)
+ if (is_bpf_type(btf, btf_params(proto)[i].type))
+ return true;
+ return false;
+}
+
/*
* The codes of include/linux/errno.h, 512 and up, never reach user space. They,
* -EAGAIN, -EMSGSIZE and -EINPROGRESS tell the caller to retry, to go on or to
@@ -220,6 +251,9 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
size = int_return_size(btf, t);
if ((size != 4 && size != 8) || !fits_trampoline(btf, t))
continue;
+ /* Skip functions which take or return BPF objects */
+ if (has_bpf_types(btf, t))
+ continue;
/* Init code is gone before a program can attach */
name = btf__name_by_offset(btf, t->name_off);
func = image_func(&img, name);
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 bpf-next 3/7] resolve_btfids: Do not tag kfuncs and helpers
2026-11-26 14:29 [PATCH v2 bpf-next 0/7] Do not tag selected functions as fmodret targets Anton Protopopov
2026-11-26 14:29 ` [PATCH v2 bpf-next 1/7] selftests/bpf: Test the tag of vmlinux with do_epoll_create() Anton Protopopov
2026-11-26 14:29 ` [PATCH v2 bpf-next 2/7] resolve_btfids: Do not tag functions which work on BPF objects Anton Protopopov
@ 2026-11-26 14:29 ` Anton Protopopov
2026-11-26 14:29 ` [PATCH v2 bpf-next 4/7] resolve_btfids: Exclude a set of functions by name Anton Protopopov
` (3 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Anton Protopopov @ 2026-11-26 14:29 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Jiri Olsa,
Alan Maguire, John Fastabend, bpf
Cc: Anton Protopopov
The verifier relies on what a kfunc or a helper does, also on an
error. bpf_skb_load_bytes() clears the buffer on an error, and the
verifier takes it as initialized. After a skip a socket filter reads
what was on the kernel stack.
Do not tag the functions with the "bpf_kfunc" decl tag. A helper
takes only u64 values, so the bpf_* types do not tell it.
BPF_CALL_x() declares a typedef btf_<helper> for each: do not tag the
function of such a typedef.
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
tools/bpf/resolve_btfids/fmodret.c | 32 ++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/tools/bpf/resolve_btfids/fmodret.c b/tools/bpf/resolve_btfids/fmodret.c
index aaff58718da3..7d26a5c9b028 100644
--- a/tools/bpf/resolve_btfids/fmodret.c
+++ b/tools/bpf/resolve_btfids/fmodret.c
@@ -87,6 +87,29 @@ static bool has_bpf_types(const struct btf *btf, const struct btf_type *func)
return false;
}
+/* Find kfuncs and helpers */
+static bool *find_bpf_funcs(const struct btf *btf)
+{
+ const struct btf *base = btf__base_btf(btf);
+ __u32 id, nr_types = btf__type_cnt(btf);
+ bool *funcs = calloc(nr_types, sizeof(*funcs));
+
+ for (id = base ? btf__type_cnt(base) : 1; funcs && id < nr_types; id++) {
+ const struct btf_type *t = btf__type_by_id(btf, id);
+ const char *name = btf__name_by_offset(btf, t->name_off);
+
+ if (btf_is_decl_tag(t) && !strcmp(name, "bpf_kfunc"))
+ funcs[t->type] = true;
+ if (btf_is_typedef(t) && !strncmp(name, "btf_", 4) && strncmp(name, "btf_trace_", 10)) {
+ int func = btf__find_by_name_kind(btf, name + 4, BTF_KIND_FUNC);
+
+ if (func > 0)
+ funcs[func] = true;
+ }
+ }
+ return funcs;
+}
+
/*
* The codes of include/linux/errno.h, 512 and up, never reach user space. They,
* -EAGAIN, -EMSGSIZE and -EINPROGRESS tell the caller to retry, to go on or to
@@ -225,6 +248,7 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
const struct btf *base = btf__base_btf(btf);
__u32 id, nr_types = btf__type_cnt(btf);
struct scan *scan = NULL;
+ bool *bpf_funcs = NULL;
struct image img;
char counts[200];
int err;
@@ -237,6 +261,10 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
if (!scan)
goto out;
set_protos(scan, &img, btf);
+ err = -ENOMEM;
+ bpf_funcs = find_bpf_funcs(btf);
+ if (!bpf_funcs)
+ goto out;
for (id = base ? btf__type_cnt(base) : 1, err = 0; id < nr_types && err >= 0; id++) {
const struct btf_type *t = btf__type_by_id(btf, id);
@@ -254,6 +282,9 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
/* Skip functions which take or return BPF objects */
if (has_bpf_types(btf, t))
continue;
+ /* Skip kfuncs and helpers which escaped the previous check */
+ if (bpf_funcs[id])
+ continue;
/* Init code is gone before a program can attach */
name = btf__name_by_offset(btf, t->name_off);
func = image_func(&img, name);
@@ -291,6 +322,7 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
printf(" FMODRET %s\n", counts);
}
out:
+ free(bpf_funcs);
scan_close(scan);
image_close(&img);
return err < 0 ? err : 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 bpf-next 4/7] resolve_btfids: Exclude a set of functions by name
2026-11-26 14:29 [PATCH v2 bpf-next 0/7] Do not tag selected functions as fmodret targets Anton Protopopov
` (2 preceding siblings ...)
2026-11-26 14:29 ` [PATCH v2 bpf-next 3/7] resolve_btfids: Do not tag kfuncs and helpers Anton Protopopov
@ 2026-11-26 14:29 ` Anton Protopopov
2026-11-26 14:26 ` sashiko-bot
2026-11-26 14:29 ` [PATCH v2 bpf-next 5/7] resolve_btfids: Exclude bpf_*() and __bpf_*() of vmlinux Anton Protopopov
` (2 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Anton Protopopov @ 2026-11-26 14:29 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Jiri Olsa,
Alan Maguire, John Fastabend, bpf
Cc: Anton Protopopov
ftrace reads the code it patches with copy_from_kernel_nofault(). A
program which makes it fail breaks the detach of fentry on x86:
unregister_fentry()
update_ftrace_direct_del() returns 0
ftrace_replace_code() ftrace_bug(), no text poke
ftrace_verify_code() -EFAULT
bpf_tramp_image_put() the function still calls the freed image
On arm64 ftrace reads and writes the code with aarch64_insn_read()
and aarch64_insn_patch_text_nosync(), which calls
aarch64_insn_write(). They are traceable without KPROBES. The same
holds for them. Two more functions break BPF after a skip:
target error after the skip
----------------------------- ------- ---------------------------------
copy_to_kernel_nofault() -EFAULT arm64, with KPROBES too:
__aarch64_insn_write() fails.
ftrace_bug(), no text poke.
text_poke_memcpy() ignores it.
bpf_arch_text_copy() returns dst.
The new prog is all BRK insns
tracepoint_probe_unregister() -ENOENT bpf_raw_tp_link_release() ignores
it. __bpf_trace_run() reads the
freed link
Do not tag these six.
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
tools/bpf/resolve_btfids/fmodret.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/tools/bpf/resolve_btfids/fmodret.c b/tools/bpf/resolve_btfids/fmodret.c
index 7d26a5c9b028..b425208702b4 100644
--- a/tools/bpf/resolve_btfids/fmodret.c
+++ b/tools/bpf/resolve_btfids/fmodret.c
@@ -87,6 +87,24 @@ static bool has_bpf_types(const struct btf *btf, const struct btf_type *func)
return false;
}
+static bool excluded_by_name(const char *name)
+{
+ static const char *const names[] = {
+ "copy_from_kernel_nofault",
+ "copy_to_kernel_nofault",
+ "aarch64_insn_read",
+ "aarch64_insn_write",
+ "aarch64_insn_patch_text_nosync",
+ "tracepoint_probe_unregister",
+ };
+ unsigned int i;
+
+ for (i = 0; i < sizeof(names) / sizeof(names[0]); i++)
+ if (!strcmp(name, names[i]))
+ return true;
+ return false;
+}
+
/* Find kfuncs and helpers */
static bool *find_bpf_funcs(const struct btf *btf)
{
@@ -290,6 +308,8 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
func = image_func(&img, name);
if (!func || !strcmp(func->section, ".init.text"))
continue;
+ if (excluded_by_name(name))
+ continue;
nr_scanned++;
err = scan_func(scan, func, &values);
if (err == -EINVAL) {
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 bpf-next 5/7] resolve_btfids: Exclude bpf_*() and __bpf_*() of vmlinux
2026-11-26 14:29 [PATCH v2 bpf-next 0/7] Do not tag selected functions as fmodret targets Anton Protopopov
` (3 preceding siblings ...)
2026-11-26 14:29 ` [PATCH v2 bpf-next 4/7] resolve_btfids: Exclude a set of functions by name Anton Protopopov
@ 2026-11-26 14:29 ` Anton Protopopov
2026-11-26 15:01 ` bot+bpf-ci
2026-11-26 14:29 ` [PATCH v2 bpf-next 6/7] resolve_btfids: Exclude the code of kernel/bpf and of the JIT Anton Protopopov
2026-11-26 14:29 ` [PATCH v2 bpf-next 7/7] selftests/bpf: Test functions which must have no fmod_ret tag Anton Protopopov
6 siblings, 1 reply; 15+ messages in thread
From: Anton Protopopov @ 2026-11-26 14:29 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Jiri Olsa,
Alan Maguire, John Fastabend, bpf
Cc: Anton Protopopov
bpf_unlocked_sk_getsockopt() has no tag, but it passes optval, an
ARG_PTR_TO_UNINIT_MEM buffer, to __bpf_getsockopt(). That one clears
the buffer on an error. It takes no BPF type and is in net/core, so
it keeps its tag. After a skip the program reads its stack.
__bpf_skb_load_bytes() has the same memset() before -EFAULT.
Do not tag bpf_*() and __bpf_*() of vmlinux. This also covers
bpf_set_dentry_xattr_locked() and bpf_remove_dentry_xattr_locked(),
kfuncs without the "bpf_kfunc" tag: specialize_kfunc() calls them
instead of the kfuncs without _locked. The functions of modules keep
their tags, the selftests need bpf_testmod_retval_*().
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
tools/bpf/resolve_btfids/fmodret.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tools/bpf/resolve_btfids/fmodret.c b/tools/bpf/resolve_btfids/fmodret.c
index b425208702b4..d2d4db1ca3d5 100644
--- a/tools/bpf/resolve_btfids/fmodret.c
+++ b/tools/bpf/resolve_btfids/fmodret.c
@@ -105,6 +105,12 @@ static bool excluded_by_name(const char *name)
return false;
}
+/* bpf_*() and __bpf_*() */
+static bool excluded_by_prefix(const char *name, bool vmlinux)
+{
+ return vmlinux && !strncmp(name + strspn(name, "_"), "bpf_", 4);
+}
+
/* Find kfuncs and helpers */
static bool *find_bpf_funcs(const struct btf *btf)
{
@@ -310,6 +316,8 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
continue;
if (excluded_by_name(name))
continue;
+ if (excluded_by_prefix(name, !base))
+ continue;
nr_scanned++;
err = scan_func(scan, func, &values);
if (err == -EINVAL) {
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 bpf-next 6/7] resolve_btfids: Exclude the code of kernel/bpf and of the JIT
2026-11-26 14:29 [PATCH v2 bpf-next 0/7] Do not tag selected functions as fmodret targets Anton Protopopov
` (4 preceding siblings ...)
2026-11-26 14:29 ` [PATCH v2 bpf-next 5/7] resolve_btfids: Exclude bpf_*() and __bpf_*() of vmlinux Anton Protopopov
@ 2026-11-26 14:29 ` Anton Protopopov
2026-11-26 14:29 ` [PATCH v2 bpf-next 7/7] selftests/bpf: Test functions which must have no fmod_ret tag Anton Protopopov
6 siblings, 0 replies; 15+ messages in thread
From: Anton Protopopov @ 2026-11-26 14:29 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Jiri Olsa,
Alan Maguire, John Fastabend, bpf
Cc: Anton Protopopov, Alexei Starovoitov
Not every function of kernel/bpf and of the JIT has a BPF type in its
prototype or a bpf_ prefix, e.g. check_attach_modify_return() of the
verifier, range_tree_set() and btf_get_fd_by_id(). Let gen-btf.sh
list the symbols of kernel/bpf/built-in.a and
arch/${SRCARCH}/net/built-in.a with ${NM}, which reads what ${CC}
writes, LTO bitcode included. resolve_btfids gets the list with
--fmodret_deny and does not tag these functions.
Weak symbols count too. Only one tagged function outside BPF has a
weak copy in kernel/bpf, skb_copy_bits(), and it loses its tag. BPF
helpers call it, so this is acceptable.
Co-developed-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Signed-off-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
scripts/gen-btf.sh | 10 +++++++
tools/bpf/resolve_btfids/fmodret.c | 46 ++++++++++++++++++++++++++++--
tools/bpf/resolve_btfids/fmodret.h | 4 +--
tools/bpf/resolve_btfids/main.c | 5 +++-
4 files changed, 60 insertions(+), 5 deletions(-)
diff --git a/scripts/gen-btf.sh b/scripts/gen-btf.sh
index b17f1189298a..af40d746f218 100755
--- a/scripts/gen-btf.sh
+++ b/scripts/gen-btf.sh
@@ -75,8 +75,17 @@ gen_btf_data()
--btf_encode_detached=${btf1} \
"${ELF_FILE}"
+ # The code of BPF itself is not a target of fmod_ret
+ fmodret_deny=
+ if [ -z "${BTF_BASE}" ] && is_enabled CONFIG_BPF_FMODRET_SCAN; then
+ fmodret_deny="${ELF_FILE}.fmodret_deny"
+ ${NM} --defined-only ${objtree}/kernel/bpf/built-in.a \
+ ${objtree}/arch/${SRCARCH}/net/built-in.a > ${fmodret_deny}
+ fi
+
${RESOLVE_BTFIDS} ${RESOLVE_BTFIDS_FLAGS} \
${BTF_BASE:+--btf_base ${BTF_BASE}} \
+ ${fmodret_deny:+--fmodret_deny ${fmodret_deny}} \
${inline} \
--btf ${btf1} "${ELF_FILE}"
}
@@ -148,6 +157,7 @@ cleanup()
rm -f "${ELF_FILE}.BTF"
rm -f "${ELF_FILE}.BTF.inline"
rm -f "${ELF_FILE}.BTF.inline.link"
+ rm -f "${ELF_FILE}.fmodret_deny"
if [ "${BTFGEN_MODE}" = "module" ]; then
rm -f "${ELF_FILE}.BTF.base"
rm -f "${ELF_FILE}.BTF_ids"
diff --git a/tools/bpf/resolve_btfids/fmodret.c b/tools/bpf/resolve_btfids/fmodret.c
index d2d4db1ca3d5..b950d6b52554 100644
--- a/tools/bpf/resolve_btfids/fmodret.c
+++ b/tools/bpf/resolve_btfids/fmodret.c
@@ -266,13 +266,46 @@ static void set_protos(struct scan *scan, const struct image *img, const struct
}
}
-int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
+/*
+ * Mark the functions of IMG which are in PATH, the output of nm. The line of a
+ * symbol is "<address> <type> <name>". The other lines have fewer words.
+ */
+static bool *read_denied(const struct image *img, const char *path)
+{
+ bool *denied = calloc(img->nr_funcs, sizeof(*denied));
+ FILE *f = fopen(path, "r");
+ char line[1024], name[1024];
+
+ if (!denied || !f) {
+ fprintf(stderr, "FAILED: --fmodret_deny: cannot read %s\n", path);
+ free(denied);
+ denied = NULL;
+ }
+ while (denied && fgets(line, sizeof(line), f)) {
+ const struct image_func *func = NULL;
+
+ if (sscanf(line, "%*s %*s %1023s", name) == 1)
+ func = image_func(img, name);
+ if (func)
+ denied[func - img->funcs] = true;
+ }
+ if (denied && !feof(f)) {
+ fprintf(stderr, "FAILED: --fmodret_deny: cannot read %s\n", path);
+ free(denied);
+ denied = NULL;
+ }
+ if (f)
+ fclose(f);
+ return denied;
+}
+
+int fmodret_tag(Elf *elf, struct btf *btf, const char *deny_path, int verbose)
{
size_t nr_funcs = 0, nr_scanned = 0, nr_undecodable = 0, nr_tags = 0;
const struct btf *base = btf__base_btf(btf);
__u32 id, nr_types = btf__type_cnt(btf);
struct scan *scan = NULL;
- bool *bpf_funcs = NULL;
+ bool *bpf_funcs = NULL, *denied = NULL;
struct image img;
char counts[200];
int err;
@@ -289,6 +322,11 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
bpf_funcs = find_bpf_funcs(btf);
if (!bpf_funcs)
goto out;
+ if (deny_path) {
+ denied = read_denied(&img, deny_path);
+ if (!denied)
+ goto out;
+ }
for (id = base ? btf__type_cnt(base) : 1, err = 0; id < nr_types && err >= 0; id++) {
const struct btf_type *t = btf__type_by_id(btf, id);
@@ -318,6 +356,9 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
continue;
if (excluded_by_prefix(name, !base))
continue;
+ /* Skip the code of kernel/bpf and of the JIT */
+ if (denied && denied[func - img.funcs])
+ continue;
nr_scanned++;
err = scan_func(scan, func, &values);
if (err == -EINVAL) {
@@ -350,6 +391,7 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
printf(" FMODRET %s\n", counts);
}
out:
+ free(denied);
free(bpf_funcs);
scan_close(scan);
image_close(&img);
diff --git a/tools/bpf/resolve_btfids/fmodret.h b/tools/bpf/resolve_btfids/fmodret.h
index d61a9de026df..177b116ee799 100644
--- a/tools/bpf/resolve_btfids/fmodret.h
+++ b/tools/bpf/resolve_btfids/fmodret.h
@@ -6,7 +6,7 @@
struct btf;
-/* Tag the functions of ELF which return errors in BTF */
-int fmodret_tag(Elf *elf, struct btf *btf, int verbose);
+/* Tag the functions of ELF which return errors in BTF, but not those in DENY_PATH */
+int fmodret_tag(Elf *elf, struct btf *btf, const char *deny_path, int verbose);
#endif
diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
index 0ac895222a14..919b301e88f3 100644
--- a/tools/bpf/resolve_btfids/main.c
+++ b/tools/bpf/resolve_btfids/main.c
@@ -2104,6 +2104,7 @@ int main(int argc, const char **argv)
bool fatal_warnings = false;
bool resolve_btfids = true;
bool fmodret_scan = false;
+ const char *fmodret_deny = NULL;
char out_path[PATH_MAX];
struct option btfid_options[] = {
@@ -2121,6 +2122,8 @@ int main(int argc, const char **argv)
"extract location BTF into a .BTF.inline file"),
OPT_BOOLEAN(0, "fmodret_scan", &fmodret_scan,
"tag the functions which return errors as fmod_ret targets"),
+ OPT_STRING(0, "fmodret_deny", &fmodret_deny, "file",
+ "output of nm with the functions which get no tag"),
OPT_CALLBACK(0, "btf_link", &btf_links, "section:module:btf-file",
"patch a BTF link with --patch_btfids", parse_btf_link),
OPT_STRING(0, "patch_btfids", &btfids_path, "file",
@@ -2182,7 +2185,7 @@ int main(int argc, const char **argv)
if (btf2btf(&obj))
goto out;
- if (fmodret_scan && fmodret_tag(obj.efile.elf, obj.btf, verbose))
+ if (fmodret_scan && fmodret_tag(obj.efile.elf, obj.btf, fmodret_deny, verbose))
goto out;
if (finalize_btf(&obj))
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 bpf-next 7/7] selftests/bpf: Test functions which must have no fmod_ret tag
2026-11-26 14:29 [PATCH v2 bpf-next 0/7] Do not tag selected functions as fmodret targets Anton Protopopov
` (5 preceding siblings ...)
2026-11-26 14:29 ` [PATCH v2 bpf-next 6/7] resolve_btfids: Exclude the code of kernel/bpf and of the JIT Anton Protopopov
@ 2026-11-26 14:29 ` Anton Protopopov
2026-11-26 14:27 ` sashiko-bot
6 siblings, 1 reply; 15+ messages in thread
From: Anton Protopopov @ 2026-11-26 14:29 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Jiri Olsa,
Alan Maguire, John Fastabend, bpf
Cc: Anton Protopopov
Check in the BTF of vmlinux that the build has not tagged a few
functions which return errors. Each of them loses its tag by one rule
only: two which work on BPF objects, a helper, one which is excluded
by name, one by prefix, and one of kernel/bpf.
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
.../bpf/prog_tests/fmodret_untagged.c | 58 +++++++++++++++++++
1 file changed, 58 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/fmodret_untagged.c
diff --git a/tools/testing/selftests/bpf/prog_tests/fmodret_untagged.c b/tools/testing/selftests/bpf/prog_tests/fmodret_untagged.c
new file mode 100644
index 000000000000..9f4b0586fe8f
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/fmodret_untagged.c
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Functions which return errors, but which the build must not tag as fmod_ret targets */
+#include <test_progs.h>
+#include <bpf/btf.h>
+
+#define TAG "bpf_fmodret_retval:"
+
+static const char * const funcs[] = {
+ /* They work on BPF objects */
+ "tracing_iter_filter",
+ "sock_map_delete_elem",
+ /* A helper */
+ "sk_skb_adjust_room",
+ /* By name */
+ "copy_from_kernel_nofault",
+ /* By prefix */
+ "bpf_sk_storage_clone",
+ /* Of kernel/bpf */
+ "range_tree_set",
+};
+
+/* Has the build tagged the function FUNC_ID, or any function if FUNC_ID is 0? */
+static bool tagged(const struct btf *btf, int func_id)
+{
+ int id;
+
+ for (id = 1; id < btf__type_cnt(btf); id++) {
+ const struct btf_type *t = btf__type_by_id(btf, id);
+ const char *name = btf__name_by_offset(btf, t->name_off);
+
+ if (btf_is_decl_tag(t) && (!func_id || t->type == func_id) &&
+ !strncmp(name, TAG, strlen(TAG)))
+ return true;
+ }
+ return false;
+}
+
+void test_fmodret_untagged(void)
+{
+ struct btf *btf;
+ int i, id;
+
+ btf = btf__load_vmlinux_btf();
+ if (!ASSERT_OK_PTR(btf, "btf__load_vmlinux_btf"))
+ return;
+ if (!tagged(btf, 0)) {
+ printf("%s:SKIP:no CONFIG_BPF_FMODRET_SCAN\n", __func__);
+ test__skip();
+ goto out;
+ }
+ for (i = 0; i < ARRAY_SIZE(funcs); i++) {
+ id = btf__find_by_name_kind(btf, funcs[i], BTF_KIND_FUNC);
+ if (ASSERT_GT(id, 0, funcs[i]))
+ ASSERT_FALSE(tagged(btf, id), funcs[i]);
+ }
+out:
+ btf__free(btf);
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2 bpf-next 2/7] resolve_btfids: Do not tag functions which work on BPF objects
2026-11-26 14:27 ` sashiko-bot
@ 2026-11-26 14:42 ` Anton Protopopov
0 siblings, 0 replies; 15+ messages in thread
From: Anton Protopopov @ 2026-11-26 14:42 UTC (permalink / raw)
To: sashiko-reviews; +Cc: bpf
On 26/11/26 02:27PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Low] resolve_btfids: missing Fixes trailer for fmodret_tag() BPF type
> exclusion
> --
>
> commit 22ec6a5284d69e95482c5c70ca4fae778848a0da
> Author: Anton Protopopov <a.s.protopopov@gmail.com>
>
> > resolve_btfids: Do not tag functions which work on BPF objects
> >
> > A program on tracing_iter_filter() which returns -EACCES makes the
> > verifier miss that a global subprog throws. A function which takes or
> > returns a bpf_* or btf_* type, or struct btf, works for BPF itself:
> > for the verifier, a link or a map. Do not tag it.
> >
> > __sys_bpf() loses its tag. A program can still deny a bpf command on
> > the syscall, which is on the error injection list, or on a
> > security_bpf*() hook.
> >
> > Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
>
> [Severity: Low]
> This fixes the tagging of internal BPF functions in fmodret_tag(). Should
> the commit message include a Fixes tag:
>
> Fixes: 4dd950adacad ("resolve_btfids: Tag the functions that return errors")
I can add it if robots continue to complain, but I am not really
seeing why. What will this tag signal?
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261126142915.1106330-1-a.s.protopopov@gmail.com?part=2
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 bpf-next 4/7] resolve_btfids: Exclude a set of functions by name
2026-11-26 14:26 ` sashiko-bot
@ 2026-11-26 14:44 ` Anton Protopopov
0 siblings, 0 replies; 15+ messages in thread
From: Anton Protopopov @ 2026-11-26 14:44 UTC (permalink / raw)
To: sashiko-reviews; +Cc: bpf
On 26/11/26 02:26PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Low] bpf: missing Fixes: trailer for fmodret_tag() function exclusion
> fix
> --
>
> commit 2fc421479a0ddf21d6c174ca83ce8384475f3b9a
> Author: Anton Protopopov <a.s.protopopov@gmail.com>
>
> > resolve_btfids: Exclude a set of functions by name
> >
> > ftrace reads the code it patches with copy_from_kernel_nofault(). A
> > program which makes it fail breaks the detach of fentry on x86:
> >
> > unregister_fentry()
> > update_ftrace_direct_del() returns 0
> > ftrace_replace_code() ftrace_bug(), no text poke
> > ftrace_verify_code() -EFAULT
> > bpf_tramp_image_put() the function still calls the freed image
> >
> > On arm64 ftrace reads and writes the code with aarch64_insn_read()
> > and aarch64_insn_patch_text_nosync(), which calls
> > aarch64_insn_write(). They are traceable without KPROBES. The same
> > holds for them. Two more functions break BPF after a skip:
> >
> > target error after the skip
> > ----------------------------- ------- ---------------------------------
> > copy_to_kernel_nofault() -EFAULT arm64, with KPROBES too:
> > __aarch64_insn_write() fails.
> > ftrace_bug(), no text poke.
> > text_poke_memcpy() ignores it.
> > bpf_arch_text_copy() returns dst.
> > The new prog is all BRK insns
> > tracepoint_probe_unregister() -ENOENT bpf_raw_tp_link_release() ignores
> > it. __bpf_trace_run() reads the
> > freed link
> >
> > Do not tag these six.
> >
> > Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
>
> [Severity: Low]
> Since this fixes unsafe bpf_fmodret_retval tagging in fmodret_tag(), should
> it include a Fixes: tag?
>
> Fixes: 4dd950adacad ("resolve_btfids: Tag the functions that return errors")
Same. Will add it if another version will be needed.
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261126142915.1106330-1-a.s.protopopov@gmail.com?part=4
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 bpf-next 7/7] selftests/bpf: Test functions which must have no fmod_ret tag
2026-11-26 14:27 ` sashiko-bot
@ 2026-11-26 14:48 ` Anton Protopopov
0 siblings, 0 replies; 15+ messages in thread
From: Anton Protopopov @ 2026-11-26 14:48 UTC (permalink / raw)
To: sashiko-reviews; +Cc: bpf
On 26/11/26 02:27PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Low] selftests/bpf: fmodret_untagged.c duplicates fmodret_retval.c
> BTF tag test
> --
>
> commit 6b9f59cbaa78b14e32ed408a9747440fae862df8
> Author: Anton Protopopov <a.s.protopopov@gmail.com>
>
> selftests/bpf: Test functions which must have no fmod_ret tag
>
> This commit adds a BPF selftest that loads vmlinux BTF and verifies that
> specific kernel functions are not tagged with bpf_fmodret_retval:.
>
> > diff --git a/tools/testing/selftests/bpf/prog_tests/fmodret_untagged.c b/tools/testing/selftests/bpf/prog_tests/fmodret_untagged.c
> > new file mode 100644
> > index 0000000000000..9f4b0586fe8f0
> > --- /dev/null
> > +++ b/tools/testing/selftests/bpf/prog_tests/fmodret_untagged.c
> > @@ -0,0 +1,58 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/* Functions which return errors, but which the build must not tag as fmod_ret targets */
> > +#include <test_progs.h>
> > +#include <bpf/btf.h>
> > +
> > +#define TAG "bpf_fmodret_retval:"
>
> [ ... ]
>
> > +/* Has the build tagged the function FUNC_ID, or any function if FUNC_ID is 0? */
> > +static bool tagged(const struct btf *btf, int func_id)
> > +{
> > + int id;
> > +
> > + for (id = 1; id < btf__type_cnt(btf); id++) {
> > + const struct btf_type *t = btf__type_by_id(btf, id);
> > + const char *name = btf__name_by_offset(btf, t->name_off);
> > +
> > + if (btf_is_decl_tag(t) && (!func_id || t->type == func_id) &&
> > + !strncmp(name, TAG, strlen(TAG)))
> > + return true;
> > + }
> > + return false;
> > +}
> > +
> > +void test_fmodret_untagged(void)
> > +{
> > + struct btf *btf;
> > + int i, id;
> > +
> > + btf = btf__load_vmlinux_btf();
> > + if (!ASSERT_OK_PTR(btf, "btf__load_vmlinux_btf"))
> > + return;
> > + if (!tagged(btf, 0)) {
> > + printf("%s:SKIP:no CONFIG_BPF_FMODRET_SCAN\n", __func__);
> > + test__skip();
> > + goto out;
> > + }
> > + for (i = 0; i < ARRAY_SIZE(funcs); i++) {
> > + id = btf__find_by_name_kind(btf, funcs[i], BTF_KIND_FUNC);
> > + if (ASSERT_GT(id, 0, funcs[i]))
> > + ASSERT_FALSE(tagged(btf, id), funcs[i]);
> > + }
> > +out:
> > + btf__free(btf);
> > +}
>
> [Severity: Low]
> This isn't a bug, but could these untagged vmlinux function checks be folded
> into tools/testing/selftests/bpf/prog_tests/fmodret_retval.c instead of adding
> a separate standalone test file?
>
> test_fmodret_retval() in that file already loads vmlinux_btf, checks for
> CONFIG_BPF_FMODRET_SCAN, and scans BTF_KIND_DECL_TAG entries for
> bpf_fmodret_retval: via tagged_errors(). Adjusting tagged_errors() to start at
> id = btf__base_btf(btf) ? btf__type_cnt(btf__base_btf(btf)) : 1 would let
> test_fmodret_retval() check these vmlinux functions directly without
> duplicating the BTF load, tag lookup, and skip handling.
Will do if v3 will be needed.
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261126142915.1106330-1-a.s.protopopov@gmail.com?part=7
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 bpf-next 5/7] resolve_btfids: Exclude bpf_*() and __bpf_*() of vmlinux
2026-11-26 14:29 ` [PATCH v2 bpf-next 5/7] resolve_btfids: Exclude bpf_*() and __bpf_*() of vmlinux Anton Protopopov
@ 2026-11-26 15:01 ` bot+bpf-ci
0 siblings, 0 replies; 15+ messages in thread
From: bot+bpf-ci @ 2026-11-26 15:01 UTC (permalink / raw)
To: a.s.protopopov, ast, daniel, andrii, eddyz87, memxor, jolsa,
almagui, john.fastabend, bpf
Cc: a.s.protopopov, ast, andrii, daniel, martin.lau, eddyz87,
yonghong.song, mason, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 1937 bytes --]
> resolve_btfids: Exclude bpf_*() and __bpf_*() of vmlinux
TL;DR: Comment and commit message only: the code also excludes _bpf_*() and
___bpf_*() names, broader than documented; the review asks to document this,
citing _bpf_getsockopt().
> diff --git a/tools/bpf/resolve_btfids/fmodret.c b/tools/bpf/resolve_btfids/fmodret.c
> --- a/tools/bpf/resolve_btfids/fmodret.c
> +++ b/tools/bpf/resolve_btfids/fmodret.c
[ ... ]
> @@ -105,6 +105,12 @@ static bool excluded_by_name(const char *name)
> return false;
> }
>
> +/* bpf_*() and __bpf_*() */
> +static bool excluded_by_prefix(const char *name, bool vmlinux)
> +{
> + return vmlinux && !strncmp(name + strspn(name, "_"), "bpf_", 4);
> +}
This isn't a bug, but the comment and the commit message ("Do not tag
bpf_*() and __bpf_*() of vmlinux") describe a narrower rule than the code.
strspn(name, "_") skips any number of leading underscores, so _bpf_*() and
___bpf_*() names are excluded as well. In vmlinux these include
_bpf_getsockopt(), _bpf_setsockopt(), ___bpf_prog_run() and
___bpf_copy_key().
The broader behaviour looks right, since _bpf_getsockopt() sits on the
chain the commit is concerned with:
BPF_CALL_5(bpf_sk_getsockopt, ...)
{
return _bpf_getsockopt(sk, level, optname, optval, optlen);
}
If the compiler keeps _bpf_getsockopt() out of line, an fmod_ret skip of it
would bypass the memset() in __bpf_getsockopt() in the same way. A later
change that makes the code match the comment (for example, two strncmp()
calls for "bpf_" and "__bpf_") would reopen that hole.
Could the comment and changelog say "bpf_*() after any leading
underscores", and name _bpf_getsockopt() as a reason?
[ ... ]
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45839706175
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2026-11-26 15:01 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 14:29 [PATCH v2 bpf-next 0/7] Do not tag selected functions as fmodret targets Anton Protopopov
2026-11-26 14:29 ` [PATCH v2 bpf-next 1/7] selftests/bpf: Test the tag of vmlinux with do_epoll_create() Anton Protopopov
2026-11-26 14:29 ` [PATCH v2 bpf-next 2/7] resolve_btfids: Do not tag functions which work on BPF objects Anton Protopopov
2026-11-26 14:27 ` sashiko-bot
2026-11-26 14:42 ` Anton Protopopov
2026-11-26 14:29 ` [PATCH v2 bpf-next 3/7] resolve_btfids: Do not tag kfuncs and helpers Anton Protopopov
2026-11-26 14:29 ` [PATCH v2 bpf-next 4/7] resolve_btfids: Exclude a set of functions by name Anton Protopopov
2026-11-26 14:26 ` sashiko-bot
2026-11-26 14:44 ` Anton Protopopov
2026-11-26 14:29 ` [PATCH v2 bpf-next 5/7] resolve_btfids: Exclude bpf_*() and __bpf_*() of vmlinux Anton Protopopov
2026-11-26 15:01 ` bot+bpf-ci
2026-11-26 14:29 ` [PATCH v2 bpf-next 6/7] resolve_btfids: Exclude the code of kernel/bpf and of the JIT Anton Protopopov
2026-11-26 14:29 ` [PATCH v2 bpf-next 7/7] selftests/bpf: Test functions which must have no fmod_ret tag Anton Protopopov
2026-11-26 14:27 ` sashiko-bot
2026-11-26 14:48 ` Anton Protopopov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox