From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B66A43E9F6 for ; Mon, 10 Aug 2026 20:02:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786392139; cv=none; b=ftw363r8CG5juHrTWn+C7kyr0H2Ysb7Urirhw0ZI9xdkyeBZ/IKco8l6j448fOe/ST+soPyRd/taGxSzn1eUoutYolfIpI+7qaP3FW5SM8KVTDAQCrYkGHg4G8FVunpJQWoGR1PX9YKpPFlwjQTTCpNLPBYRvpoN9MM79JlCO/k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786392139; c=relaxed/simple; bh=+9vkNVNvPzcxlfQfdghfV+XHMT4tY8VrvFMNsqBQXUs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Hf2JYrAd4PpkzhgdDstUR+kKHgc7zX5Cjgqan63OTfWbcXyZIqCAgWqkU/8BYgrvysAvy6f50oYCxlSxdkGY7xilsSdvbuwn+MdDd/6BmDKvXw2ThfzYiYCMdTsH7Z1fThkUAb1iIFOoLK7JgtK27AlHxErICjMqVAypLQWBHnU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=COdbYREc; arc=none smtp.client-ip=209.85.160.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="COdbYREc" Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-51bfa429aa6so2185781cf.0 for ; Mon, 10 Aug 2026 13:02:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1786392136; x=1786996936; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=4+rLRCu6gZDlUjtqIIOCBd9IdZYPdWeKZsJ7JGferjg=; b=COdbYREcD8ihEE1qDb5aeX4Tuz1d2LmPiIrAmNsIzJY5zMuCclvPeWsR3PLnnrrC0z 9VaXfV6arK4XAINPgwui4Pwu9VyGnmENKTCSCp3Vlc8GewKyyJM4+ZYBpnnDqaAUeC/i RCsnEfY2rlmMnKzW/35nJYqC/G58y62WDnSpqpkmjoPGDRVJMQo5OA48E0jImGk41xOX I8EYzL3+gGJNSAhTA8vk1gzteZqlZ07pSyz9FKKGXHbzevucDLCMH7U/bg8nFdraxVNw Tyh54i8PQJ8hwE730ydfYKWFm0hevill/RAFfdx5TUYQpfwwO4UrgZMWU8E5jIMYq0Fn GJfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786392136; x=1786996936; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=4+rLRCu6gZDlUjtqIIOCBd9IdZYPdWeKZsJ7JGferjg=; b=BX75VIRaOpLng6KnQG6ThwQWRWookPI+Xy7b3JfdD/9wkf3vifTg6GZQeIDFTHOrgP xLBqvsg50yYHB3ZH78mDpF8E5QCG49SjbMTVkfrHIB4x9F4XqZUzWH2AewoEYCh9uXcG hNIqjQkToRdSCVdWo1U6G9V3gV1Ngl2EAlKVmC1ioo+YAgjBBzElsNsim/OCBHXgO7Pu Kq+xtAfcg/X3Y8fc2JF+HUU4C4yADtzOW8QFvpVQWkTqZf+wdRxLAcbfh9HdaW6gw3Cb lruGiVl9sls+G7jjf6vSzqFWUTov7PcVFbyoAvXwoge0hCwcX7PBBNMCbW72Ay2h3Nb/ Rcuw== X-Forwarded-Encrypted: i=1; AHgh+Rqzmd8XUznb1KmVUteTuO269ucANcA7e5fRyVZJTBGf7sW3SZ6jI+HDdgtS6apKGvmL5/rklXIEpZZ3xVs=@vger.kernel.org X-Gm-Message-State: AOJu0YwjygJvv4dzT0XXCQHZkhCBdnt2Ar+Z5j+j0OyxC6JHjr0rGoty pNtV2DDFJluShzqN5T8aU+MtZ5jZB6PjDsiSWCsXeCwBJ6S1rh3iMIMsWJssMEN0PdI= X-Gm-Gg: AR+sD12h91o5ZX+qF8Czu4iJhFC2oMgjU0qseYpFzTxnUX0NrI2Jbn6n6h4ejIzrwZD vS7a38RhzRVPnnaRxVkTgubc74uRv6KO+oOguCiSEDesyPRUtztoH4GO95LzD7LFrLzKcXgwFc0 yIOfzhC5eF09JgrbGXgoGOyGyhpkVW9FhTcxbL1bk8jvghT3prpSFJhS4Qj0xR77b7I+QzrCvmL WaLfqU2ISBlzP+5fswWPT08Pu10UZEpRgrTQAFJDoo7Dp0QI1WZ6dMlPVS1s/PFdrgN79Nv+xzu 1Zc2R3EVEW0H4M2TRi62FJXwam+0fXXnBlD1ACZgO89Q57gLeOOW6DF5ViTbXmB2r/QqMPcndlE V7IZM2bI6J4/awJjYJZmx6T2djzfnu2iiCyWGrUlQlQRa82kaFbJ6Xq4s3NNXIU+Y18UN0lFxKQ skaeraNgWi9Ybg9YUQkX4cidWySOu2H97KwGloNA== X-Received: by 2002:a05:622a:e0d5:10b0:527:69ad:fceb with SMTP id d75a77b69052e-52d512575e3mr10177061cf.0.1786392136248; Mon, 10 Aug 2026 13:02:16 -0700 (PDT) Received: from ziepe.ca ([142.166.156.215]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-52d1637dd4dsm78983291cf.8.2026.08.10.13.02.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2026 13:02:15 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wtWCN-00000002D1s-0cYc; Mon, 10 Aug 2026 17:02:15 -0300 Date: Mon, 10 Aug 2026 17:02:15 -0300 From: Jason Gunthorpe To: Peiyang He Cc: "Tian, Kevin" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "joro@8bytes.org" , "will@kernel.org" , "robin.murphy@arm.com" , "syzkaller@googlegroups.com" Subject: Re: [BUG] iommufd/selftest: KASAN slab-use-after-free in iommu_report_device_fault Message-ID: <20260810200215.GA518032@ziepe.ca> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Jul 28, 2026 at 01:32:09PM +0800, Peiyang He wrote: > On 2026/7/27 17:41, Tian, Kevin wrote: > >> From: Peiyang He > >> Sent: Wednesday, July 22, 2026 5:52 PM > >> > > [...] > > > Since iommu_attach_handle_get() explicitly says that the caller should be > >> responsible for "synchronize the call of iommu_attach_handle_get() > >> with domain attachment and detachment", maybe we shouldn't add extra > >> lifetime > >> management mechanism around iommu_attach_handle, instead we should > >> fix this at the caller side. > >> > >> Fault report can run concurrently with PASID detach and replacement, but > >> before the old attach handle is removed and freed, mockdev must block new > >> reports > >> for that PASID and wait for in-flight iommu_report_device_fault() calls to > >> finish. > >> > > > > yes the mock driver should drain in-flight fault requests before the > > actual detachment, just like other iommu drivers do. > > Hi Kevin, > > Thanks for your reply. I looked into the code in more detail. Would this > approach make sense? > > In iommufd_test_trigger_iopf(), call iommu_report_device_fault() under the protection > of idev->igroup->lock. Since detach and replace also require the same lock, they can > be serialized with fault reporting. This would ensure that a mock fault report either > completes before detach/replace starts, or starts only after the old handle has been removed. > Thus it should prevent the UAF. > > Would this simple serialization meet the design intention of mock dev? Or would you prefer > an explicit quiesce/drain mechanism instead? The mock driver should follow the expected design of a real driver, so I'd put an internal rwsem or something like that to protect this Jason