OSDN Git Service

virtio_ring: validate used buffer length
authorJason Wang <jasowang@redhat.com>
Wed, 27 Oct 2021 02:21:04 +0000 (10:21 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Mon, 1 Nov 2021 09:26:48 +0000 (05:26 -0400)
commit939779f5152d161b34f612af29e7dc1ac4472fcf
treebf93ea06622a3e1fb9263a12ed4c7bd0f415b193
parentf0839372478ec53ff6d728422a6088f8a35b3a28
virtio_ring: validate used buffer length

This patch validate the used buffer length provided by the device
before trying to use it. This is done by record the in buffer length
in a new field in desc_state structure during virtqueue_add(), then we
can fail the virtqueue_get_buf() when we find the device is trying to
give us a used buffer length which is greater than the in buffer
length.

Since some drivers have already done the validation by themselves,
this patch tries to makes the core validation optional. For the driver
that doesn't want the validation, it can set the
suppress_used_validation to be true (which could be overridden by
force_used_validation module parameter). To be more efficient, a
dedicate array is used for storing the validate used length, this
helps to eliminate the cache stress if validation is done by the
driver.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Link: https://lore.kernel.org/r/20211027022107.14357-2-jasowang@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/virtio/virtio_ring.c
include/linux/virtio.h