Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754614AbaDYA3I (ORCPT ); Thu, 24 Apr 2014 20:29:08 -0400 Received: from e39.co.us.ibm.com ([32.97.110.160]:39015 "EHLO e39.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752052AbaDYA3F (ORCPT ); Thu, 24 Apr 2014 20:29:05 -0400 Subject: Re: [PATCH] uprobes/x86: Refuse to attach uprobe to "word-sized" branch insns From: Jim Keniston To: Oleg Nesterov Cc: Denys Vlasenko , linux-kernel@vger.kernel.org, Masami Hiramatsu , Ingo Molnar In-Reply-To: <20140424173333.GA416@redhat.com> References: <1398359304-26472-1-git-send-email-dvlasenk@redhat.com> <20140424173333.GA416@redhat.com> Content-Type: text/plain; charset="UTF-8" Date: Thu, 24 Apr 2014 17:28:57 -0700 Message-ID: <1398385737.4536.13.camel@oc7886638347.ibm.com.usor.ibm.com> Mime-Version: 1.0 X-Mailer: Evolution 2.32.3 (2.32.3-30.el6) Content-Transfer-Encoding: 7bit X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14042500-9332-0000-0000-0000009AA489 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2014-04-24 at 19:33 +0200, Oleg Nesterov wrote: > Thanks! > > Masami, Jim, any acks? Acked-by: Jim Keniston > > On 04/24, Denys Vlasenko wrote: > > > > All branch insns on x86 can be prefixed with the operand-size > > override prefix, 0x66. It was only ever useful for performing > > jumps to 32-bit offsets in 16-bit code segments. > > > > In 32-bit code, such instructions are useless since > > they cause IP truncation to 16 bits, and in case of call insns, > > they save only 16 bits of return address and misalign > > the stack pointer as a "bonus". > > > > In 64-bit code, such instructions are treated differently by Intel > > and AMD CPUs: Intel ignores the prefix altogether, > > AMD treats them the same as in 32-bit mode. > > > > Before this patch, the emulation code would execute > > the instructions as if they have no 0x66 prefix. > > > > With this patch, we refuse to attach uprobes to such insns. > > > > Signed-off-by: Denys Vlasenko > > Cc: Oleg Nesterov > > --- > > arch/x86/kernel/uprobes.c | 12 ++++++++++++ > > 1 file changed, 12 insertions(+) > > > > diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c > > index ace2291..29b152d 100644 > > --- a/arch/x86/kernel/uprobes.c > > +++ b/arch/x86/kernel/uprobes.c > > @@ -582,6 +582,7 @@ static struct uprobe_xol_ops branch_xol_ops = { > > /* Returns -ENOSYS if branch_xol_ops doesn't handle this insn */ > > static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn) > > { > > + int i; > > u8 opc1 = OPCODE1(insn); > > > > /* has the side-effect of processing the entire instruction */ > > @@ -612,6 +613,17 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn) > > return -ENOSYS; > > } > > > > + /* > > + * 16-bit overrides such as CALLW (66 e8 nn nn) are not supported. > > + * Intel and AMD behavior differ in 64-bit mode: Intel ignores 66 prefix. > > + * No one uses these insns. > > + * Reject any branch insns with such prefix. > > + */ > > + for (i = 0; i < insn->prefixes.nbytes; i++) { > > + if (insn->prefixes.bytes[i] == 0x66) > > + return -ENOTSUPP; > > + } > > + > > auprobe->branch.opc1 = opc1; > > auprobe->branch.ilen = insn->length; > > auprobe->branch.offs = insn->immediate.value; > > -- > > 1.8.1.4 > > > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/