Archive-only list for patches
 help / color / mirror / Atom feed
* [PATCH rc v2 0/2] Do not UAF during iommufd_put_object()
@ 2023-11-22 13:13 Jason Gunthorpe
  2023-11-22 13:13 ` [PATCH rc v2 1/2] iommufd: Add iommufd_ctx to iommufd_put_object() Jason Gunthorpe
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Jason Gunthorpe @ 2023-11-22 13:13 UTC (permalink / raw)
  To: iommu
  Cc: Lu Baolu, Eric Auger, Kevin Tian, Lixiao Yang, Matthew Rosato,
	Nicolin Chen, patches, syzbot+7574ebfe589049630608,
	syzbot+d31adfb277377ef8fcba, Yi Liu

The mixture of kernel and user space lifecycle objects continues to be
complicated inside iommufd. The obj->destroy_rwsem is used to bring order
to the kernel driver destruction sequence but it cannot be sequenced right
with the other refcounts so we end up possibly UAF'ing.

Fix it by using two refcounts and a wait queue to sequence the destruction
process.

v2:
 - Use refcount_inc_not_zero in both places in iommu_lock_obj() for
   robustness
 - Move the wait_event_timeout sequence into
   iommufd_object_dec_wait_shortterm()
 - Consistently dec users on the bug path to give close() a chance to
   recover
 - Change the order so if users reaches zero then we clean the xarray and
   then unlock. Wait for shortterm to reach zero outside the lock
 - Make iommufd_object_remove() non-static and use inlines to call it in
   the various cases
 - Comments
v1: https://lore.kernel.org/r/0-v1-4c9a7fbb5702+107a-iommufd_syz4_jgg@nvidia.com

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Jason Gunthorpe (2):
  iommufd: Add iommufd_ctx to iommufd_put_object()
  iommufd: Do not UAF during iommufd_put_object()

 drivers/iommu/iommufd/device.c          |  14 +--
 drivers/iommu/iommufd/hw_pagetable.c    |   8 +-
 drivers/iommu/iommufd/ioas.c            |  14 +--
 drivers/iommu/iommufd/iommufd_private.h |  56 +++++++--
 drivers/iommu/iommufd/main.c            | 146 +++++++++++++-----------
 drivers/iommu/iommufd/selftest.c        |  14 +--
 drivers/iommu/iommufd/vfio_compat.c     |  18 +--
 7 files changed, 160 insertions(+), 110 deletions(-)


base-commit: 98b1cc82c4affc16f5598d4fa14b1858671b2263
-- 
2.42.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-11-30  0:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-22 13:13 [PATCH rc v2 0/2] Do not UAF during iommufd_put_object() Jason Gunthorpe
2023-11-22 13:13 ` [PATCH rc v2 1/2] iommufd: Add iommufd_ctx to iommufd_put_object() Jason Gunthorpe
2023-11-22 13:13 ` [PATCH rc v2 2/2] iommufd: Do not UAF during iommufd_put_object() Jason Gunthorpe
2023-11-24  6:48   ` Tian, Kevin
2023-11-24 12:50     ` Jason Gunthorpe
2023-11-28  7:59       ` Tian, Kevin
2023-11-29  1:03         ` Jason Gunthorpe
2023-11-30  0:37 ` [PATCH rc v2 0/2] " Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox