Re: [PATCH] x86/kprobes: Remove dead code

From: Masami Hiramatsu
Date: Wed Mar 24 2021 - 18:58:15 EST


On Wed, 24 Mar 2021 17:50:16 +0000
Colin Ian King <colin.king@xxxxxxxxxxxxx> wrote:

> On 24/03/2021 17:36, Muhammad Usama Anjum wrote:
> > The condition in switch statement `opcode & 0xf0` cannot evaluate to
> > 0xff. So this case statement will never execute. Remove it.
> >
> > Fixes: 6256e668b7 ("x86/kprobes: Use int3 instead of debug trap for single-step")
> > Signed-off-by: Muhammad Usama Anjum <musamaanjum@xxxxxxxxx>
> > ---
> > arch/x86/kernel/kprobes/core.c | 3 ---
> > 1 file changed, 3 deletions(-)
> >
> > diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
> > index 89d9f26785c7..3b7bcc077020 100644
> > --- a/arch/x86/kernel/kprobes/core.c
> > +++ b/arch/x86/kernel/kprobes/core.c
> > @@ -177,9 +177,6 @@ int can_boost(struct insn *insn, void *addr)
> > case 0xf0:
> > /* clear and set flags are boostable */
> > return (opcode == 0xf5 || (0xf7 < opcode && opcode < 0xfe));
> > - case 0xff:
> > - /* indirect jmp is boostable */
> > - return X86_MODRM_REG(insn->modrm.bytes[0]) == 4;
> > default:
> > /* CS override prefix and call are not boostable */
> > return (opcode != 0x2e && opcode != 0x9a);
> >
>
> The 0xff case was added with some form of intention to be executed so I
> suspect removing it is not an appropriate fix.

Right, it must be moved under the case 0xf0. Something like this.

case 0xf0:
if (opcde == 0xff) {
/* indirect jmp is boostable */
return X86_MODRM_REG(insn->modrm.bytes[0]) == 4;
}

Thank you,

--
Masami Hiramatsu <mhiramat@xxxxxxxxxx>