[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/8] VT-d: plug memory leaks in iommu_alloc()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 11 Apr 2022 11:36:43 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JIOtB5hoGvxfTiBr5WkyK/emu3c33KdonytgCqOz8N4=; b=EH86Tdakl5zMvOABjYeAHevrsu26w0tIVYhywTlDjI+gzQadw6YE5cK+QJQ4rstD+gcvEvz0bXidNWxtw5V3km9qWSKsc1w4xgtFZeIZszaQyGSoySoz4cdNDaE2QFHh0u48M9/pJ2T7O5ToEsO/a3SRTNgdTHGaneDn0Lrlqq/f6RUQjXvjLjhuRCELNhDWbFPd3Dmfo8GNJ02jjnY+S+YrVwt2b5S+ozpFD4bNKcqg4WV08V0VGnNvKzPKPF6NtuQjNfsGsc1qCGVnoRovsla2MFxKQB/ANHAtCfZuDGy+DQ8vg50UqoPkx52/MnQqNHCwsH6jk7zbcg73w6kdoQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QKToGTdRtFQqfWWcuJbuadyybRdJuj5V94VWNj0rB/6eq88t74cT7QbVPd8ZUhQul/c3clXjgNNE/7As+2QaGpHqWnnDHqW1xClA0293YqUcS5l9b1SKM1W/F6peWFyTV6D3AKYsafWQI1xPMYuyoa/MLpGikoSyynivQaHj6cN6oRs5eQd8CdEeTOzo969XxCIZ+994yr8jPa2x2lPlcXkBXE1nxrqvq5fQdyZhoHIG1l0MNZA6yPLt0YV8Wfoi7v1TDkuakfpCpA8MFF4WhIuiiWsZqYvOP5QQhdXfxCy9Mp6G5FgsZ4TvJW6jw6mjQM70x5WnGhsZOxNzwKLdpA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Kevin Tian <kevin.tian@xxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Mon, 11 Apr 2022 09:36:57 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

While 97af062b89d5 ("IOMMU/x86: maintain a per-device pseudo domain ID")
took care of not making things worse, plugging pre-existing leaks wasn't
the purpose of that change; they're not security relevant after all.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -1238,8 +1238,9 @@ int __init iommu_alloc(struct acpi_drhd_
     drhd->iommu = iommu;
 
     iommu->reg = ioremap(drhd->address, PAGE_SIZE);
+    rc = -ENOMEM;
     if ( !iommu->reg )
-        return -ENOMEM;
+        goto free;
     iommu->index = nr_iommus++;
 
     iommu->cap = dmar_readq(iommu->reg, DMAR_CAP_REG);
@@ -1260,8 +1261,9 @@ int __init iommu_alloc(struct acpi_drhd_
         printk(VTDPREFIX "cap = %"PRIx64" ecap = %"PRIx64"\n",
                iommu->cap, iommu->ecap);
     }
+    rc = -ENODEV;
     if ( !(iommu->cap + 1) || !(iommu->ecap + 1) )
-        return -ENODEV;
+        goto free;
 
     quirk_iommu_caps(iommu);
 
@@ -1272,7 +1274,8 @@ int __init iommu_alloc(struct acpi_drhd_
     {
         printk(XENLOG_ERR VTDPREFIX "IOMMU: unsupported\n");
         print_iommu_regs(drhd);
-        return -ENODEV;
+        rc = -ENODEV;
+        goto free;
     }
 
     /* Calculate number of pagetable levels: 3 or 4. */
@@ -1283,7 +1286,8 @@ int __init iommu_alloc(struct acpi_drhd_
     {
         printk(XENLOG_ERR VTDPREFIX "IOMMU: unsupported sagaw %x\n", sagaw);
         print_iommu_regs(drhd);
-        return -ENODEV;
+        rc = -ENODEV;
+        goto free;
     }
     iommu->nr_pt_levels = agaw_to_level(agaw);
 
@@ -1298,8 +1302,9 @@ int __init iommu_alloc(struct acpi_drhd_
         iommu->domid_bitmap = xzalloc_array(unsigned long,
                                             BITS_TO_LONGS(nr_dom));
         iommu->domid_map = xzalloc_array(domid_t, nr_dom);
+        rc = -ENOMEM;
         if ( !iommu->domid_bitmap || !iommu->domid_map )
-            return -ENOMEM;
+            goto free;
 
         /*
          * If Caching mode is set, then invalid translations are tagged




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.