From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH] x86/AMD-ucode: correct multiple container handling Date: Mon, 15 Dec 2014 11:29:31 +0000 Message-ID: <548EC61B.6000806@citrix.com> References: <548EB4E9020000780004F7BE@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7630040474445199251==" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Y0TqK-0000gF-82 for xen-devel@lists.xenproject.org; Mon, 15 Dec 2014 11:29:36 +0000 In-Reply-To: <548EB4E9020000780004F7BE@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich , xen-devel Cc: Aravind Gopalakrishnan , Keir Fraser List-Id: xen-devel@lists.xenproject.org --===============7630040474445199251== Content-Type: multipart/alternative; boundary="------------050004020708090308040904" --------------050004020708090308040904 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable On 15/12/14 09:16, Jan Beulich wrote: > 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 Reviewed-by: Andrew Cooper > > --- 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, &offse= t); > + if ( error =3D=3D -ENODATA ) > + { > + ASSERT(offset =3D=3D bufsize); > + break; > + } > if ( error ) > { > printk(KERN_ERR "microcode: CPU%d incorrect or corrupt con= tainer file\n" > > > > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xen.org > http://lists.xen.org/xen-devel --------------050004020708090308040904 Content-Type: text/html; charset="windows-1252" Content-Transfer-Encoding: 8bit
On 15/12/14 09:16, Jan Beulich wrote:
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 <jbeulich@suse.com>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>


--- a/xen/arch/x86/microcode_amd.c
+++ b/xen/arch/x86/microcode_amd.c
@@ -331,12 +331,17 @@ static int container_fast_forward(const 
              header[1] == UCODE_EQUIV_CPU_TABLE_TYPE )
             break;
 
+        if ( header[0] != UCODE_UCODE_TYPE )
+            return -EINVAL;
         size = header[1] + SECTION_HDR_SIZE;
         if ( size < PATCH_HDR_SIZE || size_left < size )
             return -EINVAL;
 
         size_left -= size;
         *offset += size;
+
+        if ( !size_left )
+            return -ENODATA;
     }
 
     return 0;
@@ -386,10 +391,6 @@ static int cpu_request_microcode(int cpu
             break;
         }
 
-        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;
         }
 
+        if ( find_equiv_cpu_id(mc_amd->equiv_cpu_table, current_cpu_id,
+                               &equiv_cpu_id) )
+            break;
+
         error = container_fast_forward(buf, bufsize - offset, &offset);
+        if ( error == -ENODATA )
+        {
+            ASSERT(offset == bufsize);
+            break;
+        }
         if ( error )
         {
             printk(KERN_ERR "microcode: CPU%d incorrect or corrupt container file\n"





_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

--------------050004020708090308040904-- --===============7630040474445199251== 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 --===============7630040474445199251==--