From: Oleg Nesterov <oleg@redhat.com>
To: Denys Vlasenko <dvlasenk@redhat.com>
Cc: linux-kernel@vger.kernel.org,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Jim Keniston <jkenisto@us.ibm.com>, Ingo Molnar <mingo@elte.hu>
Subject: Re: [PATCH] uprobes/x86: Refuse to attach uprobe to "word-sized" branch insns
Date: Thu, 24 Apr 2014 19:33:33 +0200 [thread overview]
Message-ID: <20140424173333.GA416@redhat.com> (raw)
In-Reply-To: <1398359304-26472-1-git-send-email-dvlasenk@redhat.com>
Thanks!
Masami, Jim, any acks?
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 <dvlasenk@redhat.com>
> Cc: Oleg Nesterov <oleg@redhat.com>
> ---
> 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
>
next prev parent reply other threads:[~2014-04-24 17:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-24 17:08 [PATCH] uprobes/x86: Refuse to attach uprobe to "word-sized" branch insns Denys Vlasenko
2014-04-24 17:33 ` Oleg Nesterov [this message]
2014-04-25 0:28 ` Jim Keniston
2014-04-25 3:23 ` Masami Hiramatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140424173333.GA416@redhat.com \
--to=oleg@redhat.com \
--cc=dvlasenk@redhat.com \
--cc=jkenisto@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@elte.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox