Re: [PATCH RFC 34/43] objtool: Adapt indirect call of __fentry__() for PIE support

From: Peter Zijlstra
Date: Fri Apr 28 2023 - 11:19:23 EST


On Fri, Apr 28, 2023 at 05:51:14PM +0800, Hou Wenlong wrote:

> --- a/tools/objtool/arch/x86/decode.c
> +++ b/tools/objtool/arch/x86/decode.c
> @@ -747,15 +747,21 @@ void arch_initial_func_cfi_state(struct cfi_init_state *state)
>
> const char *arch_nop_insn(int len)
> {
> - static const char nops[5][5] = {
> + static const char nops[6][6] = {
> { BYTES_NOP1 },
> { BYTES_NOP2 },
> { BYTES_NOP3 },
> { BYTES_NOP4 },
> { BYTES_NOP5 },
> + /*
> + * For PIE kernel, use a 5-byte nop
> + * and 1-byte nop to keep the frace
> + * hooking algorithm working correct.
> + */
> + { BYTES_NOP5, BYTES_NOP1 },
> };
> - if (len < 1 || len > 5) {
> + if (len < 1 || len > 6) {
> WARN("invalid NOP size: %d\n", len);
> return NULL;
> }

Like Steve already said, this is broken, we hard rely on these things
being single instructions, this must absolutely be BYTES_NOP6.

And yes, then you get to fix a whole lot more.