Re: [PATCH] x86/kprobes: Fix optprobe to detect padding int3 correctly

From: Kees Cook
Date: Fri Dec 11 2020 - 14:41:27 EST


On Fri, Dec 11, 2020 at 04:04:17PM +0900, Masami Hiramatsu wrote:
> Fix optprobe to detect padding int3 correctly.
>
> Since commit 7705dc855797 ("x86/vmlinux: Use INT3 instead of NOP
> for linker fill bytes") changed the padding bytes between functions
> from nop to int3, when optprobe decodes a target function it finds
> int3 and gives up the jump optimization.
>
> Instead of giving up any int3 detection, this checks whether the
> rest of bytes to the end of the function are int3 or not. If all
> of those are int3, those come from the linker. In that case,
> optprobe continues jump optimization.
>
> Fixes: 7705dc855797 ("x86/vmlinux: Use INT3 instead of NOP for linker fill bytes")
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Adam Zabrocki <pi3@xxxxxxxxxx>
> Signed-off-by: Masami Hiramatsu <mhiramat@xxxxxxxxxx>

Reviewed-by: Kees Cook <keescook@xxxxxxxxxxxx>

--
Kees Cook