aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2014-03-27 06:00:26 -0400
committerDavid S. Miller <davem@davemloft.net>2014-03-28 16:07:31 -0400
commitd8316f3991d207fe32881a9ac20241be8fa2bad0 (patch)
tree76802d9368e0115d9c53ac7cf0477b53011a4486
parent05efa8c943b1d5d90fa8c8147571837573338bb6 (diff)
vhost: fix total length when packets are too short
When mergeable buffers are disabled, and the incoming packet is too large for the rx buffer, get_rx_bufs returns success. This was intentional in order for make recvmsg truncate the packet and then handle_rx would detect err != sock_len and drop it. Unfortunately we pass the original sock_len to recvmsg - which means we use parts of iov not fully validated. Fix this up by detecting this overrun and doing packet drop immediately. CVE-2014-0077 Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/vhost/net.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index a0fa5de210cf..026be580d318 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -532,6 +532,12 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
532 *iovcount = seg; 532 *iovcount = seg;
533 if (unlikely(log)) 533 if (unlikely(log))
534 *log_num = nlogs; 534 *log_num = nlogs;
535
536 /* Detect overrun */
537 if (unlikely(datalen > 0)) {
538 r = UIO_MAXIOV + 1;
539 goto err;
540 }
535 return headcount; 541 return headcount;
536err: 542err:
537 vhost_discard_vq_desc(vq, headcount); 543 vhost_discard_vq_desc(vq, headcount);
@@ -587,6 +593,14 @@ static void handle_rx(struct vhost_net *net)
587 /* On error, stop handling until the next kick. */ 593 /* On error, stop handling until the next kick. */
588 if (unlikely(headcount < 0)) 594 if (unlikely(headcount < 0))
589 break; 595 break;
596 /* On overrun, truncate and discard */
597 if (unlikely(headcount > UIO_MAXIOV)) {
598 msg.msg_iovlen = 1;
599 err = sock->ops->recvmsg(NULL, sock, &msg,
600 1, MSG_DONTWAIT | MSG_TRUNC);
601 pr_debug("Discarded rx packet: len %zd\n", sock_len);
602 continue;
603 }
590 /* OK, now we need to know about added descriptors. */ 604 /* OK, now we need to know about added descriptors. */
591 if (!headcount) { 605 if (!headcount) {
592 if (unlikely(vhost_enable_notify(&net->dev, vq))) { 606 if (unlikely(vhost_enable_notify(&net->dev, vq))) {