提交 cb864b57 编写于 作者: S Sean Christopherson 提交者: Zheng Zengkai

KVM: Disallow user memslot with size that exceeds "unsigned long"

stable inclusion
from stable-v5.10.84
commit 6a44f200f1f15d041dc381dd13dd840ac36af863
bugzilla: 186030 https://gitee.com/openeuler/kernel/issues/I4QV2F

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=6a44f200f1f15d041dc381dd13dd840ac36af863

--------------------------------

commit 6b285a55 upstream.

Reject userspace memslots whose size exceeds the storage capacity of an
"unsigned long".  KVM's uAPI takes the size as u64 to support large slots
on 64-bit hosts, but does not account for the size being truncated on
32-bit hosts in various flows.  The access_ok() check on the userspace
virtual address in particular casts the size to "unsigned long" and will
check the wrong number of bytes.

KVM doesn't actually support slots whose size doesn't fit in an "unsigned
long", e.g. KVM's internal kvm_memory_slot.npages is an "unsigned long",
not a "u64", and misc arch specific code follows that behavior.

Fixes: fa3d315a ("KVM: Validate userspace_addr of memslot when registered")
Cc: stable@vger.kernel.org
Signed-off-by: NSean Christopherson <seanjc@google.com>
Reviewed-by: NMaciej S. Szmigiero <maciej.szmigiero@oracle.com>
Message-Id: <20211104002531.1176691-3-seanjc@google.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 ce02e0c2
...@@ -1305,7 +1305,8 @@ int __kvm_set_memory_region(struct kvm *kvm, ...@@ -1305,7 +1305,8 @@ int __kvm_set_memory_region(struct kvm *kvm,
id = (u16)mem->slot; id = (u16)mem->slot;
/* General sanity checks */ /* General sanity checks */
if (mem->memory_size & (PAGE_SIZE - 1)) if ((mem->memory_size & (PAGE_SIZE - 1)) ||
(mem->memory_size != (unsigned long)mem->memory_size))
return -EINVAL; return -EINVAL;
if (mem->guest_phys_addr & (PAGE_SIZE - 1)) if (mem->guest_phys_addr & (PAGE_SIZE - 1))
return -EINVAL; return -EINVAL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册