[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250616164941.GA1373692@ziepe.ca>
Date: Mon, 16 Jun 2025 13:49:41 -0300
From: Jason Gunthorpe <jgg@...pe.ca>
To: "Tian, Kevin" <kevin.tian@...el.com>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@...nel.org>,
"iommu@...ts.linux.dev" <iommu@...ts.linux.dev>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Joerg Roedel <joro@...tes.org>, Will Deacon <will@...nel.org>,
Robin Murphy <robin.murphy@....com>
Subject: Re: [RFC PATCH] iommufd: Destroy vdevice on device unbind
On Mon, Jun 16, 2025 at 05:37:58AM +0000, Tian, Kevin wrote:
> the expected destruction flow from userspace is to IOMMU_DESTROY
> the vdevice object before closing the vfio cdev fd which unbinds the
> idevice.
>
> now we are discussing how to handle a malfunction userspace which
> violates that flow: let it be or add a tomestone state, after extending
> unbind to destroy the vdevice...
Right, to be clear the concern is
close(vfio_cdev)
ioctl(DESTROY, vdevice_id);
close(iommufd)
Which is a possibile sequence for userspace/syzkaller to trigger.
My position has historically been that DESTROY should not destroy some
random unrelated object eg because a parallel thread did an allocation
and re-used the kernel deleted ID. ID's that belong to userspace have
to be retained right up until DESTROY.
Thus we've historically avoided creating scenarios where IDs owned by
userspace are destroyed by the kernel.
Given we can say the above is illegal use of the API we could leave
behind a tombstone in the xarray. The goal would be to prevent lookup
of the object (since it is destroyed) and prevent reallocation of the
ID.
For instance a simple thing would be to drop in XA_ZERO_ENTRY, this
will reserve the ID and fail all future operations. The userspace will
get a failure on DESTROY so they know they did something wrong. The fd
close will clean up the reserved ID.
We just need to make some decision about the above sequence.
Jason
Powered by blists - more mailing lists