kvm: x86: svm: Fix NULL pointer dereference when AVIC not enabled
PATCH 1/1 kvm: x86: svm: Fix NULL pointer dereference when AVIC not enabled
Launching VM w/ AVIC disabled together with pass-through device results in NULL pointer dereference bug with the following call trace.
RIP: 0010:svm_refresh_apicv_exec_ctrl+0x17e/0x1a0 [kvm_amd]
Call Trace:
kvm_vcpu_update_apicv+0x44/0x60 [kvm]
kvm_arch_vcpu_ioctl_run+0x3f4/0x1c80 [kvm]
kvm_vcpu_ioctl+0x3d8/0x650 [kvm]
do_vfs_ioctl+0xaa/0x660
? tomoyo_file_ioctl+0x19/0x20
ksys_ioctl+0x67/0x90
__x64_sys_ioctl+0x1a/0x20
do_syscall_64+0x57/0x190
entry_SYSCALL_64_after_hwframe+0x44/0xa9Investigation shows that this is due to the uninitialized usage of struct vapu_svm.ir_list in the svm_set_pi_irte_mode(), which is called from svm_refresh_apicv_exec_ctrl().
The ir_list is initialized only if AVIC is enabled. So, fixes by adding a check if AVIC is enabled in the svm_refresh_apicv_exec_ctrl().
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=206579
--- arch/x86/kvm/svm.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/kvm/svm.c +3 -0
@@ -5222,6 +5222,9 @@ static void svm_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu)struct vmcb *vmcb = svm->vmcb;bool activated =kvm_vcpu_apicv_active (vcpu); +if (!avic) +return ; +if (activated) {/** * During AVIC temporary deactivation, guest could update
Signature · 1 line
1.8.3.1
Quoted 23 lines · On Fri, 21 Feb 2020 08:52:17 -0600 Suravee Suthikulpanit…
Launching VM w/ AVIC disabled together with pass-through device results in NULL pointer dereference bug with the following call trace.
RIP: 0010:svm_refresh_apicv_exec_ctrl+0x17e/0x1a0 [kvm_amd] Call Trace: kvm_vcpu_update_apicv+0x44/0x60 [kvm] kvm_arch_vcpu_ioctl_run+0x3f4/0x1c80 [kvm] kvm_vcpu_ioctl+0x3d8/0x650 [kvm] do_vfs_ioctl+0xaa/0x660 ? tomoyo_file_ioctl+0x19/0x20 ksys_ioctl+0x67/0x90 __x64_sys_ioctl+0x1a/0x20 do_syscall_64+0x57/0x190 entry_SYSCALL_64_after_hwframe+0x44/0xa9Investigation shows that this is due to the uninitialized usage of struct vapu_svm.ir_list in the
svm_set_pi_irte_mode(), which is called fromsvm_refresh_apicv_exec_ctrl().The
ir_listis initialized only if AVIC is enabled. So, fixes by adding a check if AVIC is enabled in thesvm_refresh_apicv_exec_ctrl().
Quoted 7 lines
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=206579
Fixes 8937d762396d ("kvm: x86: svm: Add support to (de)activate posted interrupts.")Signed-off-by Suravee Suthikulpanit <[email protected]>Cc Alex Williamson <[email protected]>--- arch/x86/kvm/svm.c | 3 +++ 1 file changed, 3 insertions(+)
Works for me, thanks Suravee!
Quoted 15 lines
arch/x86/kvm/svm.c +3
-0@@ -5222,6 +5222,9 @@ static void svm_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu)struct vmcb *vmcb = svm->vmcb;bool activated =kvm_vcpu_apicv_active (vcpu); +if (!avic) +return ; +if (activated) {/** * During AVIC temporary deactivation, guest could update
Paolo Bonzini
maintainerQuoted 47 lines · Alex Williamson
Quoted 23 lines · On Fri, 21 Feb 2020 08:52:17 -0600 Suravee Suthikulpanit…
Launching VM w/ AVIC disabled together with pass-through device results in NULL pointer dereference bug with the following call trace.
RIP: 0010:svm_refresh_apicv_exec_ctrl+0x17e/0x1a0 [kvm_amd] Call Trace: kvm_vcpu_update_apicv+0x44/0x60 [kvm] kvm_arch_vcpu_ioctl_run+0x3f4/0x1c80 [kvm] kvm_vcpu_ioctl+0x3d8/0x650 [kvm] do_vfs_ioctl+0xaa/0x660 ? tomoyo_file_ioctl+0x19/0x20 ksys_ioctl+0x67/0x90 __x64_sys_ioctl+0x1a/0x20 do_syscall_64+0x57/0x190 entry_SYSCALL_64_after_hwframe+0x44/0xa9Investigation shows that this is due to the uninitialized usage of struct vapu_svm.ir_list in the
svm_set_pi_irte_mode(), which is called fromsvm_refresh_apicv_exec_ctrl().The
ir_listis initialized only if AVIC is enabled. So, fixes by adding a check if AVIC is enabled in thesvm_refresh_apicv_exec_ctrl().Quoted 7 lines
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=206579
Fixes 8937d762396d ("kvm: x86: svm: Add support to (de)activate posted interrupts.")Signed-off-by Suravee Suthikulpanit <[email protected]>Cc Alex Williamson <[email protected]>--- arch/x86/kvm/svm.c | 3 +++ 1 file changed, 3 insertions(+)Works for me, thanks Suravee!
Tested-by Alex Williamson <[email protected]>Quoted 9 lines
arch/x86/kvm/svm.c +0
-0@@ -5222,6 +5222,9 @@ static void svm_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu)struct vmcb *vmcb = svm->vmcb;bool activated =kvm_vcpu_apicv_active (vcpu);
Quoted 7 lines
arch/x86/kvm/svm.c static void svm_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu) · line 5230
Quoted 6 lines
arch/x86/kvm/svm.c +3
-0+if (!avic) +return ; +if (activated) {/** * During AVIC temporary deactivation, guest could update
Thanks to both of you. I'll get it to Linus next Monday.
Paolo