[tip: objtool/core] objtool/LoongArch: Move the cfi->regs access after the NULL check
From: tip-bot2 for Leizhen Zhang
Date: Wed Nov 25 2026 - 03:41:35 EST
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: c06e6818861dd242022c5acfa039bea994365aae
Gitweb: https://git.kernel.org/tip/c06e6818861dd242022c5acfa039bea994365aae
Author: Leizhen Zhang <lzsx618@xxxxxxxxx>
AuthorDate: Mon, 09 Nov 2026 18:02:54 -06:00
Committer: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
CommitterDate: Sat, 21 Nov 2026 23:24:39 -08:00
objtool/LoongArch: Move the cfi->regs access after the NULL check
init_orc_entry() takes &cfi->regs[CFI_FP] and &cfi->regs[CFI_RA] before
it checks whether cfi is NULL, although a NULL cfi is an expected case
(unreachable nops/traps and STACK_FRAME_NON_STANDARD functions, as the
comment right below says).
Forming a member address through a NULL pointer is undefined behaviour,
and it lets the compiler assume cfi != NULL and drop the check that
follows. The x86 copy of this function has the same problem, and UBSan
reports it there on every defconfig build.
Take the addresses only after the NULL check.
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: 3c7266cd7bc5 ("objtool/LoongArch: Enable orc to be built")
Signed-off-by: Leizhen Zhang <lzsx618@xxxxxxxxx>
Link: https://patch.msgid.link/20261110000255.1720945-3-lzsx618@xxxxxxxxx
Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
---
tools/objtool/arch/loongarch/orc.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/objtool/arch/loongarch/orc.c b/tools/objtool/arch/loongarch/orc.c
index ffd3a3c..960b59d 100644
--- a/tools/objtool/arch/loongarch/orc.c
+++ b/tools/objtool/arch/loongarch/orc.c
@@ -8,8 +8,7 @@
int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, struct instruction *insn)
{
- struct cfi_reg *fp = &cfi->regs[CFI_FP];
- struct cfi_reg *ra = &cfi->regs[CFI_RA];
+ struct cfi_reg *fp, *ra;
memset(orc, 0, sizeof(*orc));
@@ -23,6 +22,9 @@ int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, struct instruct
return 0;
}
+ fp = &cfi->regs[CFI_FP];
+ ra = &cfi->regs[CFI_RA];
+
switch (cfi->type) {
case UNWIND_HINT_TYPE_UNDEFINED:
orc->type = ORC_TYPE_UNDEFINED;