From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E4203BA252; Mon, 23 Mar 2026 14:00:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774274412; cv=none; b=QmzSxXWb0EgHFFOjSd6XZ9JVQmyLZEqZZ6Juw5NwGAKbksdRFMyg19neBkyXRXv9asxiSPmo28zHwT/3x/Hzw4czc5FJhYemuiL6RXvuSZ4DXV0tWFnx8ejNYMdsUD0lDrEyL+RZBsopNyuWSLulGRXbz+S2/BobBePNVTh+XIc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774274412; c=relaxed/simple; bh=9ncozbRRlZC1rSgdD1jgslGFXfvZC802+gp4gw5WRnU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qWc+gyAPOqGpJ2OasjYBTdlDJhJVNnjypQm2+DrwTxgzg4uIGX8etX6WTFkdZLQ9D28wbCNunaJrqP+FIdZKBk5ZXo8dmr4G7N1c0TM5+6m/gRr2jWerK5yNP0pxaDgXTV608sHu3wQYtvOtUxHHeE1oW9A7Bvh/U0LsZhyHHx4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xR3161IB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="xR3161IB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CBBFC2BC9E; Mon, 23 Mar 2026 14:00:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774274412; bh=9ncozbRRlZC1rSgdD1jgslGFXfvZC802+gp4gw5WRnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xR3161IBzSpIvcCV+VFTMliO8mzNHCPpMkN16yqCKF3hedmA4svqW5OpWBG6QmhfZ SCNd4VqRzkRWF4gja8Hj9nfe8xIAI9k+GjXr8vGUp0NVWhlPrKYkT3s3ERScsQoQEX Fo7HfqOPwRoBwzIwkimPCl/3Qk2KBiaGIRdtcKfQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Lizhi Hou , Jason Gunthorpe , Yi Liu , Vasant Hegde , Lu Baolu , Joerg Roedel , Sasha Levin Subject: [PATCH 6.19 207/220] iommu/sva: Fix crash in iommu_sva_unbind_device() Date: Mon, 23 Mar 2026 14:46:24 +0100 Message-ID: <20260323134511.098960498@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260323134504.575022936@linuxfoundation.org> References: <20260323134504.575022936@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lizhi Hou [ Upstream commit 06e14c36e20b48171df13d51b89fe67c594ed07a ] domain->mm->iommu_mm can be freed by iommu_domain_free(): iommu_domain_free() mmdrop() __mmdrop() mm_pasid_drop() After iommu_domain_free() returns, accessing domain->mm->iommu_mm may dereference a freed mm structure, leading to a crash. Fix this by moving the code that accesses domain->mm->iommu_mm to before the call to iommu_domain_free(). Fixes: e37d5a2d60a3 ("iommu/sva: invalidate stale IOTLB entries for kernel address space") Signed-off-by: Lizhi Hou Reviewed-by: Jason Gunthorpe Reviewed-by: Yi Liu Reviewed-by: Vasant Hegde Reviewed-by: Lu Baolu Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/iommu-sva.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c index e1e63c2be82b2..fd735aaae9e3f 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -182,13 +182,13 @@ void iommu_sva_unbind_device(struct iommu_sva *handle) iommu_detach_device_pasid(domain, dev, iommu_mm->pasid); if (--domain->users == 0) { list_del(&domain->next); - iommu_domain_free(domain); - } + if (list_empty(&iommu_mm->sva_domains)) { + list_del(&iommu_mm->mm_list_elm); + if (list_empty(&iommu_sva_mms)) + iommu_sva_present = false; + } - if (list_empty(&iommu_mm->sva_domains)) { - list_del(&iommu_mm->mm_list_elm); - if (list_empty(&iommu_sva_mms)) - iommu_sva_present = false; + iommu_domain_free(domain); } mutex_unlock(&iommu_sva_lock); -- 2.51.0