Skip to content

Commit d8316f3

Browse files
mstsirkindavem330
authored andcommitted
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>
1 parent 05efa8c commit d8316f3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

drivers/vhost/net.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,12 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
532532
*iovcount = seg;
533533
if (unlikely(log))
534534
*log_num = nlogs;
535+
536+
/* Detect overrun */
537+
if (unlikely(datalen > 0)) {
538+
r = UIO_MAXIOV + 1;
539+
goto err;
540+
}
535541
return headcount;
536542
err:
537543
vhost_discard_vq_desc(vq, headcount);
@@ -587,6 +593,14 @@ static void handle_rx(struct vhost_net *net)
587593
/* On error, stop handling until the next kick. */
588594
if (unlikely(headcount < 0))
589595
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+
}
590604
/* OK, now we need to know about added descriptors. */
591605
if (!headcount) {
592606
if (unlikely(vhost_enable_notify(&net->dev, vq))) {

0 commit comments

Comments
 (0)