diff mbox

qemu-kvm: Work around borken MSR_GET_INDEX_LIST

Message ID 4A4D0F99.2030604@web.de (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Kiszka July 2, 2009, 7:50 p.m. UTC
Allocate enough memory for KVM_GET_MSR_INDEX_LIST as older kernels shot
far beyond their limits, corrupting user space memory.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

 qemu-kvm-x86.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

Comments

Avi Kivity July 6, 2009, 7:50 a.m. UTC | #1
On 07/02/2009 10:50 PM, Jan Kiszka wrote:
> Allocate enough memory for KVM_GET_MSR_INDEX_LIST as older kernels shot
> far beyond their limits, corrupting user space memory.
>    

Applied, thanks.
diff mbox

Patch

diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index d6735c1..e528acb 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -349,7 +349,10 @@  struct kvm_msr_list *kvm_get_msr_list(kvm_context_t kvm)
 	r = ioctl(kvm->fd, KVM_GET_MSR_INDEX_LIST, &sizer);
 	if (r == -1 && errno != E2BIG)
 		return NULL;
-	msrs = malloc(sizeof *msrs + sizer.nmsrs * sizeof *msrs->indices);
+	/* Old kernel modules had a bug and could write beyond the provided
+	   memory. Allocate at least a safe amount of 1K. */
+	msrs = malloc(MAX(1024, sizeof(*msrs) +
+				sizer.nmsrs * sizeof(*msrs->indices)));
 	if (!msrs) {
 		errno = ENOMEM;
 		return NULL;