]> git.dujemihanovic.xyz Git - linux.git/commitdiff
KVM: downgrade two BUG_ONs to WARN_ON_ONCE
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 22 Nov 2021 23:24:01 +0000 (18:24 -0500)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 26 Nov 2021 11:43:28 +0000 (06:43 -0500)
This is not an unrecoverable situation.  Users of kvm_read_guest_offset_cached
and kvm_write_guest_offset_cached must expect the read/write to fail, and
therefore it is possible to just return early with an error value.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
virt/kvm/kvm_main.c

index 6c5083f2eb505d15a453b7e52d200055b91b7e65..72c4e6b393896aa9f4a7fa3531151ee8df3d1268 100644 (file)
@@ -2931,7 +2931,8 @@ int kvm_write_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
        int r;
        gpa_t gpa = ghc->gpa + offset;
 
-       BUG_ON(len + offset > ghc->len);
+       if (WARN_ON_ONCE(len + offset > ghc->len))
+               return -EINVAL;
 
        if (slots->generation != ghc->generation) {
                if (__kvm_gfn_to_hva_cache_init(slots, ghc, ghc->gpa, ghc->len))
@@ -2968,7 +2969,8 @@ int kvm_read_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
        int r;
        gpa_t gpa = ghc->gpa + offset;
 
-       BUG_ON(len + offset > ghc->len);
+       if (WARN_ON_ONCE(len + offset > ghc->len))
+               return -EINVAL;
 
        if (slots->generation != ghc->generation) {
                if (__kvm_gfn_to_hva_cache_init(slots, ghc, ghc->gpa, ghc->len))