From: "Jan Beulich" Subject: [PATCH] AMD IOMMU: add missing checks Date: Tue, 27 Aug 2013 14:52:17 +0100 Message-ID: <521CCB3102000078000EECAC@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part88BBCB01.1__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VEJhC-0004hA-BK for xen-devel@lists.xenproject.org; Tue, 27 Aug 2013 13:52:34 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Jacob Shin , suravee.suthikulpanit@amd.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part88BBCB01.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline For one we shouldn't accept IVHD tables specifying IO-APIC IDs beyond the limit we support (MAX_IO_APICS, currently 128). And then we shouldn't memset() a pointer allocation of which failed. Signed-off-by: Jan Beulich --- a/xen/drivers/passthrough/amd/iommu_acpi.c +++ b/xen/drivers/passthrough/amd/iommu_acpi.c @@ -674,6 +674,13 @@ static u16 __init parse_ivhd_device_spec if ( IO_APIC_ID(apic) !=3D special->handle ) continue; =20 + if ( special->handle >=3D ARRAY_SIZE(ioapic_sbdf) ) + { + printk(XENLOG_ERR "IVHD Error: IO-APIC %#x entry beyond = bounds\n", + special->handle); + return 0; + } + if ( ioapic_sbdf[special->handle].pin_2_idx ) { if ( ioapic_sbdf[special->handle].bdf =3D=3D bdf && @@ -943,13 +950,14 @@ static int __init parse_ivrs_table(struc { ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx =3D xmalloc_array( u16, nr_ioapic_entries[apic]); - if ( !ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx ) + if ( ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx ) + memset(ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx, -1, + nr_ioapic_entries[apic] * sizeof(*ioapic_sbdf->pin_= 2_idx)); + else { printk(XENLOG_ERR "IVHD Error: Out of memory\n"); error =3D -ENOMEM; } - memset(ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx, -1, - nr_ioapic_entries[apic] * sizeof(*ioapic_sbdf->pin_2_id= x)); } } =20 --=__Part88BBCB01.1__= Content-Type: text/plain; name="AMD-IOMMU-checks.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="AMD-IOMMU-checks.patch" AMD IOMMU: add missing checks=0A=0AFor one we shouldn't accept IVHD tables = specifying IO-APIC IDs beyond=0Athe limit we support (MAX_IO_APICS, = currently 128).=0A=0AAnd then we shouldn't memset() a pointer allocation = of which failed.=0A=0ASigned-off-by: Jan Beulich =0A=0A-= -- a/xen/drivers/passthrough/amd/iommu_acpi.c=0A+++ b/xen/drivers/passthrou= gh/amd/iommu_acpi.c=0A@@ -674,6 +674,13 @@ static u16 __init parse_ivhd_dev= ice_spec=0A if ( IO_APIC_ID(apic) !=3D special->handle )=0A = continue;=0A =0A+ if ( special->handle >=3D = ARRAY_SIZE(ioapic_sbdf) )=0A+ {=0A+ printk(XENLOG= _ERR "IVHD Error: IO-APIC %#x entry beyond bounds\n",=0A+ = special->handle);=0A+ return 0;=0A+ = }=0A+=0A if ( ioapic_sbdf[special->handle].pin_2_idx )=0A = {=0A if ( ioapic_sbdf[special->handle].bdf =3D=3D = bdf &&=0A@@ -943,13 +950,14 @@ static int __init parse_ivrs_table(struc=0A = {=0A ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx =3D = xmalloc_array(=0A u16, nr_ioapic_entries[apic]);=0A- = if ( !ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx )=0A+ if ( = ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx )=0A+ memset(ioapic_= sbdf[IO_APIC_ID(apic)].pin_2_idx, -1,=0A+ nr_ioapic_e= ntries[apic] * sizeof(*ioapic_sbdf->pin_2_idx));=0A+ else=0A = {=0A printk(XENLOG_ERR "IVHD Error: Out of = memory\n");=0A error =3D -ENOMEM;=0A }=0A- = memset(ioapic_sbdf[IO_APIC_ID(apic)].pin_2_idx, -1,=0A- = nr_ioapic_entries[apic] * sizeof(*ioapic_sbdf->pin_2_idx));=0A = }=0A }=0A =0A --=__Part88BBCB01.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part88BBCB01.1__=--