Commit d22d2474 authored by Ashish Kalra's avatar Ashish Kalra Committed by Paolo Bonzini

KVM: SVM: Use kzalloc for sev ioctl interfaces to prevent kernel data leak

For some sev ioctl interfaces, the length parameter that is passed maybe
less than or equal to SEV_FW_BLOB_MAX_SIZE, but larger than the data
that PSP firmware returns. In this case, kmalloc will allocate memory
that is the size of the input rather than the size of the data.
Since PSP firmware doesn't fully overwrite the allocated buffer, these
sev ioctl interface may return uninitialized kernel slab memory.
Reported-by: default avatarAndy Nguyen <theflow@google.com>
Suggested-by: default avatarDavid Rientjes <rientjes@google.com>
Suggested-by: default avatarPeter Gonda <pgonda@google.com>
Cc: kvm@vger.kernel.org
Cc: stable@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Fixes: eaf78265 ("KVM: SVM: Move SEV code to separate file")
Fixes: 2c07ded0 ("KVM: SVM: add support for SEV attestation command")
Fixes: 4cfdd47d ("KVM: SVM: Add KVM_SEV SEND_START command")
Fixes: d3d1af85 ("KVM: SVM: Add KVM_SEND_UPDATE_DATA command")
Fixes: eba04b20 ("KVM: x86: Account a variety of miscellaneous allocations")
Signed-off-by: default avatarAshish Kalra <ashish.kalra@amd.com>
Reviewed-by: default avatarPeter Gonda <pgonda@google.com>
Message-Id: <20220516154310.3685678-1-Ashish.Kalra@amd.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent d187ba53
...@@ -688,7 +688,7 @@ static int sev_launch_measure(struct kvm *kvm, struct kvm_sev_cmd *argp) ...@@ -688,7 +688,7 @@ static int sev_launch_measure(struct kvm *kvm, struct kvm_sev_cmd *argp)
if (params.len > SEV_FW_BLOB_MAX_SIZE) if (params.len > SEV_FW_BLOB_MAX_SIZE)
return -EINVAL; return -EINVAL;
blob = kmalloc(params.len, GFP_KERNEL_ACCOUNT); blob = kzalloc(params.len, GFP_KERNEL_ACCOUNT);
if (!blob) if (!blob)
return -ENOMEM; return -ENOMEM;
...@@ -808,7 +808,7 @@ static int __sev_dbg_decrypt_user(struct kvm *kvm, unsigned long paddr, ...@@ -808,7 +808,7 @@ static int __sev_dbg_decrypt_user(struct kvm *kvm, unsigned long paddr,
if (!IS_ALIGNED(dst_paddr, 16) || if (!IS_ALIGNED(dst_paddr, 16) ||
!IS_ALIGNED(paddr, 16) || !IS_ALIGNED(paddr, 16) ||
!IS_ALIGNED(size, 16)) { !IS_ALIGNED(size, 16)) {
tpage = (void *)alloc_page(GFP_KERNEL); tpage = (void *)alloc_page(GFP_KERNEL | __GFP_ZERO);
if (!tpage) if (!tpage)
return -ENOMEM; return -ENOMEM;
...@@ -1094,7 +1094,7 @@ static int sev_get_attestation_report(struct kvm *kvm, struct kvm_sev_cmd *argp) ...@@ -1094,7 +1094,7 @@ static int sev_get_attestation_report(struct kvm *kvm, struct kvm_sev_cmd *argp)
if (params.len > SEV_FW_BLOB_MAX_SIZE) if (params.len > SEV_FW_BLOB_MAX_SIZE)
return -EINVAL; return -EINVAL;
blob = kmalloc(params.len, GFP_KERNEL_ACCOUNT); blob = kzalloc(params.len, GFP_KERNEL_ACCOUNT);
if (!blob) if (!blob)
return -ENOMEM; return -ENOMEM;
...@@ -1176,7 +1176,7 @@ static int sev_send_start(struct kvm *kvm, struct kvm_sev_cmd *argp) ...@@ -1176,7 +1176,7 @@ static int sev_send_start(struct kvm *kvm, struct kvm_sev_cmd *argp)
return -EINVAL; return -EINVAL;
/* allocate the memory to hold the session data blob */ /* allocate the memory to hold the session data blob */
session_data = kmalloc(params.session_len, GFP_KERNEL_ACCOUNT); session_data = kzalloc(params.session_len, GFP_KERNEL_ACCOUNT);
if (!session_data) if (!session_data)
return -ENOMEM; return -ENOMEM;
...@@ -1300,11 +1300,11 @@ static int sev_send_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp) ...@@ -1300,11 +1300,11 @@ static int sev_send_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp)
/* allocate memory for header and transport buffer */ /* allocate memory for header and transport buffer */
ret = -ENOMEM; ret = -ENOMEM;
hdr = kmalloc(params.hdr_len, GFP_KERNEL_ACCOUNT); hdr = kzalloc(params.hdr_len, GFP_KERNEL_ACCOUNT);
if (!hdr) if (!hdr)
goto e_unpin; goto e_unpin;
trans_data = kmalloc(params.trans_len, GFP_KERNEL_ACCOUNT); trans_data = kzalloc(params.trans_len, GFP_KERNEL_ACCOUNT);
if (!trans_data) if (!trans_data)
goto e_free_hdr; goto e_free_hdr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment