All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/kprobes: Remove dead code
@ 2021-03-24 17:36 Muhammad Usama Anjum
  2021-03-24 17:50 ` Colin Ian King
  0 siblings, 1 reply; 4+ messages in thread
From: Muhammad Usama Anjum @ 2021-03-24 17:36 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
	H. Peter Anvin, Peter Zijlstra (Intel),
	Masami Hiramatsu, linux-kernel, kernel-janitors, colin.king,
	dan.carpenter
  Cc: musamaanjum, linux-kernel

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@gmail.com>
---
 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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/kprobes: Remove dead code
  2021-03-24 17:36 [PATCH] x86/kprobes: Remove dead code Muhammad Usama Anjum
@ 2021-03-24 17:50 ` Colin Ian King
  2021-03-24 22:56   ` Masami Hiramatsu
  0 siblings, 1 reply; 4+ messages in thread
From: Colin Ian King @ 2021-03-24 17:50 UTC (permalink / raw)
  To: Muhammad Usama Anjum, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, x86, H. Peter Anvin, Peter Zijlstra (Intel),
	Masami Hiramatsu, linux-kernel, kernel-janitors, dan.carpenter

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@gmail.com>
> ---
>  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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/kprobes: Remove dead code
  2021-03-24 17:50 ` Colin Ian King
@ 2021-03-24 22:56   ` Masami Hiramatsu
  2021-03-24 23:50     ` Masami Hiramatsu
  0 siblings, 1 reply; 4+ messages in thread
From: Masami Hiramatsu @ 2021-03-24 22:56 UTC (permalink / raw)
  To: Colin Ian King
  Cc: Muhammad Usama Anjum, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, x86, H. Peter Anvin, Peter Zijlstra (Intel),
	linux-kernel, kernel-janitors, dan.carpenter

On Wed, 24 Mar 2021 17:50:16 +0000
Colin Ian King <colin.king@canonical.com> 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@gmail.com>
> > ---
> >  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@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/kprobes: Remove dead code
  2021-03-24 22:56   ` Masami Hiramatsu
@ 2021-03-24 23:50     ` Masami Hiramatsu
  0 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2021-03-24 23:50 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Colin Ian King, Muhammad Usama Anjum, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, x86, H. Peter Anvin,
	Peter Zijlstra (Intel),
	linux-kernel, kernel-janitors, dan.carpenter

On Thu, 25 Mar 2021 07:56:54 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> On Wed, 24 Mar 2021 17:50:16 +0000
> Colin Ian King <colin.king@canonical.com> 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@gmail.com>
> > > ---
> > >  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;
> 	}

Hmm, wait. I think there is no reason don't use range case.
I think the root cause of this issue is using masked opcode for
switching. Let me clean it up.

Thank you,

-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-24 23:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24 17:36 [PATCH] x86/kprobes: Remove dead code Muhammad Usama Anjum
2021-03-24 17:50 ` Colin Ian King
2021-03-24 22:56   ` Masami Hiramatsu
2021-03-24 23:50     ` Masami Hiramatsu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.