Skip to content

Commit 445a229

Browse files
YongjiXiegregkh
authored andcommitted
virtio_console: Assure used length from device is limited
[ Upstream commit d00d8da ] The buf->len might come from an untrusted device. This ensures the value would not exceed the size of the buffer to avoid data corruption or loss. Signed-off-by: Xie Yongji <xieyongji@bytedance.com> Acked-by: Jason Wang <jasowang@redhat.com> Link: https://lore.kernel.org/r/20210525125622.1203-1-xieyongji@bytedance.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 3c08a11 commit 445a229

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎drivers/char/virtio_console.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ static struct port_buffer *get_inbuf(struct port *port)
475475

476476
buf = virtqueue_get_buf(port->in_vq, &len);
477477
if (buf) {
478-
buf->len = len;
478+
buf->len = min_t(size_t, len, buf->size);
479479
buf->offset = 0;
480480
port->stats.bytes_received += len;
481481
}
@@ -1712,7 +1712,7 @@ static void control_work_handler(struct work_struct *work)
17121712
while ((buf = virtqueue_get_buf(vq, &len))) {
17131713
spin_unlock(&portdev->c_ivq_lock);
17141714

1715-
buf->len = len;
1715+
buf->len = min_t(size_t, len, buf->size);
17161716
buf->offset = 0;
17171717

17181718
handle_control_message(vq->vdev, portdev, buf);

0 commit comments

Comments
 (0)