]> git.apps.os.sepia.ceph.com Git - ceph-client.git/commit
iommufd: Fix refcounting race during mmap
authorJason Gunthorpe <jgg@nvidia.com>
Tue, 16 Sep 2025 15:42:56 +0000 (12:42 -0300)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 19 Sep 2025 13:34:49 +0000 (10:34 -0300)
commit7a425ec75d2bb30a1c959a8676ef8c5ef285095d
tree80ffed2cbcff9b293b2c943ad2ff14e024ec74f1
parentf83ec76bf285bea5727f478a68b894f5543ca76e
iommufd: Fix refcounting race during mmap

The owner object of the imap can be destroyed while the imap remains in
the mtree. So access to the imap pointer without holding locks is racy
with destruction.

The imap is safe to access outside the lock once a users refcount is
obtained, the owner object cannot start destruction until users is 0.

Thus the users refcount should not be obtained at the end of
iommufd_fops_mmap() but instead inside the mtree lock held around the
mtree_load(). Move the refcount there and use refcount_inc_not_zero() as
we can have a 0 refcount inside the mtree during destruction races.

Link: https://patch.msgid.link/r/0-v1-e6faace50971+3cc-iommufd_mmap_fix_jgg@nvidia.com
Cc: stable@vger.kernel.org
Fixes: 56e9a0d8e53f ("iommufd: Add mmap interface")
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/iommufd/main.c