mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
KVM: SVM: prevent DBG_DECRYPT and DBG_ENCRYPT overflow
[ Upstream commit b86bc2858b ]
This ensures that the address and length provided to DBG_DECRYPT and
DBG_ENCRYPT do not cause an overflow.
At the same time, pass the actual number of pages pinned in memory to
sev_unpin_memory() as a cleanup.
Reported-by: Cfir Cohen <cfir@google.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin (Microsoft) <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
93e9dabbcd
commit
271ea551cf
@@ -6815,7 +6815,8 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec)
|
|||||||
struct page **src_p, **dst_p;
|
struct page **src_p, **dst_p;
|
||||||
struct kvm_sev_dbg debug;
|
struct kvm_sev_dbg debug;
|
||||||
unsigned long n;
|
unsigned long n;
|
||||||
int ret, size;
|
unsigned int size;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (!sev_guest(kvm))
|
if (!sev_guest(kvm))
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
@@ -6823,6 +6824,11 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec)
|
|||||||
if (copy_from_user(&debug, (void __user *)(uintptr_t)argp->data, sizeof(debug)))
|
if (copy_from_user(&debug, (void __user *)(uintptr_t)argp->data, sizeof(debug)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
|
if (!debug.len || debug.src_uaddr + debug.len < debug.src_uaddr)
|
||||||
|
return -EINVAL;
|
||||||
|
if (!debug.dst_uaddr)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
vaddr = debug.src_uaddr;
|
vaddr = debug.src_uaddr;
|
||||||
size = debug.len;
|
size = debug.len;
|
||||||
vaddr_end = vaddr + size;
|
vaddr_end = vaddr + size;
|
||||||
@@ -6873,8 +6879,8 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec)
|
|||||||
dst_vaddr,
|
dst_vaddr,
|
||||||
len, &argp->error);
|
len, &argp->error);
|
||||||
|
|
||||||
sev_unpin_memory(kvm, src_p, 1);
|
sev_unpin_memory(kvm, src_p, n);
|
||||||
sev_unpin_memory(kvm, dst_p, 1);
|
sev_unpin_memory(kvm, dst_p, n);
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|||||||
Reference in New Issue
Block a user