From: Andrew Cooper Date: Thu, 9 Apr 2020 08:15:17 +0000 (+0200) Subject: x86/ucode/amd: Fix potential buffer overrun with equiv table handling X-Git-Tag: archive/raspbian/4.11.4-1+rpi1^2~58^2~10 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=09508fda40f08deed89e5f7e9f9b9744ff2bbeca;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 master commit: 1f97b6b9f1b5978659c5735954c37c130e7bb151 master date: 2020-03-27 13:13:26 +0000 --- diff --git a/xen/arch/x86/microcode_amd.c b/xen/arch/x86/microcode_amd.c index afceaf83ba..5080e54409 100644 --- a/xen/arch/x86/microcode_amd.c +++ b/xen/arch/x86/microcode_amd.c @@ -297,6 +297,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 */ @@ -306,7 +307,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;