From 5b9d93ad5feee7a1e9e6c4486c493eaa914c3239 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 9 Aug 2021 12:55:59 +0200 Subject: [PATCH] 4.19-stable patches added patches: kvm-x86-accept-userspace-interrupt-only-if-no-event-is-injected.patch kvm-x86-mmu-fix-per-cpu-counter-corruption-on-32-bit-builds.patch pcmcia-i82092-fix-a-null-pointer-dereference-bug.patch --- ...terrupt-only-if-no-event-is-injected.patch | 57 +++++++++++++++++++ ...-counter-corruption-on-32-bit-builds.patch | 54 ++++++++++++++++++ ...2-fix-a-null-pointer-dereference-bug.patch | 32 +++++++++++ queue-4.19/series | 3 + 4 files changed, 146 insertions(+) create mode 100644 queue-4.19/kvm-x86-accept-userspace-interrupt-only-if-no-event-is-injected.patch create mode 100644 queue-4.19/kvm-x86-mmu-fix-per-cpu-counter-corruption-on-32-bit-builds.patch create mode 100644 queue-4.19/pcmcia-i82092-fix-a-null-pointer-dereference-bug.patch diff --git a/queue-4.19/kvm-x86-accept-userspace-interrupt-only-if-no-event-is-injected.patch b/queue-4.19/kvm-x86-accept-userspace-interrupt-only-if-no-event-is-injected.patch new file mode 100644 index 00000000000..0a634f1cfa7 --- /dev/null +++ b/queue-4.19/kvm-x86-accept-userspace-interrupt-only-if-no-event-is-injected.patch @@ -0,0 +1,57 @@ +From fa7a549d321a4189677b0cea86e58d9db7977f7b Mon Sep 17 00:00:00 2001 +From: Paolo Bonzini +Date: Wed, 14 Jul 2021 17:37:49 -0400 +Subject: KVM: x86: accept userspace interrupt only if no event is injected + +From: Paolo Bonzini + +commit fa7a549d321a4189677b0cea86e58d9db7977f7b upstream. + +Once an exception has been injected, any side effects related to +the exception (such as setting CR2 or DR6) have been taked place. +Therefore, once KVM sets the VM-entry interruption information +field or the AMD EVENTINJ field, the next VM-entry must deliver that +exception. + +Pending interrupts are processed after injected exceptions, so +in theory it would not be a problem to use KVM_INTERRUPT when +an injected exception is present. However, DOSEMU is using +run->ready_for_interrupt_injection to detect interrupt windows +and then using KVM_SET_SREGS/KVM_SET_REGS to inject the +interrupt manually. For this to work, the interrupt window +must be delayed after the completion of the previous event +injection. + +Cc: stable@vger.kernel.org +Reported-by: Stas Sergeev +Tested-by: Stas Sergeev +Fixes: 71cc849b7093 ("KVM: x86: Fix split-irqchip vs interrupt injection window request") +Reviewed-by: Sean Christopherson +Signed-off-by: Paolo Bonzini +Signed-off-by: Greg Kroah-Hartman +--- + arch/x86/kvm/x86.c | 13 +++++++++++-- + 1 file changed, 11 insertions(+), 2 deletions(-) + +--- a/arch/x86/kvm/x86.c ++++ b/arch/x86/kvm/x86.c +@@ -3366,8 +3366,17 @@ static int kvm_cpu_accept_dm_intr(struct + + static int kvm_vcpu_ready_for_interrupt_injection(struct kvm_vcpu *vcpu) + { +- return kvm_arch_interrupt_allowed(vcpu) && +- kvm_cpu_accept_dm_intr(vcpu); ++ /* ++ * Do not cause an interrupt window exit if an exception ++ * is pending or an event needs reinjection; userspace ++ * might want to inject the interrupt manually using KVM_SET_REGS ++ * or KVM_SET_SREGS. For that to work, we must be at an ++ * instruction boundary and with no events half-injected. ++ */ ++ return (kvm_arch_interrupt_allowed(vcpu) && ++ kvm_cpu_accept_dm_intr(vcpu) && ++ !kvm_event_needs_reinjection(vcpu) && ++ !vcpu->arch.exception.pending); + } + + static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, diff --git a/queue-4.19/kvm-x86-mmu-fix-per-cpu-counter-corruption-on-32-bit-builds.patch b/queue-4.19/kvm-x86-mmu-fix-per-cpu-counter-corruption-on-32-bit-builds.patch new file mode 100644 index 00000000000..9b6c6ba7aed --- /dev/null +++ b/queue-4.19/kvm-x86-mmu-fix-per-cpu-counter-corruption-on-32-bit-builds.patch @@ -0,0 +1,54 @@ +From d5aaad6f83420efb8357ac8e11c868708b22d0a9 Mon Sep 17 00:00:00 2001 +From: Sean Christopherson +Date: Wed, 4 Aug 2021 14:46:09 -0700 +Subject: KVM: x86/mmu: Fix per-cpu counter corruption on 32-bit builds + +From: Sean Christopherson + +commit d5aaad6f83420efb8357ac8e11c868708b22d0a9 upstream. + +Take a signed 'long' instead of an 'unsigned long' for the number of +pages to add/subtract to the total number of pages used by the MMU. This +fixes a zero-extension bug on 32-bit kernels that effectively corrupts +the per-cpu counter used by the shrinker. + +Per-cpu counters take a signed 64-bit value on both 32-bit and 64-bit +kernels, whereas kvm_mod_used_mmu_pages() takes an unsigned long and thus +an unsigned 32-bit value on 32-bit kernels. As a result, the value used +to adjust the per-cpu counter is zero-extended (unsigned -> signed), not +sign-extended (signed -> signed), and so KVM's intended -1 gets morphed to +4294967295 and effectively corrupts the counter. + +This was found by a staggering amount of sheer dumb luck when running +kvm-unit-tests on a 32-bit KVM build. The shrinker just happened to kick +in while running tests and do_shrink_slab() logged an error about trying +to free a negative number of objects. The truly lucky part is that the +kernel just happened to be a slightly stale build, as the shrinker no +longer yells about negative objects as of commit 18bb473e5031 ("mm: +vmscan: shrink deferred objects proportional to priority"). + + vmscan: shrink_slab: mmu_shrink_scan+0x0/0x210 [kvm] negative objects to delete nr=-858993460 + +Fixes: bc8a3d8925a8 ("kvm: mmu: Fix overflow on kvm mmu page limit calculation") +Cc: stable@vger.kernel.org +Cc: Ben Gardon +Signed-off-by: Sean Christopherson +Message-Id: <20210804214609.1096003-1-seanjc@google.com> +Reviewed-by: Jim Mattson +Signed-off-by: Paolo Bonzini +Signed-off-by: Greg Kroah-Hartman +--- + arch/x86/kvm/mmu.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/arch/x86/kvm/mmu.c ++++ b/arch/x86/kvm/mmu.c +@@ -2042,7 +2042,7 @@ static int is_empty_shadow_page(u64 *spt + * aggregate version in order to make the slab shrinker + * faster + */ +-static inline void kvm_mod_used_mmu_pages(struct kvm *kvm, unsigned long nr) ++static inline void kvm_mod_used_mmu_pages(struct kvm *kvm, long nr) + { + kvm->arch.n_used_mmu_pages += nr; + percpu_counter_add(&kvm_total_used_mmu_pages, nr); diff --git a/queue-4.19/pcmcia-i82092-fix-a-null-pointer-dereference-bug.patch b/queue-4.19/pcmcia-i82092-fix-a-null-pointer-dereference-bug.patch new file mode 100644 index 00000000000..43f86bcf838 --- /dev/null +++ b/queue-4.19/pcmcia-i82092-fix-a-null-pointer-dereference-bug.patch @@ -0,0 +1,32 @@ +From e39cdacf2f664b09029e7c1eb354c91a20c367af Mon Sep 17 00:00:00 2001 +From: Zheyu Ma +Date: Tue, 22 Jun 2021 07:11:31 +0000 +Subject: pcmcia: i82092: fix a null pointer dereference bug + +From: Zheyu Ma + +commit e39cdacf2f664b09029e7c1eb354c91a20c367af upstream. + +During the driver loading process, the 'dev' field was not assigned, but +the 'dev' field was referenced in the subsequent 'i82092aa_set_mem_map' +function. + +Signed-off-by: Zheyu Ma +CC: +[linux@dominikbrodowski.net: shorten commit message, add Cc to stable] +Signed-off-by: Dominik Brodowski +Signed-off-by: Greg Kroah-Hartman +--- + drivers/pcmcia/i82092.c | 1 + + 1 file changed, 1 insertion(+) + +--- a/drivers/pcmcia/i82092.c ++++ b/drivers/pcmcia/i82092.c +@@ -105,6 +105,7 @@ static int i82092aa_pci_probe(struct pci + for (i = 0;i