virtio-blk: enforce iothread-vq-mapping validation
commit1f995a4782d140b16d9b24e787053944fb5c4dfb
authorStefan Hajnoczi <stefanha@redhat.com>
Tue, 6 Feb 2024 19:06:06 +0000 (6 14:06 -0500)
committerKevin Wolf <kwolf@redhat.com>
Wed, 7 Feb 2024 13:44:05 +0000 (7 14:44 +0100)
treee7564758db5fe87a4c8601826cedc311665d0661
parent39a6e4f87e7b75a45b08d6dc8b8b7c2954c87440
virtio-blk: enforce iothread-vq-mapping validation

Hanna Czenczek <hreitz@redhat.com> noticed that the safety of
`vq_aio_context[vq->value] = ctx;` with user-defined vq->value inputs is
not obvious.

The code is structured in validate() + apply() steps so input validation
is there, but it happens way earlier and there is nothing that
guarantees apply() can only be called with validated inputs.

This patch moves the validate() call inside the apply() function so
validation is guaranteed. I also added the bounds checking assertion
that Hanna suggested.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Message-ID: <20240206190610.107963-2-stefanha@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
hw/block/virtio-blk.c