[PATCH 1/3] objtool/x86: Move the cfi->regs access after the NULL check

From: Leizhen Zhang

Date: Mon Nov 09 2026 - 19:07:48 EST


init_orc_entry() takes &cfi->regs[CFI_BP] before it checks whether cfi
is NULL, and a NULL cfi is an expected case: the comment right below
says it happens for unreachable nops/traps and for
STACK_FRAME_NON_STANDARD functions.

Forming a member address through a NULL pointer is undefined behaviour,
and since the dereference comes first the compiler is free to assume
cfi != NULL and drop the check that follows. An x86_64 defconfig build
of v7.4-rc2 with objtool built with -fsanitize=undefined hits it in
every objtool run, on vmlinux.o and on each module, all through
orc_create():

arch/x86/orc.c:11:18: runtime error: member access within null pointer of type 'struct cfi_state'
#0 init_orc_entry arch/x86/orc.c:11
#1 orc_create tools/objtool/orc_gen.c:72
#2 check tools/objtool/check.c:4939

Take the address only after the NULL check. Running objtool with and
without this patch on the same defconfig vmlinux.o gives byte-identical
output.

The report was found with UBSan, and the analysis and fix were
prepared with the help of an AI coding assistant; I reviewed and
tested the result.

Fixes: 8b946cc38e06 ("objtool: Introduce CFI hash")
Signed-off-by: Leizhen Zhang <lzsx618@xxxxxxxxx>
---
tools/objtool/arch/x86/orc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/objtool/arch/x86/orc.c b/tools/objtool/arch/x86/orc.c
index eff078ecc945..b688afcc4ffc 100644
--- a/tools/objtool/arch/x86/orc.c
+++ b/tools/objtool/arch/x86/orc.c
@@ -8,7 +8,7 @@

int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, struct instruction *insn)
{
- struct cfi_reg *bp = &cfi->regs[CFI_BP];
+ struct cfi_reg *bp;

memset(orc, 0, sizeof(*orc));

@@ -22,6 +22,8 @@ int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, struct instruct
return 0;
}

+ bp = &cfi->regs[CFI_BP];
+
switch (cfi->type) {
case UNWIND_HINT_TYPE_UNDEFINED:
orc->type = ORC_TYPE_UNDEFINED;
--
2.34.1