Tag fmod_ret functions that return ERR_PTR()
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest7 patches 3 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/7 | bpf: Require the JIT for fmod_ret programs on 64-bit functionskernel/ | +2 | 0 replies | |
| 2/7 | bpf: Remove a wrong comment about fmod_ret targetskernel/ | +0 | 0 replies | |
| 3/7 | bpf: Allow only NULL or ERR_PTR() from fmod_ret on pointer functionskernel/ | +14 | 2 replies | |
| 4/7 | selftests/bpf: Test fmod_ret on a declared function that returns a pointertools/ tools/ tools/ +2 more | +111 | 1 reply | |
| 5/7 | bpf: Check fmod_ret return values of tagged pointer targets in 64 bitskernel/ | +3 | 0 replies | |
| 6/7 | resolve_btfids: Tag the functions that return ERR_PTR()tools/ | +7 | 0 replies | |
| 7/7 | selftests/bpf: Test fmod_ret on functions that return a pointertools/ tools/ tools/ | +12 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH v1 bpf-next 0/7] Tag fmod_ret functions that return ERR_PTR()
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
Signature · 1 line
2.43.0