vfio: Don't leak a group reference if the group already exists
authorJason Gunthorpe <jgg@nvidia.com>
Fri, 15 Oct 2021 11:40:52 +0000 (08:40 -0300)
committerAlex Williamson <alex.williamson@redhat.com>
Fri, 15 Oct 2021 19:58:20 +0000 (13:58 -0600)
commit325a31c920309d2225311573a05c2f4dd402b2ed
tree907abc48d414c4f0b1ab4cef209b417bfce05a72
parent1ceabade1df78c420e30efd4d39a48ceb46487bc
vfio: Don't leak a group reference if the group already exists

If vfio_create_group() searches the group list and returns an already
existing group it does not put back the iommu_group reference that the
caller passed in.

Change the semantic of vfio_create_group() to not move the reference in
from the caller, but instead obtain a new reference inside and leave the
caller's reference alone. The two callers must now call iommu_group_put().

This is an unlikely race as the only caller that could hit it has already
searched the group list before attempting to create the group.

Fixes: cba3345cc494 ("vfio: VFIO core")
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/3-v3-2fdfe4ca2cc6+18c-vfio_group_cdev_jgg@nvidia.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/vfio.c