Re: [PATCH RFC 22/43] x86/ftrace: Adapt ftrace nop patching for PIE support

From: Steven Rostedt
Date: Fri Apr 28 2023 - 09:45:04 EST


On Fri, 28 Apr 2023 17:51:02 +0800
"Hou Wenlong" <houwenlong.hwl@xxxxxxxxxxxx> wrote:

> From: Thomas Garnier <thgarnie@xxxxxxxxxxxx>
>
> From: Thomas Garnier <thgarnie@xxxxxxxxxxxx>
>
> When using PIE with function tracing, the compiler generates a
> call through the GOT (call *__fentry__@GOTPCREL). This instruction
> takes 6-bytes instead of 5-bytes with a relative call. And -mnop-mcount
> option is not implemented for -fPIE now.
>
> If PIE is enabled, replace the 6th byte of the GOT call by a 1-byte nop
> so ftrace can handle the previous 5-bytes as before.

Wait! This won't work!

You can't just append another nop to fill in the blanks here. We must
either have a single 6 byte nop, or we need to refactor the entire logic to
something that other archs have.

The two nops means that the CPU can take it as two separate commands.
There's nothing stopping the computer from preempting a task between the
two. If that happens, and you modify the 1byte nop and 5byte nop with a
single 6 byte command, when the task get's rescheduled, it will execute the
last 5 bytes of that 6 byte command and take a general protection fault, and
likely crash the machine.

NACK on this. It needs a better solution.

-- Steve


>
> [Hou Wenlong: Adapt code change and fix wrong offset calculation in
> make_nop_x86()]
>