* Re: [PATCH v1 bpf-next 1/5] resolve_btfids: Do not tag functions which work on BPF objects
2026-11-25 21:28 ` [PATCH v1 bpf-next 1/5] resolve_btfids: Do not tag functions which work on BPF objects Anton Protopopov
@ 2026-11-25 21:25 ` sashiko-bot
2026-11-26 10:50 ` Anton Protopopov
2026-11-25 22:14 ` bot+bpf-ci
1 sibling, 1 reply; 17+ messages in thread
From: sashiko-bot @ 2026-11-25 21:25 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 36940d1b337a769c63009cfc2b22cfd69fcc61f9
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 a bug in the automatic fmod_ret tagging where internal BPF
functions were left modifiable. Should this include:
Fixes: 4dd950adacad ("resolve_btfids: Tag the functions that return errors")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125212849.868523-1-a.s.protopopov@gmail.com?part=1
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 bpf-next 0/5] Do not tag selected functions as fmodret targets
@ 2026-11-25 21:28 Anton Protopopov
2026-11-25 21:28 ` [PATCH v1 bpf-next 1/5] resolve_btfids: Do not tag functions which work on BPF objects Anton Protopopov
` (4 more replies)
0 siblings, 5 replies; 17+ messages in thread
From: Anton Protopopov @ 2026-11-25 21:28 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 excludes the functions which use BPF types.
* Patch 2 excludes kfuncs and helpers.
* Patch 3 adds a static list of functions to exclude,
which contains only 3 functions for now.
* Patch 4 excludes the code of kernel/bpf/* and of JITs (x86 and arm).
* Patch 5 adds a corresponding selftest.
In my arm64 vmlinux build this removes 774 tags, 13650 are left.
Precisely,
* Patch 1, BPF types: removes 575 targets
* Patch 2, kfuncs, helpers: removes another 130 targets
* Patch 3, by name: removes another 2 targets
* Patch 4, kernel/bpf, JITs: removes another 67 targets
One implementation note: the llvm-nm was chosen to list names in Patch 4,
because a) it handles any object independently of how the kernel is built
b) BPF scan already requires llvm tools.
[1] https://lore.kernel.org/bpf/DN3P7509U44I.MLLYA1W3M3X9@gmail.com/
Anton Protopopov (5):
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 the code of kernel/bpf and of the JIT
selftests/bpf: Test functions which must have no fmod_ret tag
tools/bpf/resolve_btfids/Makefile | 1 +
tools/bpf/resolve_btfids/fmodret.c | 164 +++++++++++++++++-
tools/bpf/resolve_btfids/llvm-mc.sh | 8 +-
.../bpf/prog_tests/fmodret_untagged.c | 61 +++++++
4 files changed, 231 insertions(+), 3 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/fmodret_untagged.c
--
2.43.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v1 bpf-next 1/5] resolve_btfids: Do not tag functions which work on BPF objects
2026-11-25 21:28 [PATCH v1 bpf-next 0/5] Do not tag selected functions as fmodret targets Anton Protopopov
@ 2026-11-25 21:28 ` Anton Protopopov
2026-11-25 21:25 ` sashiko-bot
2026-11-25 22:14 ` bot+bpf-ci
2026-11-25 21:28 ` [PATCH v1 bpf-next 2/5] resolve_btfids: Do not tag kfuncs and helpers Anton Protopopov
` (3 subsequent siblings)
4 siblings, 2 replies; 17+ messages in thread
From: Anton Protopopov @ 2026-11-25 21:28 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] 17+ messages in thread
* [PATCH v1 bpf-next 2/5] resolve_btfids: Do not tag kfuncs and helpers
2026-11-25 21:28 [PATCH v1 bpf-next 0/5] Do not tag selected functions as fmodret targets Anton Protopopov
2026-11-25 21:28 ` [PATCH v1 bpf-next 1/5] resolve_btfids: Do not tag functions which work on BPF objects Anton Protopopov
@ 2026-11-25 21:28 ` Anton Protopopov
2026-11-25 21:28 ` [PATCH v1 bpf-next 3/5] resolve_btfids: Exclude a set of functions by name Anton Protopopov
` (2 subsequent siblings)
4 siblings, 0 replies; 17+ messages in thread
From: Anton Protopopov @ 2026-11-25 21:28 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_copy_from_user_str() with BPF_F_PAD_ZEROS and
bpf_skb_load_bytes() clear the buffer on an error, and the verifier
takes it as initialized. After a skip the program reads what was on
its 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] 17+ messages in thread
* [PATCH v1 bpf-next 3/5] resolve_btfids: Exclude a set of functions by name
2026-11-25 21:28 [PATCH v1 bpf-next 0/5] Do not tag selected functions as fmodret targets Anton Protopopov
2026-11-25 21:28 ` [PATCH v1 bpf-next 1/5] resolve_btfids: Do not tag functions which work on BPF objects Anton Protopopov
2026-11-25 21:28 ` [PATCH v1 bpf-next 2/5] resolve_btfids: Do not tag kfuncs and helpers Anton Protopopov
@ 2026-11-25 21:28 ` Anton Protopopov
2026-11-25 21:57 ` bot+bpf-ci
` (2 more replies)
2026-11-25 21:28 ` [PATCH v1 bpf-next 4/5] resolve_btfids: Exclude the code of kernel/bpf and of the JIT Anton Protopopov
2026-11-25 21:28 ` [PATCH v1 bpf-next 5/5] selftests/bpf: Test functions which must have no fmod_ret tag Anton Protopopov
4 siblings, 3 replies; 17+ messages in thread
From: Anton Protopopov @ 2026-11-25 21:28 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 writes the code with
aarch64_insn_patch_text_nosync(), which is traceable without KPROBES.
The same holds for it.
bpf_set_dentry_xattr_locked() and bpf_remove_dentry_xattr_locked() are
kfuncs without the "bpf_kfunc" tag: specialize_kfunc() calls them
instead of the kfuncs without _locked. Do not tag these four.
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
tools/bpf/resolve_btfids/fmodret.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/tools/bpf/resolve_btfids/fmodret.c b/tools/bpf/resolve_btfids/fmodret.c
index 7d26a5c9b028..5a392452471e 100644
--- a/tools/bpf/resolve_btfids/fmodret.c
+++ b/tools/bpf/resolve_btfids/fmodret.c
@@ -87,6 +87,22 @@ 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",
+ "aarch64_insn_patch_text_nosync",
+ "bpf_remove_dentry_xattr_locked",
+ "bpf_set_dentry_xattr_locked",
+ };
+ 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 +306,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] 17+ messages in thread
* [PATCH v1 bpf-next 4/5] resolve_btfids: Exclude the code of kernel/bpf and of the JIT
2026-11-25 21:28 [PATCH v1 bpf-next 0/5] Do not tag selected functions as fmodret targets Anton Protopopov
` (2 preceding siblings ...)
2026-11-25 21:28 ` [PATCH v1 bpf-next 3/5] resolve_btfids: Exclude a set of functions by name Anton Protopopov
@ 2026-11-25 21:28 ` Anton Protopopov
2026-11-25 22:15 ` bot+bpf-ci
2026-11-26 0:53 ` Alexei Starovoitov
2026-11-25 21:28 ` [PATCH v1 bpf-next 5/5] selftests/bpf: Test functions which must have no fmod_ret tag Anton Protopopov
4 siblings, 2 replies; 17+ messages in thread
From: Anton Protopopov @ 2026-11-25 21:28 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
Not every function of kernel/bpf and of the JIT has a BPF type in its
prototype, e.g. check_attach_modify_return() of the verifier,
bpf_tramp_ftrace_ops_func() and bpf_arch_text_invalidate(). Read the
symbols of kernel/bpf/built-in.a and arch/<arch>/net/built-in.a with
the llvm-nm of llvm-config, which reads ELF objects and LTO bitcode,
and do not tag these functions.
Weak symbols count too, for the bpf_lsm_* stubs. 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.
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
tools/bpf/resolve_btfids/Makefile | 1 +
tools/bpf/resolve_btfids/fmodret.c | 80 ++++++++++++++++++++++++++++-
tools/bpf/resolve_btfids/llvm-mc.sh | 8 ++-
3 files changed, 86 insertions(+), 3 deletions(-)
diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
index 38b7caa98776..6d2a2b3582cb 100644
--- a/tools/bpf/resolve_btfids/Makefile
+++ b/tools/bpf/resolve_btfids/Makefile
@@ -93,6 +93,7 @@ LLVM_MC_HELP := CONFIG_BPF_FMODRET_SCAN=y needs a C++17 compiler (HOSTCXX=$(HOST
llvm-dev, llvm-devel). See above what is wrong, or switch the option off
or_llvm_mc_help := || { echo '$(LLVM_MC_HELP)' >&2; false; }
HOSTCFLAGS_resolve_btfids += -DHAVE_LLVM_MC
+HOSTCFLAGS_resolve_btfids += -DLLVM_NM='"$(shell $(LLVM_MC_SH) nm)"'
CXX := $(HOSTCXX)
CXXFLAGS := $(filter-out -Werror,$(HOSTCFLAGS_resolve_btfids)) -O2 \
$(or $(shell $(LLVM_MC_SH) cxxflags),$(error $(LLVM_MC_HELP)))
diff --git a/tools/bpf/resolve_btfids/fmodret.c b/tools/bpf/resolve_btfids/fmodret.c
index 5a392452471e..384efb5307ab 100644
--- a/tools/bpf/resolve_btfids/fmodret.c
+++ b/tools/bpf/resolve_btfids/fmodret.c
@@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <bpf/btf.h>
@@ -103,6 +104,71 @@ static bool excluded_by_name(const char *name)
return false;
}
+#ifndef LLVM_NM
+#define LLVM_NM "llvm-nm"
+#endif
+
+/* The code of BPF itself, in the build directory of vmlinux */
+static const char * const bpf_archives[] = {
+ "kernel/bpf/built-in.a",
+ "arch/x86/net/built-in.a",
+ "arch/arm64/net/built-in.a",
+};
+
+static int cmp_name(const void *a, const void *b)
+{
+ return strcmp(*(char * const *)a, *(char * const *)b);
+}
+
+/* Read the symbols of bpf_archives[] into NAMES, sorted */
+static int read_bpf_code(char ***names, size_t *nr)
+{
+ char cmd[sizeof(LLVM_NM) + 256] = LLVM_NM " --defined-only -j", *line = NULL;
+ size_t i, size = 0;
+ int err = 0;
+ FILE *f;
+
+ if (access(bpf_archives[0], F_OK)) {
+ fprintf(stderr, "FAILED: --fmodret_scan: no %s\n", bpf_archives[0]);
+ return -ENOENT;
+ }
+ for (i = 0; i < sizeof(bpf_archives) / sizeof(bpf_archives[0]); i++)
+ if (!access(bpf_archives[i], F_OK))
+ strcat(strcat(cmd, " "), bpf_archives[i]);
+ f = popen(cmd, "r");
+ if (!f)
+ return -errno;
+ while (getline(&line, &size, f) > 0) {
+ char **p = *nr % 4096 ? *names : realloc(*names, (*nr + 4096) * sizeof(*p));
+
+ if (!p) {
+ err = -ENOMEM;
+ break;
+ }
+ *names = p;
+ line[strcspn(line, "\n")] = 0;
+ p[(*nr)++] = line;
+ line = NULL;
+ size = 0;
+ }
+ free(line);
+ if (!feof(f) && !err)
+ err = -EIO;
+ if (pclose(f) && !err)
+ err = -EINVAL;
+ if (err) {
+ fprintf(stderr, "FAILED: --fmodret_scan: %s\n", cmd);
+ return err;
+ }
+ qsort(*names, *nr, sizeof(**names), cmp_name);
+ return 0;
+}
+
+static bool is_bpf_code(char **names, size_t nr, const char *name)
+{
+ return bsearch(&name, names, nr, sizeof(*names), cmp_name);
+}
+
/* Find kfuncs and helpers */
static bool *find_bpf_funcs(const struct btf *btf)
{
@@ -260,11 +326,12 @@ static void set_protos(struct scan *scan, const struct image *img, const struct
int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
{
- size_t nr_funcs = 0, nr_scanned = 0, nr_undecodable = 0, nr_tags = 0;
+ size_t nr_funcs = 0, nr_scanned = 0, nr_undecodable = 0, nr_tags = 0, nr_bpf_code = 0, i;
const struct btf *base = btf__base_btf(btf);
__u32 id, nr_types = btf__type_cnt(btf);
struct scan *scan = NULL;
bool *bpf_funcs = NULL;
+ char **bpf_code = NULL;
struct image img;
char counts[200];
int err;
@@ -281,6 +348,11 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
bpf_funcs = find_bpf_funcs(btf);
if (!bpf_funcs)
goto out;
+ if (!base) {
+ err = read_bpf_code(&bpf_code, &nr_bpf_code);
+ if (err)
+ 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);
@@ -308,6 +380,9 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
continue;
if (excluded_by_name(name))
continue;
+ /* Skip the code of kernel/bpf and of the JIT */
+ if (is_bpf_code(bpf_code, nr_bpf_code, name))
+ continue;
nr_scanned++;
err = scan_func(scan, func, &values);
if (err == -EINVAL) {
@@ -340,6 +415,9 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
printf(" FMODRET %s\n", counts);
}
out:
+ for (i = 0; i < nr_bpf_code; i++)
+ free(bpf_code[i]);
+ free(bpf_code);
free(bpf_funcs);
scan_close(scan);
image_close(&img);
diff --git a/tools/bpf/resolve_btfids/llvm-mc.sh b/tools/bpf/resolve_btfids/llvm-mc.sh
index bc62c4e43406..919cf9480250 100755
--- a/tools/bpf/resolve_btfids/llvm-mc.sh
+++ b/tools/bpf/resolve_btfids/llvm-mc.sh
@@ -1,7 +1,7 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only
#
-# usage: llvm-mc.sh SRCARCH [cxxflags | libs]
+# usage: llvm-mc.sh SRCARCH [cxxflags | libs | nm]
#
# text_mc.cpp reads the machine code of the kernel arch SRCARCH with LLVM's MC
# layer. Fail, and say why, if this host lacks what it takes to build it.
@@ -9,7 +9,8 @@
# one run of llvm-config. Whether text_mc.cpp works with this LLVM shows when the
# tool is built, and in text_arch_init() when it starts.
#
-# For the Makefile print the flags to compile text_mc.cpp, or the libraries.
+# For the Makefile print the flags to compile text_mc.cpp, the libraries, or
+# llvm-nm, which reads kbuild's objects for fmodret.c.
#
# The host's LLVM need not be the one which compiles the kernel, if any does.
@@ -56,4 +57,7 @@ libs)
libs=$($LLVM_CONFIG --link-shared "$@") || die "no libraries of LLVM"
echo $libs -lstdc++ -lm
;;
+nm)
+ echo "$($LLVM_CONFIG --bindir)/llvm-nm"
+ ;;
esac
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v1 bpf-next 5/5] selftests/bpf: Test functions which must have no fmod_ret tag
2026-11-25 21:28 [PATCH v1 bpf-next 0/5] Do not tag selected functions as fmodret targets Anton Protopopov
` (3 preceding siblings ...)
2026-11-25 21:28 ` [PATCH v1 bpf-next 4/5] resolve_btfids: Exclude the code of kernel/bpf and of the JIT Anton Protopopov
@ 2026-11-25 21:28 ` Anton Protopopov
4 siblings, 0 replies; 17+ messages in thread
From: Anton Protopopov @ 2026-11-25 21:28 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: ones which work on BPF objects, a
kfunc, a helper, one of kernel/bpf, and those which are excluded by
name.
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
.../bpf/prog_tests/fmodret_untagged.c | 60 +++++++++++++++++++
1 file changed, 60 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..59347f9b4e78
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/fmodret_untagged.c
@@ -0,0 +1,60 @@
+// 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",
+ "btf_kfunc_check_flag",
+ "bpf_mprog_detach",
+ /* A kfunc and a helper */
+ "bpf_sock_destroy",
+ "bpf_skb_load_bytes",
+ /* Of kernel/bpf */
+ "bpf_tramp_ftrace_ops_func",
+ /* By name */
+ "copy_from_kernel_nofault",
+ "bpf_set_dentry_xattr_locked",
+ "bpf_remove_dentry_xattr_locked",
+};
+
+/* 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] 17+ messages in thread
* Re: [PATCH v1 bpf-next 3/5] resolve_btfids: Exclude a set of functions by name
2026-11-25 21:28 ` [PATCH v1 bpf-next 3/5] resolve_btfids: Exclude a set of functions by name Anton Protopopov
@ 2026-11-25 21:57 ` bot+bpf-ci
2026-11-26 0:55 ` Alexei Starovoitov
2026-11-26 0:56 ` Alexei Starovoitov
2 siblings, 0 replies; 17+ messages in thread
From: bot+bpf-ci @ 2026-11-25 21:57 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: 2669 bytes --]
> resolve_btfids: Exclude a set of functions by name
TL;DR:
- Exclusion list may be incomplete: fmod_ret on copy_to_kernel_nofault()
returning -EFAULT could still break arm64 ftrace patching
- Driver xdp metadata kfunc implementations may need excluding too
> 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
[ ... ]
> +static bool excluded_by_name(const char *name)
> +{
> + static const char *const names[] = {
> + "copy_from_kernel_nofault",
> + "aarch64_insn_patch_text_nosync",
The commit message excludes aarch64_insn_patch_text_nosync() so that a
program cannot make ftrace patching fail. Is the list complete for that
purpose?
aarch64_insn_patch_text_nosync() fails only through:
aarch64_insn_write()
__aarch64_insn_write()
copy_to_kernel_nofault()
copy_to_kernel_nofault() ends in "return -EFAULT", has the same shape as
the excluded copy_from_kernel_nofault(), and is not in the list.
If an fmod_ret program on it returns -EFAULT, ftrace_modify_code() on arm64
returns -EPERM without writing text, which looks like the same
ftrace_bug() and stale trampoline failure described for x86.
The read side looks similar: aarch64_insn_read(), used by the arm64 ftrace
code, returns the -EFAULT from copy_from_kernel_nofault(). Should
copy_to_kernel_nofault(), and aarch64_insn_read()/aarch64_insn_write() if
the scanner tags them, be added here?
> + "bpf_remove_dentry_xattr_locked",
> + "bpf_set_dentry_xattr_locked",
The commit message gives specialize_kfunc() calling these two in place of
the tagged kfuncs as the reason for excluding them. The same substitution
applies to driver xdp metadata implementations returned by
bpf_dev_bound_resolve_kfunc() and called from specialize_kfunc().
For example veth_xdp_rx_hash() returns -ENODATA, takes only xdp_md, u32 *
and enum pointers (none named bpf_* or btf_*), and has no bpf_kfunc tag, so
has_bpf_types(), bpf_funcs[] and excluded_by_name() all let it through.
If a program skips it, *hash and *rss_type stay unwritten while the
verifier treats the kfunc outputs as written. Does the by-name list need
to cover these driver implementations too?
> + };
> + unsigned int i;
> +
> + for (i = 0; i < sizeof(names) / sizeof(names[0]); i++)
> + if (!strcmp(name, names[i]))
> + return true;
> + return false;
> +}
[ ... ]
---
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/45706808075
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v1 bpf-next 1/5] resolve_btfids: Do not tag functions which work on BPF objects
2026-11-25 21:28 ` [PATCH v1 bpf-next 1/5] resolve_btfids: Do not tag functions which work on BPF objects Anton Protopopov
2026-11-25 21:25 ` sashiko-bot
@ 2026-11-25 22:14 ` bot+bpf-ci
2026-11-26 10:49 ` Anton Protopopov
1 sibling, 1 reply; 17+ messages in thread
From: bot+bpf-ci @ 2026-11-25 22:14 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: 2792 bytes --]
> resolve_btfids: Do not tag functions which work on BPF objects
TL;DR: Test issue: skipping bpf_* parameter types likely leaves vmlinux
bpf_dummy_reg() untagged, so the tag_of_vmlinux selftest may no longer test
anything and its comment is stale.
> 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
[ ... ]
> @@ -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);
This isn't a bug, but does this change leave the tag_of_vmlinux subtest
without anything to test?
In tools/testing/selftests/bpf/progs/fmodret_retval.c:
/*
* 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.
*/
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)
The vmlinux function is:
static int bpf_dummy_reg(void *kdata, struct bpf_link *link)
{
return -EOPNOTSUPP;
}
Its second parameter is a pointer to struct bpf_link, so is_bpf_type()
follows the pointer, matches the "bpf_" prefix, and has_bpf_types() returns
true. fmodret_tag() then no longer emits "bpf_fmodret_retval:-95" for the
vmlinux bpf_dummy_reg().
The subtest exists to show that the verifier does not use the vmlinux tag
for the module function. With no vmlinux tag left, the program is rejected
with "bpf_dummy_reg() is not modifiable" regardless of which BTF the lookup
searches, so a later change that made btf_find_func_tag_value() also search
base BTF would leave this test passing. The comment "That one returns an
error and has a tag" is also no longer true.
None of the later patches in the series touch progs/fmodret_retval.c, and
prog_tests/fmodret_untagged.c does not cover this case.
Would a pair of same-named vmlinux and module functions with the same
prototype, where the vmlinux one is still tagged, restore the coverage?
Otherwise should the subtest and its comment be updated or removed?
---
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/45706808075
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v1 bpf-next 4/5] resolve_btfids: Exclude the code of kernel/bpf and of the JIT
2026-11-25 21:28 ` [PATCH v1 bpf-next 4/5] resolve_btfids: Exclude the code of kernel/bpf and of the JIT Anton Protopopov
@ 2026-11-25 22:15 ` bot+bpf-ci
2026-11-26 0:53 ` Alexei Starovoitov
1 sibling, 0 replies; 17+ messages in thread
From: bot+bpf-ci @ 2026-11-25 22:15 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: 2490 bytes --]
> resolve_btfids: Exclude the code of kernel/bpf and of the JIT
TL;DR: With CONFIG_LTO_CLANG, a host llvm-nm older than the kernel's clang may
fail to parse kernel/bpf bitcode, possibly breaking vmlinux BTF generation in
a config that built before. Using the kernel's $(NM) is suggested.
> 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
[ ... ]
> +/* Read the symbols of bpf_archives[] into NAMES, sorted */
> +static int read_bpf_code(char ***names, size_t *nr)
> +{
> + char cmd[sizeof(LLVM_NM) + 256] = LLVM_NM " --defined-only -j", *line = NULL;
[ ... ]
> + if (pclose(f) && !err)
> + err = -EINVAL;
> + if (err) {
> + fprintf(stderr, "FAILED: --fmodret_scan: %s\n", cmd);
> + return err;
> + }
With CONFIG_LTO_CLANG, every member of kernel/bpf/built-in.a is LLVM
bitcode. Bitcode is only backward compatible, so an llvm-nm older than the
clang that built the kernel can fail to parse it and exit non-zero.
The build allows llvm-config to come from a different LLVM than the kernel
compiler (llvm-mc.sh says "The host's LLVM need not be the one which
compiles the kernel"), and LLVM_CONFIG defaults to plain llvm-config
when only LLVM=1 or CC=clang-N is used.
If that happens, the failure propagates like this:
link-vmlinux.sh -> gen-btf.sh .tmp_vmlinux1
-> resolve_btfids --fmodret_scan
-> fmodret_tag(): base == NULL -> read_bpf_code()
-> pclose(f) != 0 -> err = -EINVAL
-> fmodret_tag() goto out -> "Failed to generate BTF for vmlinux"
Before this patch the same configuration (LTO_CLANG=y, DEBUG_INFO_BTF=y,
BPF_FMODRET_SCAN=y, host llvm-config at least 17 but older than the kernel's
clang) built, since only the linked machine code of .tmp_vmlinux1 was read.
No Kconfig dependency excludes LTO_CLANG from BPF_FMODRET_SCAN, and the
BPF_FMODRET_SCAN help was not updated for the new llvm-nm dependency.
Can the host llvm-nm read kernel/bpf/built-in.a in that setup? Would the
kernel's own $(NM), which kbuild requires to be llvm-nm under LTO_CLANG and
exports to gen-btf.sh, be a safer reader here? If GNU nm were used, an
output format it supports (e.g. -P) would be needed in place of -j.
---
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/45706808075
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v1 bpf-next 4/5] resolve_btfids: Exclude the code of kernel/bpf and of the JIT
2026-11-25 21:28 ` [PATCH v1 bpf-next 4/5] resolve_btfids: Exclude the code of kernel/bpf and of the JIT Anton Protopopov
2026-11-25 22:15 ` bot+bpf-ci
@ 2026-11-26 0:53 ` Alexei Starovoitov
2026-11-26 13:18 ` Anton Protopopov
1 sibling, 1 reply; 17+ messages in thread
From: Alexei Starovoitov @ 2026-11-26 0:53 UTC (permalink / raw)
To: Anton Protopopov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Jiri Olsa,
Alan Maguire, John Fastabend, bpf
On Wed, Nov 25, 2026 at 01:28 PM Anton Protopopov <a.s.protopopov@gmail.com> wrote:
> bpf_tramp_ftrace_ops_func() and bpf_arch_text_invalidate(). Read the
> symbols of kernel/bpf/built-in.a and arch/<arch>/net/built-in.a with
> the llvm-nm of llvm-config, which reads ELF objects and LTO bitcode,
> and do not tag these functions.
bot is correct.
Let's run ${NM} in gen-btf.sh and give its output to resolve_btfids ?
kbuild knows the paths and the arch. The tool doesn't have to.
${NM} reads what ${CC} writes. HAS_LTO_CLANG requires it to be llvm-nm.
link-vmlinux.sh runs it for kallsyms already.
llvm-config can be of another LLVM than the compiler. llvm-mc.sh says so.
image_func() finds a function by name. No need to copy and sort the names.
Then LLVM_NM, the nm mode of llvm-mc.sh, bpf_archives[], popen(), qsort()
and bsearch() go away.
It replaces patch 4.
diff --git a/scripts/gen-btf.sh b/scripts/gen-btf.sh
index b17f118..341885b 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 kernel/bpf/built-in.a \
+ 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 e1afdb6..d2fa9b7 100644
--- a/tools/bpf/resolve_btfids/fmodret.c
+++ b/tools/bpf/resolve_btfids/fmodret.c
@@ -188,12 +188,41 @@ 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 (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 *denied = NULL;
struct image img;
char counts[200];
int err;
@@ -206,6 +235,11 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
if (!scan)
goto out;
set_protos(scan, &img, btf);
+ 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);
@@ -225,6 +259,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 (denied && denied[func - img.funcs])
+ continue;
nr_scanned++;
err = scan_func(scan, func, &values);
if (err == -EINVAL) {
@@ -257,6 +293,7 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
printf(" FMODRET %s\n", counts);
}
out:
+ free(denied);
scan_close(scan);
image_close(&img);
return err < 0 ? err : 0;
diff --git a/tools/bpf/resolve_btfids/fmodret.h b/tools/bpf/resolve_btfids/fmodret.h
index d61a9de..177b116 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 0ac8952..b277a65 100644
--- a/tools/bpf/resolve_btfids/main.c
+++ b/tools/bpf/resolve_btfids/main.c
@@ -2100,6 +2100,7 @@ int main(int argc, const char **argv)
.sets = RB_ROOT,
};
const char *btfids_path = NULL;
+ const char *fmodret_deny = NULL;
struct btf_links btf_links = {};
bool fatal_warnings = false;
bool resolve_btfids = true;
@@ -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))
pw-bot: cr
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v1 bpf-next 3/5] resolve_btfids: Exclude a set of functions by name
2026-11-25 21:28 ` [PATCH v1 bpf-next 3/5] resolve_btfids: Exclude a set of functions by name Anton Protopopov
2026-11-25 21:57 ` bot+bpf-ci
@ 2026-11-26 0:55 ` Alexei Starovoitov
2026-11-26 0:56 ` Alexei Starovoitov
2 siblings, 0 replies; 17+ messages in thread
From: Alexei Starovoitov @ 2026-11-26 0:55 UTC (permalink / raw)
To: Anton Protopopov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Jiri Olsa,
Alan Maguire, John Fastabend, bpf
On Wed, Nov 25, 2026 at 01:28 PM Anton Protopopov <a.s.protopopov@gmail.com> wrote:
> On arm64 ftrace writes the code with
> aarch64_insn_patch_text_nosync(), which is traceable without KPROBES.
> The same holds for it.
Pls add these two as well:
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v1 bpf-next 3/5] resolve_btfids: Exclude a set of functions by name
2026-11-25 21:28 ` [PATCH v1 bpf-next 3/5] resolve_btfids: Exclude a set of functions by name Anton Protopopov
2026-11-25 21:57 ` bot+bpf-ci
2026-11-26 0:55 ` Alexei Starovoitov
@ 2026-11-26 0:56 ` Alexei Starovoitov
2026-11-26 11:29 ` Anton Protopopov
2 siblings, 1 reply; 17+ messages in thread
From: Alexei Starovoitov @ 2026-11-26 0:56 UTC (permalink / raw)
To: Anton Protopopov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Jiri Olsa,
Alan Maguire, John Fastabend, bpf
On Wed, Nov 25, 2026 at 01:28 PM Anton Protopopov <a.s.protopopov@gmail.com> wrote:
> + "bpf_remove_dentry_xattr_locked",
> + "bpf_set_dentry_xattr_locked",
The bug from the log of patch 2 stays one call below the helper.
bpf_unlocked_sk_getsockopt() has no tag now.
It passes optval, ARG_PTR_TO_UNINIT_MEM, to __bpf_getsockopt():
if (err)
optlen = 0;
if (optlen < saved_optlen)
memset(optval + optlen, 0, saved_optlen - optlen);
return err;
__bpf_getsockopt() is in net/core/filter.c and takes no bpf type.
By the rules in fmodret.c it keeps the tag with -EINVAL.
After a skip the memset() doesn't run and the prog reads its stack.
__bpf_skb_load_bytes() has the same memset() in front of -EFAULT.
can we skip bpf_*() and __bpf_*() of vmlinux by prefix ?
Both *_locked names go away.
Modules stay as they are, bpf_testmod_retval_*() need their tags.
A few lines in fmodret.c on top of patch 5
diff --git a/tools/bpf/resolve_btfids/fmodret.c b/tools/bpf/resolve_btfids/fmodret.c
index 384efb5..18b3fbc 100644
--- a/tools/bpf/resolve_btfids/fmodret.c
+++ b/tools/bpf/resolve_btfids/fmodret.c
@@ -93,8 +93,6 @@ static bool excluded_by_name(const char *name)
static const char *const names[] = {
"copy_from_kernel_nofault",
"aarch64_insn_patch_text_nosync",
- "bpf_remove_dentry_xattr_locked",
- "bpf_set_dentry_xattr_locked",
};
unsigned int i;
@@ -166,7 +164,8 @@ static int read_bpf_code(char ***names, size_t *nr)
static bool is_bpf_code(char **names, size_t nr, const char *name)
{
- return bsearch(&name, names, nr, sizeof(*names), cmp_name);
+ return !strncmp(name + strspn(name, "_"), "bpf_", 4) ||
+ bsearch(&name, names, nr, sizeof(*names), cmp_name);
}
/* Find kfuncs and helpers */
@@ -380,8 +379,8 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
continue;
if (excluded_by_name(name))
continue;
- /* Skip the code of kernel/bpf and of the JIT */
- if (is_bpf_code(bpf_code, nr_bpf_code, name))
+ /* Skip bpf_*(), __bpf_*() and the code of kernel/bpf and of the JIT */
+ if (!base && is_bpf_code(bpf_code, nr_bpf_code, name))
continue;
nr_scanned++;
err = scan_func(scan, func, &values);
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v1 bpf-next 1/5] resolve_btfids: Do not tag functions which work on BPF objects
2026-11-25 22:14 ` bot+bpf-ci
@ 2026-11-26 10:49 ` Anton Protopopov
0 siblings, 0 replies; 17+ messages in thread
From: Anton Protopopov @ 2026-11-26 10:49 UTC (permalink / raw)
To: bot+bpf-ci
Cc: ast, daniel, andrii, eddyz87, memxor, jolsa, almagui,
john.fastabend, bpf, martin.lau, yonghong.song, mason,
ihor.solodrai
On 26/11/25 10:14PM, bot+bpf-ci@kernel.org wrote:
> > resolve_btfids: Do not tag functions which work on BPF objects
>
> TL;DR: Test issue: skipping bpf_* parameter types likely leaves vmlinux
> bpf_dummy_reg() untagged, so the tag_of_vmlinux selftest may no longer test
> anything and its comment is stale.
>
> > 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
>
> [ ... ]
>
> > @@ -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);
>
> This isn't a bug, but does this change leave the tag_of_vmlinux subtest
> without anything to test?
>
> In tools/testing/selftests/bpf/progs/fmodret_retval.c:
>
> /*
> * 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.
> */
> 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)
>
> The vmlinux function is:
>
> static int bpf_dummy_reg(void *kdata, struct bpf_link *link)
> {
> return -EOPNOTSUPP;
> }
>
> Its second parameter is a pointer to struct bpf_link, so is_bpf_type()
> follows the pointer, matches the "bpf_" prefix, and has_bpf_types() returns
> true. fmodret_tag() then no longer emits "bpf_fmodret_retval:-95" for the
> vmlinux bpf_dummy_reg().
>
> The subtest exists to show that the verifier does not use the vmlinux tag
> for the module function. With no vmlinux tag left, the program is rejected
> with "bpf_dummy_reg() is not modifiable" regardless of which BTF the lookup
> searches, so a later change that made btf_find_func_tag_value() also search
> base BTF would leave this test passing. The comment "That one returns an
> error and has a tag" is also no longer true.
>
> None of the later patches in the series touch progs/fmodret_retval.c, and
> prog_tests/fmodret_untagged.c does not cover this case.
>
> Would a pair of same-named vmlinux and module functions with the same
> prototype, where the vmlinux one is still tagged, restore the coverage?
> Otherwise should the subtest and its comment be updated or removed?
Thanks robot. I will change the selftest to use another function.
>
> ---
> 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/45706808075
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v1 bpf-next 1/5] resolve_btfids: Do not tag functions which work on BPF objects
2026-11-25 21:25 ` sashiko-bot
@ 2026-11-26 10:50 ` Anton Protopopov
0 siblings, 0 replies; 17+ messages in thread
From: Anton Protopopov @ 2026-11-26 10:50 UTC (permalink / raw)
To: sashiko-reviews; +Cc: bpf
On 26/11/25 09:25PM, 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 36940d1b337a769c63009cfc2b22cfd69fcc61f9
> 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 a bug in the automatic fmod_ret tagging where internal BPF
> functions were left modifiable. Should this include:
>
> Fixes: 4dd950adacad ("resolve_btfids: Tag the functions that return errors")
I didn't add any tags because I consider this as a follow up.
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261125212849.868523-1-a.s.protopopov@gmail.com?part=1
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v1 bpf-next 3/5] resolve_btfids: Exclude a set of functions by name
2026-11-26 0:56 ` Alexei Starovoitov
@ 2026-11-26 11:29 ` Anton Protopopov
0 siblings, 0 replies; 17+ messages in thread
From: Anton Protopopov @ 2026-11-26 11:29 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman,
Kumar Kartikeya Dwivedi, Jiri Olsa, Alan Maguire, John Fastabend,
bpf
On 26/11/26 12:56AM, Alexei Starovoitov wrote:
> On Wed, Nov 25, 2026 at 01:28 PM Anton Protopopov <a.s.protopopov@gmail.com> wrote:
> > + "bpf_remove_dentry_xattr_locked",
> > + "bpf_set_dentry_xattr_locked",
>
> The bug from the log of patch 2 stays one call below the helper.
> bpf_unlocked_sk_getsockopt() has no tag now.
> It passes optval, ARG_PTR_TO_UNINIT_MEM, to __bpf_getsockopt():
>
> if (err)
> optlen = 0;
> if (optlen < saved_optlen)
> memset(optval + optlen, 0, saved_optlen - optlen);
> return err;
>
> __bpf_getsockopt() is in net/core/filter.c and takes no bpf type.
> By the rules in fmodret.c it keeps the tag with -EINVAL.
> After a skip the memset() doesn't run and the prog reads its stack.
> __bpf_skb_load_bytes() has the same memset() in front of -EFAULT.
>
> can we skip bpf_*() and __bpf_*() of vmlinux by prefix ?
> Both *_locked names go away.
> Modules stay as they are, bpf_testmod_retval_*() need their tags.
> A few lines in fmodret.c on top of patch 5
>
> diff --git a/tools/bpf/resolve_btfids/fmodret.c b/tools/bpf/resolve_btfids/fmodret.c
> index 384efb5..18b3fbc 100644
> --- a/tools/bpf/resolve_btfids/fmodret.c
> +++ b/tools/bpf/resolve_btfids/fmodret.c
> @@ -93,8 +93,6 @@ static bool excluded_by_name(const char *name)
> static const char *const names[] = {
> "copy_from_kernel_nofault",
> "aarch64_insn_patch_text_nosync",
> - "bpf_remove_dentry_xattr_locked",
> - "bpf_set_dentry_xattr_locked",
> };
> unsigned int i;
>
> @@ -166,7 +164,8 @@ static int read_bpf_code(char ***names, size_t *nr)
>
> static bool is_bpf_code(char **names, size_t nr, const char *name)
> {
> - return bsearch(&name, names, nr, sizeof(*names), cmp_name);
> + return !strncmp(name + strspn(name, "_"), "bpf_", 4) ||
> + bsearch(&name, names, nr, sizeof(*names), cmp_name);
> }
>
> /* Find kfuncs and helpers */
> @@ -380,8 +379,8 @@ int fmodret_tag(Elf *elf, struct btf *btf, int verbose)
> continue;
> if (excluded_by_name(name))
> continue;
> - /* Skip the code of kernel/bpf and of the JIT */
> - if (is_bpf_code(bpf_code, nr_bpf_code, name))
> + /* Skip bpf_*(), __bpf_*() and the code of kernel/bpf and of the JIT */
> + if (!base && is_bpf_code(bpf_code, nr_bpf_code, name))
> continue;
> nr_scanned++;
> err = scan_func(scan, func, &values);
>
Thanks, will address al of these (and add names from the other message) in v2.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v1 bpf-next 4/5] resolve_btfids: Exclude the code of kernel/bpf and of the JIT
2026-11-26 0:53 ` Alexei Starovoitov
@ 2026-11-26 13:18 ` Anton Protopopov
0 siblings, 0 replies; 17+ messages in thread
From: Anton Protopopov @ 2026-11-26 13:18 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman,
Kumar Kartikeya Dwivedi, Jiri Olsa, Alan Maguire, John Fastabend,
bpf
On 26/11/26 12:53AM, Alexei Starovoitov wrote:
> On Wed, Nov 25, 2026 at 01:28 PM Anton Protopopov <a.s.protopopov@gmail.com> wrote:
> > bpf_tramp_ftrace_ops_func() and bpf_arch_text_invalidate(). Read the
> > symbols of kernel/bpf/built-in.a and arch/<arch>/net/built-in.a with
> > the llvm-nm of llvm-config, which reads ELF objects and LTO bitcode,
> > and do not tag these functions.
>
> bot is correct.
> Let's run ${NM} in gen-btf.sh and give its output to resolve_btfids ?
> kbuild knows the paths and the arch. The tool doesn't have to.
> ${NM} reads what ${CC} writes. HAS_LTO_CLANG requires it to be llvm-nm.
> link-vmlinux.sh runs it for kallsyms already.
> llvm-config can be of another LLVM than the compiler. llvm-mc.sh says so.
> image_func() finds a function by name. No need to copy and sort the names.
> Then LLVM_NM, the nm mode of llvm-mc.sh, bpf_archives[], popen(), qsort()
> and bsearch() go away.
>
> It replaces patch 4.
Thanks, I will adopt your variant (and add your "Co-developed-by"
and "Signed-off-by").
> [...]
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2026-11-26 13:07 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 21:28 [PATCH v1 bpf-next 0/5] Do not tag selected functions as fmodret targets Anton Protopopov
2026-11-25 21:28 ` [PATCH v1 bpf-next 1/5] resolve_btfids: Do not tag functions which work on BPF objects Anton Protopopov
2026-11-25 21:25 ` sashiko-bot
2026-11-26 10:50 ` Anton Protopopov
2026-11-25 22:14 ` bot+bpf-ci
2026-11-26 10:49 ` Anton Protopopov
2026-11-25 21:28 ` [PATCH v1 bpf-next 2/5] resolve_btfids: Do not tag kfuncs and helpers Anton Protopopov
2026-11-25 21:28 ` [PATCH v1 bpf-next 3/5] resolve_btfids: Exclude a set of functions by name Anton Protopopov
2026-11-25 21:57 ` bot+bpf-ci
2026-11-26 0:55 ` Alexei Starovoitov
2026-11-26 0:56 ` Alexei Starovoitov
2026-11-26 11:29 ` Anton Protopopov
2026-11-25 21:28 ` [PATCH v1 bpf-next 4/5] resolve_btfids: Exclude the code of kernel/bpf and of the JIT Anton Protopopov
2026-11-25 22:15 ` bot+bpf-ci
2026-11-26 0:53 ` Alexei Starovoitov
2026-11-26 13:18 ` Anton Protopopov
2026-11-25 21:28 ` [PATCH v1 bpf-next 5/5] selftests/bpf: Test functions which must have no fmod_ret tag Anton Protopopov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox