qemu-kvm: Work around borken MSR_GET_INDEX_LIST
PATCH 1/1 qemu-kvm: Work around borken MSR_GET_INDEX_LIST
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 <[email protected]>
---
qemu-kvm-x86.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
qemu-kvm-x86.c +4 -1
@@ -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 ;
Avi Kivity
AppliedQuoted 3 lines · Jan Kiszka
Allocate enough memory for
KVM_GET_MSR_INDEX_LISTas older kernels shot far beyond their limits, corrupting user space memory.
Applied, thanks.
Signature · 1 line
error compiling committee.c: too many arguments to function