Re: [PATCH v2 3/3] objtool: Add noinstr validation for static branches/calls

From: Valentin Schneider
Date: Tue Dec 03 2024 - 07:02:35 EST


On 26/11/24 20:47, Josh Poimboeuf wrote:
> @@ -3532,14 +3577,29 @@ static inline bool noinstr_call_dest(struct objtool_file *file,
> return false;
> }
>
> +static char *static_call_name(struct symbol *func)
> +{
> + return func->name + strlen("__SCT__");
> +}
> +
> static int validate_call(struct objtool_file *file,
> struct instruction *insn,
> struct insn_state *state)
> {
> - if (state->noinstr && state->instr <= 0 &&
> - !noinstr_call_dest(file, insn, insn_call_dest(insn))) {
> - WARN_INSN(insn, "call to %s() leaves .noinstr.text section", call_dest_name(insn));
> - return 1;
> + if (state->noinstr && state->instr <= 0) {
> + struct symbol *dest = insn_call_dest(insn);
> +

Interestingly only after I tried making __flush_tlb_all() noinstr did this
start causing a segfault due to a NULL dest. I added a NULL check here but
I wonder if I'm not just plastering over some other issue?

> + if (dest->static_call_tramp) {
> + if (!dest->noinstr_allowed) {
> + WARN_INSN(insn, "%s: non-RO static call usage in noinstr",
> + static_call_name(dest));
> + }
> +
> + } else if (!noinstr_call_allowed(file, insn, dest)) {
> + WARN_INSN(insn, "call to %s() leaves .noinstr.text section",
> + call_dest_name(insn));
> + return 1;
> + }
> }
>
> if (state->uaccess && !func_uaccess_safe(insn_call_dest(insn))) {