Skip to contentSkip to conversation

vhost: fix length for cross region descriptor

PATCH Applied Michael S. Tsirkin 3 participants 3 messages Nov 26, 2012 – Nov 28, 2012

Subsystems (3)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH 1/1 vhost: fix length for cross region descriptor

If a single descriptor crosses a region, the second chunk length should be decremented by size translated so far, instead it includes the full descriptor length.

---
 drivers/vhost/vhost.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/vhost.c +1 -1
index ef8f598..5a3d0f1 100644
@@ -1049,7 +1049,7 @@ static int translate_desc(struct vhost_dev *dev, u64 addr, u32 len,
 		}
 		_iov = iov + ret;
 		size = reg->memory_size - addr + reg->guest_phys_addr;
-		_iov->iov_len = min((u64)len, size);
+		_iov->iov_len = min((u64)len - s, size);
 		_iov->iov_base = (void __user *)(unsigned long)
 			(reg->userspace_addr + addr - reg->guest_phys_addr);
 		s += size;
Signature · 1 line
MST
Acked-by on v1 1/1
#1 lore raw
Quoted 15 lines · Michael S. Tsirkin

If a single descriptor crosses a region, the second chunk length should be decremented by size translated so far, instead it includes the full descriptor length.

---
  drivers/vhost/vhost.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/vhost.c +0 -0
index ef8f598..5a3d0f1 100644

drivers/vhost/vhost.c static int translate_desc(struct vhost_dev *dev, u64 addr, u32 len, · line 1055

Quoted 8 lines
drivers/vhost/vhost.c +1 -1
@@ -1049,7 +1049,7 @@ static int translate_desc(struct vhost_dev *dev, u64 addr, u32 len,
  		}
  		_iov = iov + ret;
  		size = reg->memory_size - addr + reg->guest_phys_addr;
-		_iov->iov_len = min((u64)len, size);
+		_iov->iov_len = min((u64)len - s, size);
  		_iov->iov_base = (void __user *)(unsigned long)
  			(reg->userspace_addr + addr - reg->guest_phys_addr);
  		s += size;