]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
5.15-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 27 Mar 2024 14:59:55 +0000 (15:59 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 27 Mar 2024 14:59:55 +0000 (15:59 +0100)
added patches:
kvm-svm-flush-pages-under-kvm-lock-to-fix-uaf-in-svm_register_enc_region.patch

queue-5.15/kvm-svm-flush-pages-under-kvm-lock-to-fix-uaf-in-svm_register_enc_region.patch [new file with mode: 0644]
queue-5.15/series

diff --git a/queue-5.15/kvm-svm-flush-pages-under-kvm-lock-to-fix-uaf-in-svm_register_enc_region.patch b/queue-5.15/kvm-svm-flush-pages-under-kvm-lock-to-fix-uaf-in-svm_register_enc_region.patch
new file mode 100644 (file)
index 0000000..ec2eff3
--- /dev/null
@@ -0,0 +1,67 @@
+From 5ef1d8c1ddbf696e47b226e11888eaf8d9e8e807 Mon Sep 17 00:00:00 2001
+From: Sean Christopherson <seanjc@google.com>
+Date: Fri, 16 Feb 2024 17:34:30 -0800
+Subject: KVM: SVM: Flush pages under kvm->lock to fix UAF in svm_register_enc_region()
+
+From: Sean Christopherson <seanjc@google.com>
+
+commit 5ef1d8c1ddbf696e47b226e11888eaf8d9e8e807 upstream.
+
+Do the cache flush of converted pages in svm_register_enc_region() before
+dropping kvm->lock to fix use-after-free issues where region and/or its
+array of pages could be freed by a different task, e.g. if userspace has
+__unregister_enc_region_locked() already queued up for the region.
+
+Note, the "obvious" alternative of using local variables doesn't fully
+resolve the bug, as region->pages is also dynamically allocated.  I.e. the
+region structure itself would be fine, but region->pages could be freed.
+
+Flushing multiple pages under kvm->lock is unfortunate, but the entire
+flow is a rare slow path, and the manual flush is only needed on CPUs that
+lack coherency for encrypted memory.
+
+Fixes: 19a23da53932 ("Fix unsynchronized access to sev members through svm_register_enc_region")
+Reported-by: Gabe Kirkpatrick <gkirkpatrick@google.com>
+Cc: Josh Eads <josheads@google.com>
+Cc: Peter Gonda <pgonda@google.com>
+Cc: stable@vger.kernel.org
+Signed-off-by: Sean Christopherson <seanjc@google.com>
+Message-Id: <20240217013430.2079561-1-seanjc@google.com>
+Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ arch/x86/kvm/svm/sev.c |   16 +++++++++-------
+ 1 file changed, 9 insertions(+), 7 deletions(-)
+
+--- a/arch/x86/kvm/svm/sev.c
++++ b/arch/x86/kvm/svm/sev.c
+@@ -1662,20 +1662,22 @@ int svm_register_enc_region(struct kvm *
+               goto e_free;
+       }
+-      region->uaddr = range->addr;
+-      region->size = range->size;
+-
+-      list_add_tail(&region->list, &sev->regions_list);
+-      mutex_unlock(&kvm->lock);
+-
+       /*
+        * The guest may change the memory encryption attribute from C=0 -> C=1
+        * or vice versa for this memory range. Lets make sure caches are
+        * flushed to ensure that guest data gets written into memory with
+-       * correct C-bit.
++       * correct C-bit.  Note, this must be done before dropping kvm->lock,
++       * as region and its array of pages can be freed by a different task
++       * once kvm->lock is released.
+        */
+       sev_clflush_pages(region->pages, region->npages);
++      region->uaddr = range->addr;
++      region->size = range->size;
++
++      list_add_tail(&region->list, &sev->regions_list);
++      mutex_unlock(&kvm->lock);
++
+       return ret;
+ e_free:
index 4c2c3ac6b461da3642f5b52d6ffd798bc70cba37..5f3291382648b8345358817b6576fa48a8fa043a 100644 (file)
@@ -122,3 +122,4 @@ netfilter-nf_tables-disallow-anonymous-set-with-timeout-flag.patch
 netfilter-nf_tables-reject-constant-set-with-timeout.patch
 drivers-hv-vmbus-calculate-ring-buffer-size-for-more-efficient-use-of-memory.patch
 xfrm-avoid-clang-fortify-warning-in-copy_to_user_tmpl.patch
+kvm-svm-flush-pages-under-kvm-lock-to-fix-uaf-in-svm_register_enc_region.patch