Skip to content

Commit

Permalink
kmsan: unpoison virtio input buffers when adding them to to virtqueue
Browse files Browse the repository at this point in the history
It's hard (and too late already) to figure out the memory range to
be unpoisoned when we receive something via virtio.
Instead, we unpoison the input buffer before putting it into the
virtqueue.
  • Loading branch information
ramosian-glider committed Jun 13, 2018
1 parent 98f2922 commit 81c3105
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 2 additions & 6 deletions drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -1197,17 +1197,13 @@ static int virtnet_receive(struct receive_queue *rq, int budget, bool *xdp_xmit)

while (received < budget &&
(buf = virtqueue_get_buf_ctx(rq->vq, &len, &ctx))) {
r_bytes = receive_buf(vi, rq, buf, len, ctx, xdp_xmit);
kmsan_unpoison_shadow(buf, r_bytes);
bytes += r_bytes;
bytes += receive_buf(vi, rq, buf, len, ctx, xdp_xmit);
received++;
}
} else {
while (received < budget &&
(buf = virtqueue_get_buf(rq->vq, &len)) != NULL) {
r_bytes = receive_buf(vi, rq, buf, len, NULL, xdp_xmit);
kmsan_unpoison_shadow(buf, r_bytes);
bytes += r_bytes;
bytes += receive_buf(vi, rq, buf, len, NULL, xdp_xmit);
received++;
}
}
Expand Down
4 changes: 4 additions & 0 deletions drivers/virtio/virtio_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ static inline int virtqueue_add(struct virtqueue *_vq,
desc[i].flags = cpu_to_virtio16(_vq->vdev, VRING_DESC_F_NEXT | VRING_DESC_F_WRITE);
desc[i].addr = cpu_to_virtio64(_vq->vdev, addr);
desc[i].len = cpu_to_virtio32(_vq->vdev, sg->length);
// It's hard to figure out the buffer's address upon receive.
// Instead we unpoison it once, when exposing it to the device, and hope nobody
// else will write to it.
kmsan_unpoison_shadow(sg_virt(sg), sg->length);
prev = i;
i = virtio16_to_cpu(_vq->vdev, desc[i].next);
}
Expand Down

0 comments on commit 81c3105

Please sign in to comment.