From: Mohammed Gamal <m.gamal005@gmail.com>
To: avi@redhat.com
Cc: mtosatti@redhat.com, kvm@vger.kernel.org,
Mohammed Gamal <m.gamal005@gmail.com>
Subject: [RFC PATCH v3 2/3] x86 emulator: Add segment limit checking helpers
Date: Mon, 12 Jul 2010 01:56:09 +0300 [thread overview]
Message-ID: <1278888970-2936-3-git-send-email-m.gamal005@gmail.com> (raw)
In-Reply-To: <1278888970-2936-1-git-send-email-m.gamal005@gmail.com>
Adds segment limit checking helper functions. Also added a cs_base() helper while at it.
Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
---
arch/x86/kvm/emulate.c | 33 ++++++++++++++++++++++++++++++++-
1 files changed, 32 insertions(+), 1 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 255473f..07ca28e 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -633,6 +633,15 @@ static unsigned long seg_base(struct x86_emulate_ctxt *ctxt,
return ops->get_cached_segment_base(seg, ctxt->vcpu);
}
+static u64 seg_limit(struct x86_emulate_ctxt *ctxt,
+ struct x86_emulate_ops *ops, int seg)
+{
+ if (ctxt->mode == X86EMUL_MODE_PROT64)
+ return -1ULL;
+
+ return ops->get_cached_segment_limit(seg, ctxt->vcpu);
+}
+
static unsigned long seg_override_base(struct x86_emulate_ctxt *ctxt,
struct x86_emulate_ops *ops,
struct decode_cache *c)
@@ -643,6 +652,12 @@ static unsigned long seg_override_base(struct x86_emulate_ctxt *ctxt,
return seg_base(ctxt, ops, c->seg_override);
}
+static unsigned long cs_base(struct x86_emulate_ctxt *ctxt,
+ struct x86_emulate_ops *ops)
+{
+ return seg_base(ctxt, ops, VCPU_SREG_CS);
+}
+
static unsigned long es_base(struct x86_emulate_ctxt *ctxt,
struct x86_emulate_ops *ops)
{
@@ -686,6 +701,22 @@ static void emulate_ts(struct x86_emulate_ctxt *ctxt, int err)
emulate_exception(ctxt, TS_VECTOR, err, true);
}
+static int seg_limit_check(struct x86_emulate_ctxt *ctxt,
+ struct x86_emulate_ops *ops, int seg,
+ unsigned long addr, unsigned size,
+ int vec, u32 err)
+{
+ unsigned long base = seg_base(ctxt, ops, seg);
+ u64 limit = seg_limit(ctxt, ops, seg);
+
+ if (addr - base + size - 1 > limit) {
+ emulate_exception(ctxt, vec, err, true);
+ return X86EMUL_PROPAGATE_FAULT;
+ }
+
+ return X86EMUL_CONTINUE;
+}
+
static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt,
struct x86_emulate_ops *ops,
unsigned long eip, u8 *dest)
@@ -976,7 +1007,7 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
c->eip = ctxt->eip;
c->fetch.start = c->fetch.end = c->eip;
- ctxt->cs_base = seg_base(ctxt, ops, VCPU_SREG_CS);
+ ctxt->cs_base = cs_base(ctxt, ops);
switch (mode) {
case X86EMUL_MODE_REAL:
--
1.7.0.4
next prev parent reply other threads:[~2010-07-11 22:56 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-11 22:56 [RFC PATCH v3 0/3] Add segment limit checks to emulator Mohammed Gamal
2010-07-11 22:56 ` [RFC PATCH v3 1/3] Add helper methods to get segment limits Mohammed Gamal
2010-07-11 22:56 ` Mohammed Gamal [this message]
2010-07-11 22:56 ` [RFC PATCH v3 3/3] x86 emulator: Add segment limit checks to emulator functions Mohammed Gamal
2010-07-12 6:26 ` [RFC PATCH v3 0/3] Add segment limit checks to emulator Avi Kivity
2010-07-12 12:36 ` Mohammed Gamal
2010-07-12 13:13 ` Avi Kivity
[not found] ` <AANLkTimHvpE05chocuoQnY0ydOMchMcIInu9QX5F_pV4@mail.gmail.com>
2010-07-12 13:51 ` Avi Kivity
2010-07-12 14:41 ` Gleb Natapov
2010-07-12 14:49 ` Avi Kivity
2010-07-24 15:45 ` Kevin O'Connor
2010-07-24 16:16 ` Kevin O'Connor
2010-07-25 8:55 ` Avi Kivity
2010-07-25 16:42 ` Kevin O'Connor
2010-07-25 17:19 ` Kevin O'Connor
2010-07-25 18:34 ` Avi Kivity
2010-07-25 18:55 ` Kevin O'Connor
2010-07-25 8:54 ` Avi Kivity
2010-07-25 16:23 ` Kevin O'Connor
2010-07-26 11:47 ` Avi Kivity
2010-07-26 17:47 ` Stefan Hajnoczi
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=1278888970-2936-3-git-send-email-m.gamal005@gmail.com \
--to=m.gamal005@gmail.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
/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