Re: [RFC PATCH v2 28/30] tools/unwind: Add CFG instruction abstract execution oracle to verify_cfi

From: bot+bpf-ci

Date: Wed Nov 25 2026 - 02:07:01 EST


> tools/unwind: Add CFG instruction abstract execution oracle to verify_cfi

TL;DR:
- verify_cfi may skip code after returning calls or syscall/svc/ecall, and
silently skips past 4096 instructions, yet still counts functions clean, so
--strict may miss CFI mismatches
- noreturn name list may be wrong

> diff --git a/tools/unwind/verify_insn.cpp b/tools/unwind/verify_insn.cpp
> --- /dev/null
> +++ b/tools/unwind/verify_insn.cpp

[ ... ]

> +bool isKnownNoreturnName(StringRef Name)
> +{
> + static const char *const Exact[] = {
> + "panic", "do_exit", "make_task_dead", "__stack_chk_fail",
> + "__stack_chk_fail_local", "fortify_panic", "usercopy_abort",
> + "__bug", "bug_at", "do_group_exit", "complete_and_exit",

[ ... ]

> + if (Name.starts_with("__throw_") || Name.starts_with("_ZSt7__throw") ||
> + Name.starts_with("_ZSt9__throw") || Name.contains("panicking") ||
> + Name.starts_with("rust_begin_unwind") || Name.contains("noreturn") ||
> + Name.starts_with("__bad_"))
> + return true;
> + return false;
> +}

The kernel-doc says this returns true only when calls to @Name never return.
Can Name.starts_with("__bad_") match functions that do return?

__bad_area() and __bad_area_nosemaphore() in arch/x86/mm/fault.c are
ordinary static void functions, and bad_area_nosemaphore() returns after
calling __bad_area_nosemaphore(). Similarly, Name.contains("panicking")
also matches returning Rust std helpers such as
std::panicking::panic_count::is_zero_slow_path() -> bool.

verifyFile() puts the address of every such symbol into noreturn_addrs, and
verifyOracle2Instructions() then does:

if (has_target &&
noreturn_addrs.count(CallTarget))
continue;

so the fallthrough PC is never enqueued. Instructions only reachable past
such a call (e.g. the epilogue after call __bad_area_nosemaphore) are never
checked, yet the function is still counted in funcs_clean. Could these two
rules be narrowed to exact names (or core::panicking only)?

The kernel names in Exact[] also differ from tools/objtool/noreturns.h:
complete_and_exit and bug_at do not exist in this tree, and fortify_panic
is a macro (the symbol is __fortify_panic). __fortify_panic,
kthread_complete_and_exit, vpanic and do_task_dead are not recognized.
Could the kernel names come from tools/objtool/noreturns.h instead of a
separate hand-kept list?

The prefixes _ZSt7__throw and _ZSt9__throw can only match a 7- or
9-character std:: identifier starting with __throw, so helpers like
_ZSt16__throw_bad_castv or _ZSt28__throw_bad_array_new_lengthv are missed.

[ ... ]

> + bool func_ok = true;
> + unsigned steps = 0;
> + while (!worklist.empty() && steps < 4096) {
> + uint64_t pc = worklist.front();
> + worklist.pop();
> + steps++;

Each PC enters the worklist at most once, so steps counts distinct checked
instructions. When a function has more than 4096 reachable instructions,
the loop exits with the worklist still non-empty. Is it intended that the
function is then still counted by:

> + if (func_ok)
> + st.funcs_clean++;

func_ok is only cleared by an fde_eval_error or an evalRowAgainstAbs()
failure on one of the first 4096 PCs. Nothing records the truncation, so
the function is listed as "Functions 100% instruction-clean", and a
CFA/RA/FP mismatch after the cutoff is not counted in insns_*_mismatch, so
--strict still exits 0. Large functions such as sqlite3VdbeExec exceed this
easily.

The decode-failure path behaves the same way:
`if (DStat != MCDisassembler::Success || InsnSize == 0) continue;` drops all
successors of an undecodable instruction and the function can still be
counted clean. This also seems to contradict the commit message's
"verifying at every reachable instruction". Could a truncated or abandoned
walk clear func_ok, or be recorded with recordIssue() (for example as
"step_limit")?

[ ... ]

> + if (is_ret_or_ind_jump || Desc.isTrap() ||
> + OpName == "UD2" || OpName == "BRK" ||
> + OpName == "EBREAK" || OpName == "C_EBREAK" ||
> + OpName == "SVC" || OpName == "ECALL" ||
> + OpName == "SYSCALL" || OpName == "IRET64" ||
> + OpName == "SYSRET64" || OpName == "ERET" ||
> + OpName == "SRET" || OpName == "MRET")
> + continue;

SVC, ECALL and SYSCALL return to the next instruction, but here they end the
path and next_pc is never enqueued. Everything after them on that path is
unchecked, and the function can still be counted in funcs_clean.

Examples are the arm64 vDSO fallbacks in
arch/arm64/include/asm/vdso/gettimeofday.h (svc #0 followed by the return
and the caller's epilogue), RISC-V sbi_ecall(), and user-space syscall
wrappers (syscall; cmp $-4095,%rax; ...; ret). The address after a syscall
instruction is also the user PC that dwarf_cfi_unwind_user_eh_frame_hdr()
starts from for a task that entered the kernel through a syscall.

sigreturn trampolines are already excluded by the earlier
`if (fr->signal) continue;`, and HVC/SMC are not in the list and fall
through. Should SVC/ECALL/SYSCALL be dropped from this terminator list so
the fallthrough is verified, with stepInstruction() clobbering their defs?


---
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/45561209846