From: Jason Wang Date: Thu, 13 Dec 2018 02:53:37 +0000 (+0800) Subject: vhost: make sure used idx is seen before log in vhost_add_used_n() X-Git-Tag: v4.14.92~76 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=2510d91bdafe6ebe95864290866bb6c3e714b6e8;p=users%2Fjedix%2Flinux-maple.git vhost: make sure used idx is seen before log in vhost_add_used_n() [ Upstream commit 841df922417eb82c835e93d4b93eb6a68c99d599 ] We miss a write barrier that guarantees used idx is updated and seen before log. This will let userspace sync and copy used ring before used idx is update. Fix this by adding a barrier before log_write(). Fixes: 8dd014adfea6f ("vhost-net: mergeable buffers support") Acked-by: Michael S. Tsirkin Signed-off-by: Jason Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index ffdd4e937d1d8..97518685ab58a 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2231,6 +2231,8 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads, return -EFAULT; } if (unlikely(vq->log_used)) { + /* Make sure used idx is seen before log. */ + smp_wmb(); /* Log used index update. */ log_write(vq->log_base, vq->log_addr + offsetof(struct vring_used, idx),