From mboxrd@z Thu Jan 1 00:00:00 1970 From: Weidong Han Subject: Re: Xen 4.0.0-rc7 problem/hang with vt-d DMAR parsing Date: Thu, 25 Mar 2010 08:55:36 +0800 Message-ID: <4BAAB488.3020007@intel.com> References: <20100323193748.GW1878@reaktio.net> <20100323200515.GZ1878@reaktio.net> <4BA9DA400200007800036ABB@vpn.id2.novell.com> <4BA9D512.9090902@intel.com> <4BA9ED8D0200007800036B3F@vpn.id2.novell.com> <4BA9F0C1.7080809@intel.com> <4BAA01560200007800036B9B@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4BAA01560200007800036B9B@vpn.id2.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Jan Beulich Cc: "xen-devel@lists.xensource.com" , Keir Fraser , "Cui, Dexuan" List-Id: xen-devel@lists.xenproject.org Jan Beulich wrote: >>>> Weidong Han 24.03.10 12:00 >>> >>>> >> Re-checked the code. You're right. Updated the patch to check with >> sizeof(struct acpi_table_XXX). >> > > Why that way instead of checking for the header size in the common > code path, and for the precise size in the case statements? > > Jan > > Do you mean to know which case fails on length checking? How about below patch? diff -r a4eac162dcb9 xen/drivers/passthrough/vtd/dmar.c --- a/xen/drivers/passthrough/vtd/dmar.c Thu Mar 25 01:05:03 2010 +0800 +++ b/xen/drivers/passthrough/vtd/dmar.c Thu Mar 25 17:46:03 2010 +0800 @@ -664,21 +664,57 @@ static int __init acpi_parse_dmar(struct case ACPI_DMAR_DRHD: if ( iommu_verbose ) dprintk(VTDPREFIX, "found ACPI_DMAR_DRHD:\n"); + + if ( entry_header->length < sizeof(struct acpi_table_drhd) ) + { + dprintk(XENLOG_ERR VTDPREFIX, + " Invalid length: 0x%x\n", entry_header->length); + ret = -EINVAL; + goto disable; + } + ret = acpi_parse_one_drhd(entry_header); break; case ACPI_DMAR_RMRR: if ( iommu_verbose ) dprintk(VTDPREFIX, "found ACPI_DMAR_RMRR:\n"); + + if ( entry_header->length < sizeof(struct acpi_table_rmrr) ) + { + dprintk(XENLOG_ERR VTDPREFIX, + " Invalid length: 0x%x\n", entry_header->length); + ret = -EINVAL; + goto disable; + } + ret = acpi_parse_one_rmrr(entry_header); break; case ACPI_DMAR_ATSR: if ( iommu_verbose ) dprintk(VTDPREFIX, "found ACPI_DMAR_ATSR:\n"); + + if ( entry_header->length < sizeof(struct acpi_table_atsr) ) + { + dprintk(XENLOG_ERR VTDPREFIX, + " Invalid length: 0x%x\n", entry_header->length); + ret = -EINVAL; + goto disable; + } + ret = acpi_parse_one_atsr(entry_header); break; case ACPI_DMAR_RHSA: if ( iommu_verbose ) dprintk(VTDPREFIX, "found ACPI_DMAR_RHSA:\n"); + + if ( entry_header->length < sizeof(struct acpi_table_rhsa) ) + { + dprintk(XENLOG_ERR VTDPREFIX, + " Invalid length: 0x%x\n", entry_header->length); + ret = -EINVAL; + goto disable; + } + ret = acpi_parse_one_rhsa(entry_header); break; default: @@ -694,6 +730,7 @@ static int __init acpi_parse_dmar(struct entry_header = ((void *)entry_header + entry_header->length); } +disable: if ( ret ) { printk(XENLOG_WARNING