]> git.baikalelectronics.ru Git - kernel.git/commit
KVM: Don't null dereference ops->destroy
authorAlexey Kardashevskiy <aik@ozlabs.ru>
Wed, 1 Jun 2022 01:43:28 +0000 (03:43 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 11 Aug 2022 10:57:52 +0000 (12:57 +0200)
commite1d0fe73829757c0089942420e8aeb31075c2849
treedea1fa8628e2552eb57946fed6774f330e6c6f29
parent975e898dddeccf0f520358e20bcc652e6c34e676
KVM: Don't null dereference ops->destroy

[ Upstream commit 5a77028f4b4fec24de8a3f82e1b362f7ba38a97a ]

A KVM device cleanup happens in either of two callbacks:
1) destroy() which is called when the VM is being destroyed;
2) release() which is called when a device fd is closed.

Most KVM devices use 1) but Book3s's interrupt controller KVM devices
(XICS, XIVE, XIVE-native) use 2) as they need to close and reopen during
the machine execution. The error handling in kvm_ioctl_create_device()
assumes destroy() is always defined which leads to NULL dereference as
discovered by Syzkaller.

This adds a checks for destroy!=NULL and adds a missing release().

This is not changing kvm_destroy_devices() as devices with defined
release() should have been removed from the KVM devices list by then.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
virt/kvm/kvm_main.c