From: "Jan Beulich" Subject: [PATCH] x86/AMD-ucode: correct multiple container handling Date: Mon, 15 Dec 2014 09:16:09 +0000 Message-ID: <548EB4E9020000780004F7BE@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartDDE80AC9.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 1Y0RlG-0002UE-CE for xen-devel@lists.xenproject.org; Mon, 15 Dec 2014 09:16:14 +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: Keir Fraser , Aravind Gopalakrishnan 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. --=__PartDDE80AC9.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Avoid emitting an error message referring to an incorrect or corrupt container file just because no entry was found for the running CPU. Additionally switch the order of data validation and consumption in cpu_request_microcode()'s first loop, and also check the types of skipped blocks in container_fast_forward(). Signed-off-by: Jan Beulich --- a/xen/arch/x86/microcode_amd.c +++ b/xen/arch/x86/microcode_amd.c @@ -331,12 +331,17 @@ static int container_fast_forward(const=20 header[1] =3D=3D UCODE_EQUIV_CPU_TABLE_TYPE ) break; =20 + if ( header[0] !=3D UCODE_UCODE_TYPE ) + return -EINVAL; size =3D header[1] + SECTION_HDR_SIZE; if ( size < PATCH_HDR_SIZE || size_left < size ) return -EINVAL; =20 size_left -=3D size; *offset +=3D size; + + if ( !size_left ) + return -ENODATA; } =20 return 0; @@ -386,10 +391,6 @@ static int cpu_request_microcode(int cpu break; } =20 - if ( find_equiv_cpu_id(mc_amd->equiv_cpu_table, current_cpu_id, - &equiv_cpu_id) ) - break; - /* * Could happen as we advance 'offset' early * in install_equiv_cpu_table @@ -401,7 +402,16 @@ static int cpu_request_microcode(int cpu break; } =20 + if ( find_equiv_cpu_id(mc_amd->equiv_cpu_table, current_cpu_id, + &equiv_cpu_id) ) + break; + error =3D container_fast_forward(buf, bufsize - offset, &offset); + if ( error =3D=3D -ENODATA ) + { + ASSERT(offset =3D=3D bufsize); + break; + } if ( error ) { printk(KERN_ERR "microcode: CPU%d incorrect or corrupt = container file\n" --=__PartDDE80AC9.1__= Content-Type: text/plain; name="x86-AMD-ucode-flow.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-AMD-ucode-flow.patch" x86/AMD-ucode: correct multiple container handling=0A=0AAvoid emitting an = error message referring to an incorrect or corrupt=0Acontainer file just = because no entry was found for the running CPU.=0A=0AAdditionally switch = the order of data validation and consumption in=0Acpu_request_microcode()'s= first loop, and also check the types of=0Askipped blocks in container_fast= _forward().=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/arch/x86/microcode_amd.c=0A+++ b/xen/arch/x86/microcode_amd.c=0A@@ = -331,12 +331,17 @@ static int container_fast_forward(const =0A = header[1] =3D=3D UCODE_EQUIV_CPU_TABLE_TYPE )=0A break;=0A = =0A+ if ( header[0] !=3D UCODE_UCODE_TYPE )=0A+ return = -EINVAL;=0A size =3D header[1] + SECTION_HDR_SIZE;=0A if ( = size < PATCH_HDR_SIZE || size_left < size )=0A return = -EINVAL;=0A =0A size_left -=3D size;=0A *offset +=3D = size;=0A+=0A+ if ( !size_left )=0A+ return -ENODATA;=0A = }=0A =0A return 0;=0A@@ -386,10 +391,6 @@ static int cpu_request_mic= rocode(int cpu=0A break;=0A }=0A =0A- if ( = find_equiv_cpu_id(mc_amd->equiv_cpu_table, current_cpu_id,=0A- = &equiv_cpu_id) )=0A- break;=0A-=0A = /*=0A * Could happen as we advance 'offset' early=0A * = in install_equiv_cpu_table=0A@@ -401,7 +402,16 @@ static int cpu_request_mi= crocode(int cpu=0A break;=0A }=0A =0A+ if ( = find_equiv_cpu_id(mc_amd->equiv_cpu_table, current_cpu_id,=0A+ = &equiv_cpu_id) )=0A+ break;=0A+=0A = error =3D container_fast_forward(buf, bufsize - offset, &offset);=0A+ = if ( error =3D=3D -ENODATA )=0A+ {=0A+ ASSERT(offset = =3D=3D bufsize);=0A+ break;=0A+ }=0A if ( error = )=0A {=0A printk(KERN_ERR "microcode: CPU%d incorrect = or corrupt container file\n"=0A --=__PartDDE80AC9.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 --=__PartDDE80AC9.1__=--