Re: [PATCH] objtool: Detect __nocfi calls

From: Josh Poimboeuf
Date: Thu Apr 10 2025 - 15:09:15 EST


On Thu, Apr 10, 2025 at 05:45:56PM +0200, Peter Zijlstra wrote:
> On Thu, Apr 10, 2025 at 03:25:22PM +0200, Peter Zijlstra wrote:
>
> > I should get objtool to warn about those. They undermine the point of
> > CFI.
>
> ---
> Subject: objtool: Detect __nocfi calls

"Warn on indirect calls in __nocfi functions" ?

> static int add_retpoline_call(struct objtool_file *file, struct instruction *insn)
> {
> + struct symbol *sym = insn->sym;
> +
> + /*
> + * kCFI call sites look like:
> + *
> + * movl $(-0x12345678), %r10d
> + * addl -4(%r11), %r10d
> + * jz 1f
> + * ud2
> + * 1: cs call __x86_indirect_thunk_r11
> + *
> + * Verify all indirect calls are kCFI adorned by checking for the UD2.
> + * Notably, doing __nocfi calls to regular (cfi) functions is broken.
> + */
> + if (opts.cfi && sym && sym->type == STT_FUNC && !sym->nocfi) {
> + struct instruction *prev = prev_insn_same_sym(file, insn);
> + if (!prev || prev->type != INSN_BUG)
> + WARN_INSN(insn, "no-cfi indirect call!");

Since this can break things pretty badly at runtime, this should
actually fail the build on CONFIG_OBJTOOL_WERROR.

The warning counts aren't plumbed in this early, so can this check be
done later? validate_retpoline() or validate_call()?

--
Josh