Skip to contentSkip to conversation

x86/ucode/amd: Fix buffer overrun with equiv table handling

PATCH In review Andrew Cooper 2 participants 2 messages Mar 27, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/ucode/amd: Fix buffer overrun with equiv table handling

find_equiv_cpu_id() loops until it finds a 0 installed_cpu entry. Well formed AMD microcode containers have this property.

Extend the checking in install_equiv_cpu_table() to reject tables which don't have a sentinal at the end.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

All of this logic needs rewriting, but this is the minimally invasive version for backport.

---
 xen/arch/x86/cpu/microcode/amd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
xen/arch/x86/cpu/microcode/amd.c +4 -1
index b8b83d248d..9fe1a3c941 100644
@@ -310,6 +310,7 @@ static int install_equiv_cpu_table(
     size_t *offset)
 {
     const struct mpbhdr *mpbuf = data + *offset + 4;
+    const struct equiv_cpu_entry *eq;
 
     *offset += mpbuf->len + CONT_HDR_SIZE;	/* add header length */
 
@@ -319,7 +320,9 @@ static int install_equiv_cpu_table(
         return -EINVAL;
     }
 
-    if ( mpbuf->len == 0 )
+    if ( mpbuf->len == 0 || mpbuf->len % sizeof(*eq) ||
+         (eq = (const void *)mpbuf->data,
+          eq[(mpbuf->len / sizeof(*eq)) - 1].installed_cpu) )
     {
         printk(KERN_ERR "microcode: Wrong microcode equivalent cpu table length\n");
         return -EINVAL;
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Andrew Cooper

find_equiv_cpu_id() loops until it finds a 0 installed_cpu entry. Well formed AMD microcode containers have this property.

With this, would you mind adding "potential" to the subject?

Quoted 4 lines

Extend the checking in install_equiv_cpu_table() to reject tables which don't have a sentinal at the end.