Skip to contentSkip to conversation

vhost: fix end of range for access_ok

PATCH In review Michael S. Tsirkin 2 participants 2 messages Aug 21, 2017 – Aug 22, 2017

Subsystems (5)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH 1/1 vhost: fix end of range for access_ok

During access_ok checks, addr increases as we iterate over the data structure, thus addr + len - 1 will point beyond the end of region we are translating. Harmless since we then verify that the region covers addr, but let's not waste cpu cycles.

---

Lightly tested, would appreciate an ack from reporter.

 drivers/vhost/vhost.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vhost/vhost.c +2 -2
index e4613a3..ecd70e4 100644
@@ -1176,7 +1176,7 @@ static int iotlb_access_ok(struct vhost_virtqueue *vq,
 {
 	const struct vhost_umem_node *node;
 	struct vhost_umem *umem = vq->iotlb;
-	u64 s = 0, size, orig_addr = addr;
+	u64 s = 0, size, orig_addr = addr, last = addr + len - 1;
 
 	if (vhost_vq_meta_fetch(vq, addr, len, type))
 		return true;
@@ -1184,7 +1184,7 @@ static int iotlb_access_ok(struct vhost_virtqueue *vq,
 	while (len > s) {
 		node = vhost_umem_interval_tree_iter_first(&umem->umem_tree,
 							   addr,
-							   addr + len - 1);
+							   last);
 		if (node == NULL || node->start > addr) {
 			vhost_iotlb_miss(vq, addr, access);
 			return false;
Signature · 1 line
MST
Acked-by on v1 1/1
#1 lore raw
Quoted 28 lines · Michael S. Tsirkin

During access_ok checks, addr increases as we iterate over the data structure, thus addr + len - 1 will point beyond the end of region we are translating.  Harmless since we then verify that the region covers addr, but let's not waste cpu cycles.

---

Lightly tested, would appreciate an ack from reporter.

 drivers/vhost/vhost.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vhost/vhost.c +1 -1
index e4613a3..ecd70e4 100644
@@ -1176,7 +1176,7 @@ static int iotlb_access_ok(struct vhost_virtqueue *vq,
  {
  	const struct vhost_umem_node *node;
  	struct vhost_umem *umem = vq->iotlb;
-	u64 s = 0, size, orig_addr = addr;
+	u64 s = 0, size, orig_addr = addr, last = addr + len - 1;


  if (vhost_vq_meta_fetch(vq, addr, len, type)) return true;

drivers/vhost/vhost.c static int iotlb_access_ok(struct vhost_virtqueue *vq, · line 1190

Quoted 8 lines
drivers/vhost/vhost.c +1 -1
@@ -1184,7 +1184,7 @@ static int iotlb_access_ok(struct vhost_virtqueue *vq,
  	while (len > s) {
  		node = vhost_umem_interval_tree_iter_first(&umem->umem_tree,
  							   addr,
-							   addr + len - 1);
+							   last);
  		if (node == NULL || node->start > addr) {
  			vhost_iotlb_miss(vq, addr, access);
  			return false;

Michael, Thank you for this one.

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization