aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Rutherford <srutherford@google.com>2017-01-11 21:28:29 -0500
committerPaolo Bonzini <pbonzini@redhat.com>2017-01-12 08:34:58 -0500
commit129a72a0d3c8e139a04512325384fe5ac119e74d (patch)
tree56a0adfdeff6c007ba3a5f36577036f20e7d5150
parentcef84c302fe051744b983a92764d3fcca933415d (diff)
KVM: x86: Introduce segmented_write_std
Introduces segemented_write_std. Switches from emulated reads/writes to standard read/writes in fxsave, fxrstor, sgdt, and sidt. This fixes CVE-2017-2584, a longstanding kernel memory leak. Since commit 283c95d0e389 ("KVM: x86: emulate FXSAVE and FXRSTOR", 2016-11-09), which is luckily not yet in any final release, this would also be an exploitable kernel memory *write*! Reported-by: Dmitry Vyukov <dvyukov@google.com> Cc: stable@vger.kernel.org Fixes: 96051572c819194c37a8367624b285be10297eca Fixes: 283c95d0e3891b64087706b344a4b545d04a6e62 Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Steve Rutherford <srutherford@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--arch/x86/kvm/emulate.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 56628a44668b..f36d0fa6b885 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -818,6 +818,20 @@ static int segmented_read_std(struct x86_emulate_ctxt *ctxt,
818 return ctxt->ops->read_std(ctxt, linear, data, size, &ctxt->exception); 818 return ctxt->ops->read_std(ctxt, linear, data, size, &ctxt->exception);
819} 819}
820 820
821static int segmented_write_std(struct x86_emulate_ctxt *ctxt,
822 struct segmented_address addr,
823 void *data,
824 unsigned int size)
825{
826 int rc;
827 ulong linear;
828
829 rc = linearize(ctxt, addr, size, true, &linear);
830 if (rc != X86EMUL_CONTINUE)
831 return rc;
832 return ctxt->ops->write_std(ctxt, linear, data, size, &ctxt->exception);
833}
834
821/* 835/*
822 * Prefetch the remaining bytes of the instruction without crossing page 836 * Prefetch the remaining bytes of the instruction without crossing page
823 * boundary if they are not in fetch_cache yet. 837 * boundary if they are not in fetch_cache yet.
@@ -3685,8 +3699,8 @@ static int emulate_store_desc_ptr(struct x86_emulate_ctxt *ctxt,
3685 } 3699 }
3686 /* Disable writeback. */ 3700 /* Disable writeback. */
3687 ctxt->dst.type = OP_NONE; 3701 ctxt->dst.type = OP_NONE;
3688 return segmented_write(ctxt, ctxt->dst.addr.mem, 3702 return segmented_write_std(ctxt, ctxt->dst.addr.mem,
3689 &desc_ptr, 2 + ctxt->op_bytes); 3703 &desc_ptr, 2 + ctxt->op_bytes);
3690} 3704}
3691 3705
3692static int em_sgdt(struct x86_emulate_ctxt *ctxt) 3706static int em_sgdt(struct x86_emulate_ctxt *ctxt)
@@ -3932,7 +3946,7 @@ static int em_fxsave(struct x86_emulate_ctxt *ctxt)
3932 else 3946 else
3933 size = offsetof(struct fxregs_state, xmm_space[0]); 3947 size = offsetof(struct fxregs_state, xmm_space[0]);
3934 3948
3935 return segmented_write(ctxt, ctxt->memop.addr.mem, &fx_state, size); 3949 return segmented_write_std(ctxt, ctxt->memop.addr.mem, &fx_state, size);
3936} 3950}
3937 3951
3938static int fxrstor_fixup(struct x86_emulate_ctxt *ctxt, 3952static int fxrstor_fixup(struct x86_emulate_ctxt *ctxt,
@@ -3974,7 +3988,7 @@ static int em_fxrstor(struct x86_emulate_ctxt *ctxt)
3974 if (rc != X86EMUL_CONTINUE) 3988 if (rc != X86EMUL_CONTINUE)
3975 return rc; 3989 return rc;
3976 3990
3977 rc = segmented_read(ctxt, ctxt->memop.addr.mem, &fx_state, 512); 3991 rc = segmented_read_std(ctxt, ctxt->memop.addr.mem, &fx_state, 512);
3978 if (rc != X86EMUL_CONTINUE) 3992 if (rc != X86EMUL_CONTINUE)
3979 return rc; 3993 return rc;
3980 3994