[tip: objtool/core] objtool/x86: Move the cfi->regs access after the NULL check
From: tip-bot2 for Leizhen Zhang
Date: Wed Nov 25 2026 - 03:41:33 EST
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: a28b5c2b2a2f6fa30e06d7515c644e519e5cbd77
Gitweb: https://git.kernel.org/tip/a28b5c2b2a2f6fa30e06d7515c644e519e5cbd77
Author: Leizhen Zhang <lzsx618@xxxxxxxxx>
AuthorDate: Mon, 09 Nov 2026 18:02:53 -06:00
Committer: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
CommitterDate: Sat, 21 Nov 2026 23:24:39 -08:00
objtool/x86: Move the cfi->regs access after the NULL check
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>
Link: https://patch.msgid.link/20261110000255.1720945-2-lzsx618@xxxxxxxxx
Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
---
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 eff078e..b688afc 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;