BPF List
 help / color / mirror / Atom feed
* [PATCH v1 bpf-next 0/7] Tag fmod_ret functions that return ERR_PTR()
@ 2026-11-25 10:27 Anton Protopopov
  2026-11-25 10:27 ` [PATCH v1 bpf-next 1/7] bpf: Require the JIT for fmod_ret programs on 64-bit functions Anton Protopopov
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: Anton Protopopov @ 2026-11-25 10:27 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, 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.
But it looks only at the functions that return an integer.
This set tags the functions that return ERR_PTR() too.

One note is that it turned out that verifier already allowed
to attach fmod_ret programs to functions returning pointers
(see patch 2). Besides cleanups, the two main changes are:

  * From now on we disallow fmod_ret programs attaching to targets
    returning pointers to return anything but -errno or 0 (meaning,
    as in the integer case, "exec the original function").

  * We tag new targets in resolve_btfids

Patches 1-3 are fixes for the declared targets. Patch 1 requires the
JIT for every fmod_ret program on a function which returns 64 bits,
because the interpreter returns only 32 of them. Patch 2 removes a
wrong comment in btf_ctx_access(): fmod_ret programs can already
attach to functions which return pointers, they just can't read
ret. Some functions on the error injection list return a pointer,
like xe_device_create(). An fmod_ret program on such a function may
return any value and the caller dereferences it. Patch 3 allows only
NULL or an error pointer. Patch 4 tests it, together with an
extension of a global function called from such a program.
Patches 5-7 enable tagging for new functions and test them.

In an arm64 vmlinux built with clang this series tags 1380 more
functions: 15804 instead of 14424.

As for the integer functions, among the callers of the new targets
there are ones which do not check the error, and a few functions get
a tag though they never return an error pointer: they turn one into
NULL, as inet_frag_find() does with "IS_ERR_OR_NULL(prev) ? fq :
prev". I do not fix this here, as this is a shared broblem with
integer functions, a follow-up will be send later.

Anton Protopopov (7):
  bpf: Require the JIT for fmod_ret programs on 64-bit functions
  bpf: Remove a wrong comment about fmod_ret targets
  bpf: Allow only NULL or ERR_PTR() from fmod_ret on pointer functions
  selftests/bpf: Test fmod_ret on a declared function that returns a
    pointer
  bpf: Check fmod_ret return values of tagged pointer targets in 64 bits
  resolve_btfids: Tag the functions that return ERR_PTR()
  selftests/bpf: Test fmod_ret on functions that return a pointer

 kernel/bpf/btf.c                              |  3 --
 kernel/bpf/verifier.c                         | 22 ++++++++--
 tools/bpf/resolve_btfids/fmodret.c            | 11 +++--
 .../selftests/bpf/prog_tests/fmodret_retval.c |  2 +-
 .../selftests/bpf/prog_tests/modify_return.c  | 44 +++++++++++++++++++
 tools/testing/selftests/bpf/progs/err.h       |  5 +++
 .../selftests/bpf/progs/fmodret_retval.c      | 10 +++++
 .../selftests/bpf/progs/modify_return_ext.c   | 12 +++++
 .../selftests/bpf/progs/modify_return_ptr.c   | 43 ++++++++++++++++++
 .../selftests/bpf/test_kmods/bpf_testmod.c    |  7 +++
 .../bpf/test_kmods/bpf_testmod_retval.c       |  2 +-
 11 files changed, 149 insertions(+), 12 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/modify_return_ext.c
 create mode 100644 tools/testing/selftests/bpf/progs/modify_return_ptr.c

-- 
2.43.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-11-25 13:26 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 10:27 [PATCH v1 bpf-next 0/7] Tag fmod_ret functions that return ERR_PTR() Anton Protopopov
2026-11-25 10:27 ` [PATCH v1 bpf-next 1/7] bpf: Require the JIT for fmod_ret programs on 64-bit functions Anton Protopopov
2026-11-25 10:27 ` [PATCH v1 bpf-next 2/7] bpf: Remove a wrong comment about fmod_ret targets Anton Protopopov
2026-11-25 10:28 ` [PATCH v1 bpf-next 3/7] bpf: Allow only NULL or ERR_PTR() from fmod_ret on pointer functions Anton Protopopov
2026-11-25 10:47   ` bot+bpf-ci
2026-11-25 13:14     ` Anton Protopopov
2026-11-25 13:38   ` Anton Protopopov
2026-11-25 10:28 ` [PATCH v1 bpf-next 4/7] selftests/bpf: Test fmod_ret on a declared function that returns a pointer Anton Protopopov
2026-11-25 13:34   ` Anton Protopopov
2026-11-25 10:28 ` [PATCH v1 bpf-next 5/7] bpf: Check fmod_ret return values of tagged pointer targets in 64 bits Anton Protopopov
2026-11-25 10:28 ` [PATCH v1 bpf-next 6/7] resolve_btfids: Tag the functions that return ERR_PTR() Anton Protopopov
2026-11-25 10:28 ` [PATCH v1 bpf-next 7/7] selftests/bpf: Test fmod_ret on functions that return a pointer Anton Protopopov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox