virtio_ring: Fix two use after free bugs
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 4 Dec 2020 14:23:36 +0000 (17:23 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 30 Dec 2020 10:54:00 +0000 (11:54 +0100)
commitdbdfefc71ae555d64bfb29f0d8ee5b76167ce3f3
tree1c9ed25510f94624306014f7bca05bc50f8cfd61
parent78b35fd94cf91d782f6e65ed45f0355215f8fb94
virtio_ring: Fix two use after free bugs

[ Upstream commit e152d8af4220a05c9797591609151d404866beaa ]

The "vq" struct is added to the "vdev->vqs" list prematurely.  If we
encounter an error later in the function then the "vq" is freed, but
since it is still on the list that could lead to a use after free bug.

Fixes: cbeedb72b97a ("virtio_ring: allocate desc state for split ring separately")
Reported-by: Robert Buhren <robert.buhren@sect.tu-berlin.de>
Reported-by: Felicitas Hetzelt <file@sect.tu-berlin.de>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/X8pGaG/zkI3jk8mk@mwanda
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/virtio/virtio_ring.c