uprobes/x86: allow to probe a "nop" insn with 0x66 prefix

Message ID 20221201142644.GA27185@redhat.com
State New
Headers
Series uprobes/x86: allow to probe a "nop" insn with 0x66 prefix |

Commit Message

Oleg Nesterov Dec. 1, 2022, 2:26 p.m. UTC
  From: Denys Vlasenko <dvlasenk@redhat.com>

Intel icc -hotpatch inserts 2-byte "0x66 0x90" NOP at the start of each
function to reserve extra space for hot-patching, and currently it is not
possible to probe these functions because branch_setup_xol_ops() wrongly
nacks NOP with REP prefix.

Fixes: 250bbd12c2fe ("uprobes/x86: Refuse to attach uprobe to "word-sized" branch insns")
Reported-by: Seiji Nishikawa <snishika@redhat.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 arch/x86/kernel/uprobes.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Masami Hiramatsu (Google) Dec. 1, 2022, 10:30 p.m. UTC | #1
On Thu, 1 Dec 2022 15:26:44 +0100
Oleg Nesterov <oleg@redhat.com> wrote:

> From: Denys Vlasenko <dvlasenk@redhat.com>
> 
> Intel icc -hotpatch inserts 2-byte "0x66 0x90" NOP at the start of each
> function to reserve extra space for hot-patching, and currently it is not
> possible to probe these functions because branch_setup_xol_ops() wrongly
> nacks NOP with REP prefix.

Looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thank you!

> 
> Fixes: 250bbd12c2fe ("uprobes/x86: Refuse to attach uprobe to "word-sized" branch insns")
> Reported-by: Seiji Nishikawa <snishika@redhat.com>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> ---
>  arch/x86/kernel/uprobes.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
> index b63cf8f7745e..6c07f6daaa22 100644
> --- a/arch/x86/kernel/uprobes.c
> +++ b/arch/x86/kernel/uprobes.c
> @@ -722,8 +722,9 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)
>  	switch (opc1) {
>  	case 0xeb:	/* jmp 8 */
>  	case 0xe9:	/* jmp 32 */
> -	case 0x90:	/* prefix* + nop; same as jmp with .offs = 0 */
>  		break;
> +	case 0x90:	/* prefix* + nop; same as jmp with .offs = 0 */
> +		goto setup;
>  
>  	case 0xe8:	/* call relative */
>  		branch_clear_offset(auprobe, insn);
> @@ -753,6 +754,7 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)
>  			return -ENOTSUPP;
>  	}
>  
> +setup:
>  	auprobe->branch.opc1 = opc1;
>  	auprobe->branch.ilen = insn->length;
>  	auprobe->branch.offs = insn->immediate.value;
> -- 
> 2.25.1.362.g51ebf55
> 
>
  
Thomas Gleixner Dec. 2, 2022, 11:52 a.m. UTC | #2
On Thu, Dec 01 2022 at 15:26, Oleg Nesterov wrote:

> From: Denys Vlasenko <dvlasenk@redhat.com>
>
> Intel icc -hotpatch inserts 2-byte "0x66 0x90" NOP at the start of each
> function to reserve extra space for hot-patching, and currently it is not
> possible to probe these functions because branch_setup_xol_ops() wrongly
> nacks NOP with REP prefix.
>
> Fixes: 250bbd12c2fe ("uprobes/x86: Refuse to attach uprobe to "word-sized" branch insns")
> Reported-by: Seiji Nishikawa <snishika@redhat.com>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>

The SOB chain is invalid as it lacks the author's signoff.
  
Oleg Nesterov Dec. 2, 2022, 12:54 p.m. UTC | #3
On 12/02, Thomas Gleixner wrote:
>
> On Thu, Dec 01 2022 at 15:26, Oleg Nesterov wrote:
>
> > From: Denys Vlasenko <dvlasenk@redhat.com>
> >
> > Intel icc -hotpatch inserts 2-byte "0x66 0x90" NOP at the start of each
> > function to reserve extra space for hot-patching, and currently it is not
> > possible to probe these functions because branch_setup_xol_ops() wrongly
> > nacks NOP with REP prefix.
> >
> > Fixes: 250bbd12c2fe ("uprobes/x86: Refuse to attach uprobe to "word-sized" branch insns")
> > Reported-by: Seiji Nishikawa <snishika@redhat.com>
> > Signed-off-by: Oleg Nesterov <oleg@redhat.com>
>
> The SOB chain is invalid as it lacks the author's signoff.

Denys, can we have your signed-off-by?
  
Oleg Nesterov Dec. 4, 2022, 5:34 p.m. UTC | #4
On 12/02, Oleg Nesterov wrote:
>
> On 12/02, Thomas Gleixner wrote:
> >
> > On Thu, Dec 01 2022 at 15:26, Oleg Nesterov wrote:
> >
> > > From: Denys Vlasenko <dvlasenk@redhat.com>
> > >
> > > Intel icc -hotpatch inserts 2-byte "0x66 0x90" NOP at the start of each
> > > function to reserve extra space for hot-patching, and currently it is not
> > > possible to probe these functions because branch_setup_xol_ops() wrongly
> > > nacks NOP with REP prefix.
> > >
> > > Fixes: 250bbd12c2fe ("uprobes/x86: Refuse to attach uprobe to "word-sized" branch insns")
> > > Reported-by: Seiji Nishikawa <snishika@redhat.com>
> > > Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> >
> > The SOB chain is invalid as it lacks the author's signoff.
>
> Denys, can we have your signed-off-by?

OK, let me turn "From" into "Suggested-by" if this can help to merge this fix.

After all, the patch is really simple, I don't think Denys will object when he
returns.

I am sending v2 with Masami's ack applied.

Oleg.
  

Patch

diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
index b63cf8f7745e..6c07f6daaa22 100644
--- a/arch/x86/kernel/uprobes.c
+++ b/arch/x86/kernel/uprobes.c
@@ -722,8 +722,9 @@  static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)
 	switch (opc1) {
 	case 0xeb:	/* jmp 8 */
 	case 0xe9:	/* jmp 32 */
-	case 0x90:	/* prefix* + nop; same as jmp with .offs = 0 */
 		break;
+	case 0x90:	/* prefix* + nop; same as jmp with .offs = 0 */
+		goto setup;
 
 	case 0xe8:	/* call relative */
 		branch_clear_offset(auprobe, insn);
@@ -753,6 +754,7 @@  static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)
 			return -ENOTSUPP;
 	}
 
+setup:
 	auprobe->branch.opc1 = opc1;
 	auprobe->branch.ilen = insn->length;
 	auprobe->branch.offs = insn->immediate.value;