From: Andrew Cooper Date: Fri, 27 Mar 2020 11:59:02 +0000 (+0000) Subject: x86/ucode/amd: Fix potential buffer overrun with equiv table handling X-Git-Tag: archive/raspbian/4.14.0+80-gd101b417b7-1+rpi1^2~63^2~484 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=1f97b6b9f1b5978659c5735954c37c130e7bb151;p=xen.git x86/ucode/amd: Fix potential 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. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c index 122b8309af..96b80ff960 100644 --- a/xen/arch/x86/cpu/microcode/amd.c +++ b/xen/arch/x86/cpu/microcode/amd.c @@ -309,6 +309,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 */ @@ -318,7 +319,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;