bpf: Warn with __bpf_trap() kfunc maybe due to uninitialized variable
Status from this message: This series was applied to bpf/bpf-next.git (master)
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v5 Latest3 patches 2 repliesApplied 3/3
- v43 patches 2 repliesSuperseded
- v32 patches 10 repliesSuperseded
Earlier versions · 2
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v2 | 2 patches | 6 replies | Superseded | |
| v1 | 2 patches | 4 replies | Superseded |
Changes in v5 from the cover letter
- v4: https://lore.kernel.org/bpf/[email protected]/
- Change original kfunc bpf_unreachable() to __bpf_trap().
- Better codes for function check_special_kfunc().
Patches in v5 All 3 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | bpf: Remove special_kfunc_set from verifierkernel/ | +177 | 0 replies | Applied |
| 2/3 | bpf: Warn with __bpf_trap() kfunc maybe due to uninitialized variablekernel/ kernel/ | +10 | 0 replies | Applied |
| 3/3 | selftests/bpf: Add unit tests with __bpf_trap() kfunctools/ tools/ | +73 | 1 reply | Applied |
Reviews trailers per patch
None of the 3 patches has a Reviewed-by or Acked-by.
| Patch | Eduard Zingerman |
|---|---|
| Series | T-b |
| 1/3 | |
| 2/3 | |
| 3/3 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH bpf-next v5 0/3] bpf: Warn with __bpf_trap() kfunc maybe due to uninitialized variable
Marc Suñé (Isovalent, part of Cisco) reported an issue where an uninitialized variable caused generating bpf prog binary code not working as expected. The reproducer is in [1] where the flags “-Wall -Werror” are enabled, but there is no warning as the compiler takes advantage of uninitialized variable to do aggressive optimization. Such optimization results in a verification log:
last insn is not an exit or jmp
User still needs to take quite some time to figure out what is the root cause.
To give a better hint to user, __bpf_trap() kfunc is introduced in kernel and the compiler ([2]) will encode __bpf_trap() as needed. For example, compiler may generate 'unreachable' IR after do optimizaiton by taking advantage of uninitialized variable, and later bpf backend will translate such 'unreachable' IR to __bpf_trap() func in final binary. When kernel detects __bpf_trap(), it is able to issue much better verifier log, e.g.
unexpected __bpf_trap() due to uninitialized variable?
[1] https://github.com/msune/clang_bpf/blob/main/Makefile#L3
[2] https://github.com/llvm/llvm-project/pull/131731
Changelogs:
v4 -> v5:
- v4: https://lore.kernel.org/bpf/[email protected]/
- Change original kfunc bpf_unreachable() to __bpf_trap().
- Better codes for function check_special_kfunc().
v3 -> v4:
- v3: https://lore.kernel.org/bpf/[email protected]/
- Remove special_kfunc_set in verifier.
v2 -> v3:
- v2: https://lore.kernel.org/bpf/CAADnVQL9A8vB-yRjnZn8bgMrfDSO17FFBtS_xOs5w-LSq+p74g@mail.gmail.com/
- The newer llvm patch (above [2]) added 'exit' insn if the last insn
in the function is bpf_unreachable(). This way, check_subprogs()
handling is unnecessary and removed.
- Remove the big C test (above [1]) and add a simple C test and three
inline asm tests.
v1 -> v2:
- v1: https://lore.kernel.org/bpf/[email protected]/
- If bpf_unreachable() is hit during check_kfunc_call(), report the verification failure.
- Add three inline asm test cases.
Yonghong Song (3):
bpf: Remove special_kfunc_set from verifier
bpf: Warn with __bpf_trap() kfunc maybe due to uninitialized variable selftests/bpf: Add unit tests with __bpf_trap() kfunc
kernel/bpf/helpers.c | 5 + kernel/bpf/verifier.c | 379 +++++++++--------- .../selftests/bpf/prog_tests/verifier.c | 2 + .../selftests/bpf/progs/verifier_bpf_trap.c | 71 ++++ 4 files changed, 260 insertions(+), 197 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/verifier_bpf_trap.c
Signature · 1 line
2.47.1