Skip to contentSkip to conversation

KVM: Fix off-by-one error when querying attributes in xarray

PATCH In review Sean Christopherson 2 participants 2 messages Oct 23, 2023 – Oct 24, 2023 KVM

lore
Share & tools
lore

Sean Christopherson

author reviewer
#0 lore raw

PATCH 1/1 KVM: Fix off-by-one error when querying attributes in xarray

Subtract -1 from kvm_range_has_memory_attributes()'s @end when using xas_find(), as "end" is exclusive whereas xas_find() takes an inclusive "max" as the maximal index to find/return.

---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +1 -1
index 959e866c84f0..12458959dd25 100644
@@ -2447,7 +2447,7 @@ bool kvm_range_has_memory_attributes(struct kvm *kvm, gfn_t start, gfn_t end,
 	rcu_read_lock();
 
 	if (!attrs) {
-		has_attrs = !xas_find(&xas, end);
+		has_attrs = !xas_find(&xas, end - 1);
 		goto out;
 	}
 

base-commit: 911b515af3ec5f53992b9cc162cf7d3893c2fbe2

Signature · 1 line
2.42.0.758.gaed0368e0e-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Sean Christopherson

Subtract -1 from kvm_range_has_memory_attributes()'s @end when using xas_find(), as "end" is exclusive whereas xas_find() takes an inclusive "max" as the maximal index to find/return.

Quoted 19 lines
---
  virt/kvm/kvm_main.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +1 -1
index 959e866c84f0..12458959dd25 100644
@@ -2447,7 +2447,7 @@ bool kvm_range_has_memory_attributes(struct kvm *kvm, gfn_t start, gfn_t end,
  	rcu_read_lock();
 
  	if (!attrs) {
-		has_attrs = !xas_find(&xas, end);
+		has_attrs = !xas_find(&xas, end - 1);
  		goto out;
  	}
 

base-commit: 911b515af3ec5f53992b9cc162cf7d3893c2fbe2