]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
vringh: don't use vringh_kiov_advance() in vringh_iov_xfer()
authorStefano Garzarella <sgarzare@redhat.com>
Thu, 26 Oct 2023 19:54:51 +0000 (15:54 -0400)
committerStefan Bader <stefan.bader@canonical.com>
Mon, 30 Oct 2023 11:00:34 +0000 (12:00 +0100)
In the while loop of vringh_iov_xfer(), `partlen` could be 0 if one of
the `iov` has 0 lenght.
In this case, we should skip the iov and go to the next one.
But calling vringh_kiov_advance() with 0 lenght does not cause the
advancement, since it returns immediately if asked to advance by 0 bytes.

Let's restore the code that was there before commit b8c06ad4d67d
("vringh: implement vringh_kiov_advance()"), avoiding using
vringh_kiov_advance().

Fixes: b8c06ad4d67d ("vringh: implement vringh_kiov_advance()")
Cc: stable@vger.kernel.org
Reported-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 7aed44babc7f97e82b38e9a68515e699692cc100)
CVE-2023-5158
Signed-off-by: Yuxuan Luo <yuxuan.luo@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
drivers/vhost/vringh.c

index 33eb941fcf154631eb32b01b42ef8ba80dc4ef34..10bfc5f1c50d5d66aca9c2aafe8be07a1ea69a6e 100644 (file)
@@ -123,8 +123,18 @@ static inline ssize_t vringh_iov_xfer(struct vringh *vrh,
                done += partlen;
                len -= partlen;
                ptr += partlen;
+               iov->consumed += partlen;
+               iov->iov[iov->i].iov_len -= partlen;
+               iov->iov[iov->i].iov_base += partlen;
 
-               vringh_kiov_advance(iov, partlen);
+               if (!iov->iov[iov->i].iov_len) {
+                       /* Fix up old iov element then increment. */
+                       iov->iov[iov->i].iov_len = iov->consumed;
+                       iov->iov[iov->i].iov_base -= iov->consumed;
+
+                       iov->consumed = 0;
+                       iov->i++;
+               }
        }
        return done;
 }