Skip to contentSkip to conversation

KVM: SVM: Fix offset computation bug in __sev_dbg_decrypt().

PATCH In review Ashish Kalra 2 participants 2 messages Nov 10, 2020 – Nov 16, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: SVM: Fix offset computation bug in __sev_dbg_decrypt().

From: Ashish Kalra <[email protected]>

Fix offset computation in __sev_dbg_decrypt() to include the source paddr before it is rounded down to be aligned to 16 bytes as required by SEV API. This fixes incorrect guest memory dumps observed when using qemu monitor.

---
 arch/x86/kvm/svm/sev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/svm/sev.c +1 -1
index c0b14106258a..566f4d18185b 100644
@@ -642,8 +642,8 @@ static int __sev_dbg_decrypt(struct kvm *kvm, unsigned long src_paddr,
 	 * Its safe to read more than we are asked, caller should ensure that
 	 * destination has enough space.
 	 */
-	src_paddr = round_down(src_paddr, 16);
 	offset = src_paddr & 15;
+	src_paddr = round_down(src_paddr, 16);
 	sz = round_up(sz + offset, 16);
 
 	return __sev_issue_dbg_cmd(kvm, src_paddr, dst_paddr, sz, err, false);
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 18 lines · Ashish Kalra

From: Ashish Kalra <[email protected]>

Fix offset computation in __sev_dbg_decrypt() to include the source paddr before it is rounded down to be aligned to 16 bytes as required by SEV API. This fixes incorrect guest memory dumps observed when using qemu monitor.

---
  arch/x86/kvm/svm/sev.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/svm/sev.c +0 -0
index c0b14106258a..566f4d18185b 100644

arch/x86/kvm/svm/sev.c static int __sev_dbg_decrypt(struct kvm *kvm, unsigned long src_paddr, · line 649

Quoted 9 lines
arch/x86/kvm/svm/sev.c +1 -1
@@ -642,8 +642,8 @@ static int __sev_dbg_decrypt(struct kvm *kvm, unsigned long src_paddr,
  	 * Its safe to read more than we are asked, caller should ensure that
  	 * destination has enough space.
  	 */
-	src_paddr = round_down(src_paddr, 16);
  	offset = src_paddr & 15;
+	src_paddr = round_down(src_paddr, 16);
  	sz = round_up(sz + offset, 16);
 
  	return __sev_issue_dbg_cmd(kvm, src_paddr, dst_paddr, sz, err, false);

I just missed it. Queued now, thanks.

Paolo