Skip to content

Commit d22d247

Browse files
ashkalrabonzini
authored andcommitted
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: Andy Nguyen <[email protected]> Suggested-by: David Rientjes <[email protected]> Suggested-by: Peter Gonda <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Fixes: eaf7826 ("KVM: SVM: Move SEV code to separate file") Fixes: 2c07ded ("KVM: SVM: add support for SEV attestation command") Fixes: 4cfdd47 ("KVM: SVM: Add KVM_SEV SEND_START command") Fixes: d3d1af8 ("KVM: SVM: Add KVM_SEND_UPDATE_DATA command") Fixes: eba04b2 ("KVM: x86: Account a variety of miscellaneous allocations") Signed-off-by: Ashish Kalra <[email protected]> Reviewed-by: Peter Gonda <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent d187ba5 commit d22d247

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

arch/x86/kvm/svm/sev.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ static int sev_launch_measure(struct kvm *kvm, struct kvm_sev_cmd *argp)
688688
if (params.len > SEV_FW_BLOB_MAX_SIZE)
689689
return -EINVAL;
690690

691-
blob = kmalloc(params.len, GFP_KERNEL_ACCOUNT);
691+
blob = kzalloc(params.len, GFP_KERNEL_ACCOUNT);
692692
if (!blob)
693693
return -ENOMEM;
694694

@@ -808,7 +808,7 @@ static int __sev_dbg_decrypt_user(struct kvm *kvm, unsigned long paddr,
808808
if (!IS_ALIGNED(dst_paddr, 16) ||
809809
!IS_ALIGNED(paddr, 16) ||
810810
!IS_ALIGNED(size, 16)) {
811-
tpage = (void *)alloc_page(GFP_KERNEL);
811+
tpage = (void *)alloc_page(GFP_KERNEL | __GFP_ZERO);
812812
if (!tpage)
813813
return -ENOMEM;
814814

@@ -1094,7 +1094,7 @@ static int sev_get_attestation_report(struct kvm *kvm, struct kvm_sev_cmd *argp)
10941094
if (params.len > SEV_FW_BLOB_MAX_SIZE)
10951095
return -EINVAL;
10961096

1097-
blob = kmalloc(params.len, GFP_KERNEL_ACCOUNT);
1097+
blob = kzalloc(params.len, GFP_KERNEL_ACCOUNT);
10981098
if (!blob)
10991099
return -ENOMEM;
11001100

@@ -1176,7 +1176,7 @@ static int sev_send_start(struct kvm *kvm, struct kvm_sev_cmd *argp)
11761176
return -EINVAL;
11771177

11781178
/* allocate the memory to hold the session data blob */
1179-
session_data = kmalloc(params.session_len, GFP_KERNEL_ACCOUNT);
1179+
session_data = kzalloc(params.session_len, GFP_KERNEL_ACCOUNT);
11801180
if (!session_data)
11811181
return -ENOMEM;
11821182

@@ -1300,11 +1300,11 @@ static int sev_send_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp)
13001300

13011301
/* allocate memory for header and transport buffer */
13021302
ret = -ENOMEM;
1303-
hdr = kmalloc(params.hdr_len, GFP_KERNEL_ACCOUNT);
1303+
hdr = kzalloc(params.hdr_len, GFP_KERNEL_ACCOUNT);
13041304
if (!hdr)
13051305
goto e_unpin;
13061306

1307-
trans_data = kmalloc(params.trans_len, GFP_KERNEL_ACCOUNT);
1307+
trans_data = kzalloc(params.trans_len, GFP_KERNEL_ACCOUNT);
13081308
if (!trans_data)
13091309
goto e_free_hdr;
13101310

0 commit comments

Comments
 (0)