Skip to content

Commit d43b468

Browse files
stefano-garzarellagregkh
authored andcommitted
vringh: fix __vringh_iov() when riov and wiov are different
commit 5745bcf upstream. If riov and wiov are both defined and they point to different objects, only riov is initialized. If the wiov is not initialized by the caller, the function fails returning -EINVAL and printing "Readable desc 0x... after writable" error message. This issue happens when descriptors have both readable and writable buffers (eg. virtio-blk devices has virtio_blk_outhdr in the readable buffer and status as last byte of writable buffer) and we call __vringh_iov() to get both type of buffers in two different iovecs. Let's replace the 'else if' clause with 'if' to initialize both riov and wiov if they are not NULL. As checkpatch pointed out, we also avoid crashing the kernel when riov and wiov are both NULL, replacing BUG() with WARN_ON() and returning -EINVAL. Fixes: f87d0fb ("vringh: host-side implementation of virtio rings.") Cc: stable@vger.kernel.org Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> Link: https://lore.kernel.org/r/20201008204256.162292-1-sgarzare@redhat.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 96e3212 commit d43b468

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

drivers/vhost/vringh.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,14 @@ __vringh_iov(struct vringh *vrh, u16 i,
284284
desc_max = vrh->vring.num;
285285
up_next = -1;
286286

287+
/* You must want something! */
288+
if (WARN_ON(!riov && !wiov))
289+
return -EINVAL;
290+
287291
if (riov)
288292
riov->i = riov->used = 0;
289-
else if (wiov)
293+
if (wiov)
290294
wiov->i = wiov->used = 0;
291-
else
292-
/* You must want something! */
293-
BUG();
294295

295296
for (;;) {
296297
void *addr;

0 commit comments

Comments
 (0)