[Devel] [PATCH VZ10 v3 5/5] drivers/vhost/blk: rework queue/backend setup
Andrey Zhadchenko
andrey.zhadchenko at virtuozzo.com
Tue Aug 25 16:27:52 MSK 2026
On 8/25/26 15:22, Konstantin Khorenko wrote:
> On 8/25/26 14:51, Andrey Zhadchenko wrote:
>> vhost_blk_setup() is pretty bad: silently refusing changed vq->num
>> if requests are already allocated, fetching user input second time
>> (double-fetch vulnerability).
>> To handle this, tie request allocation to backend existence. After
>> all, if there is no backend, there is no point in having requests.
>> Also expand it to get rid of boilerplate drop_backend, flush,
>> fput sequence in a few places.
>>
>> https://virtuozzo.atlassian.net/browse/VSTOR-138640
>> Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
>> ---
> ...
>
>> +static int vhost_blk_setup_vqs(struct vhost_blk *blk)
>> +{
>> + struct vhost_virtqueue *vq;
>> + int i;
>> +
>> + for (i = 0; i < VHOST_BLK_VQ_MAX; i++) {
>> + vq = &blk->vqs[i].vq;
>> +
>> + if (!vhost_vq_is_setup(vq))
>> + continue;
>> +
>> + blk->vqs[i].req = kvmalloc_array(vq->num, sizeof(struct vhost_blk_req),
>> + GFP_KERNEL);
>> + if (!blk->vqs[i].req)
>> + return -ENOMEM;
>> +
>> + mutex_lock(&vq->mutex);
>> + vhost_vq_set_backend(vq, blk->backend);
>> + if (vhost_vq_init_access(vq)) {
>> + mutex_unlock(&vq->mutex);
>> + return -EFAULT;
>> + }
>> + mutex_unlock(&vq->mutex);
>
> Well, i agree that currently vhost_vq_init_access() can return -EFAULT only as an error,
> but may be it's still worth to write a more generic return ret code?
LGTM.
Original code was using this aprroach too, no idea why have I changed that.
Can you apply this in-place or do you want me to re-spin the series?
>
> int ret, i;
>
> for (i = 0; i < VHOST_BLK_VQ_MAX; i++) {
> ...
> mutex_lock(&vq->mutex);
> vhost_vq_set_backend(vq, blk->backend);
> ret = vhost_vq_init_access(vq);
> mutex_unlock(&vq->mutex);
> if (ret)
> return ret;
>
>
>
>> + }
>> +
>> + return 0;
>> }
>> ...
More information about the Devel
mailing list