From: Leizhen Zhang <lzsx618@gmail.com>
To: jpoimboe@kernel.org, peterz@infradead.org
Cc: yangtiezhu@loongson.cn, chenhuacai@kernel.org,
alexandre.chartre@oracle.com, loongarch@lists.linux.dev,
linux-kernel@vger.kernel.org, Leizhen Zhang <lzsx618@gmail.com>
Subject: [PATCH 1/3] objtool/x86: Move the cfi->regs access after the NULL check
Date: Mon, 9 Nov 2026 18:02:53 -0600 [thread overview]
Message-ID: <20261110000255.1720945-2-lzsx618@gmail.com> (raw)
In-Reply-To: <20261110000255.1720945-1-lzsx618@gmail.com>
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@gmail.com>
---
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
next prev parent reply other threads:[~2026-11-10 0:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 0:02 [PATCH 0/3] objtool: Fix undefined behaviour reported by UBSan on a defconfig build Leizhen Zhang
2026-11-10 0:02 ` Leizhen Zhang [this message]
2026-11-10 0:02 ` [PATCH 2/3] objtool/LoongArch: Move the cfi->regs access after the NULL check Leizhen Zhang
2026-11-10 0:02 ` [PATCH 3/3] objtool: Fix misaligned load of the alternative feature word Leizhen Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261110000255.1720945-2-lzsx618@gmail.com \
--to=lzsx618@gmail.com \
--cc=alexandre.chartre@oracle.com \
--cc=chenhuacai@kernel.org \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=peterz@infradead.org \
--cc=yangtiezhu@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®