Module Name: src Committed By: martin Date: Tue Oct 11 18:05:44 UTC 2022
Modified Files: src/sys/arch/x86/include [netbsd-9]: cpu_ucode.h src/sys/arch/x86/x86 [netbsd-9]: cpu_ucode_intel.c Log Message: Pull up following revision(s) (requested by msaitoh in ticket #1538): sys/arch/x86/include/cpu_ucode.h: revision 1.5 sys/arch/x86/x86/cpu_ucode_intel.c: revision 1.19 sys/arch/x86/x86/cpu_ucode_intel.c: revision 1.20 Add missing newline in a message. KNF. Verify checksum of the extended signature table. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.4.6.1 src/sys/arch/x86/include/cpu_ucode.h cvs rdiff -u -r1.17 -r1.17.2.1 src/sys/arch/x86/x86/cpu_ucode_intel.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/x86/include/cpu_ucode.h diff -u src/sys/arch/x86/include/cpu_ucode.h:1.4 src/sys/arch/x86/include/cpu_ucode.h:1.4.6.1 --- src/sys/arch/x86/include/cpu_ucode.h:1.4 Sat Mar 17 15:56:32 2018 +++ src/sys/arch/x86/include/cpu_ucode.h Tue Oct 11 18:05:44 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu_ucode.h,v 1.4 2018/03/17 15:56:32 christos Exp $ */ +/* $NetBSD: cpu_ucode.h,v 1.4.6.1 2022/10/11 18:05:44 martin Exp $ */ /* * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. @@ -69,17 +69,16 @@ struct intel1_ucode_header { uint32_t uh_reserved[3]; }; -struct intel1_ucode_proc_signature { - uint32_t ups_signature; - uint32_t ups_proc_flags; - uint32_t ups_checksum; -}; - struct intel1_ucode_ext_table { uint32_t uet_count; uint32_t uet_checksum; uint32_t uet_reserved[3]; - struct intel1_ucode_proc_signature uet_proc_sig[1]; +}; + +struct intel1_ucode_proc_signature { + uint32_t ups_signature; + uint32_t ups_proc_flags; + uint32_t ups_checksum; }; #endif Index: src/sys/arch/x86/x86/cpu_ucode_intel.c diff -u src/sys/arch/x86/x86/cpu_ucode_intel.c:1.17 src/sys/arch/x86/x86/cpu_ucode_intel.c:1.17.2.1 --- src/sys/arch/x86/x86/cpu_ucode_intel.c:1.17 Fri May 10 18:21:01 2019 +++ src/sys/arch/x86/x86/cpu_ucode_intel.c Tue Oct 11 18:05:44 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu_ucode_intel.c,v 1.17 2019/05/10 18:21:01 maxv Exp $ */ +/* $NetBSD: cpu_ucode_intel.c,v 1.17.2.1 2022/10/11 18:05:44 martin Exp $ */ /* * Copyright (c) 2012, 2019 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.17 2019/05/10 18:21:01 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.17.2.1 2022/10/11 18:05:44 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_xen.h" @@ -111,63 +111,65 @@ static int cpu_ucode_intel_verify(struct cpu_ucode_softc *sc, struct intel1_ucode_header *buf) { + struct intel1_ucode_ext_table *ehdr; uint32_t data_size, total_size, payload_size, ext_size; uint32_t sum; + uint32_t *p; int i; if ((buf->uh_header_ver != 1) || (buf->uh_loader_rev != 1)) return EINVAL; - /* - * Data size. - */ - if (buf->uh_data_size == 0) { + /* Data size. */ + if (buf->uh_data_size == 0) data_size = 2000; - } else { + else data_size = buf->uh_data_size; - } if ((data_size % 4) != 0) return EINVAL; if (data_size > sc->sc_blobsize) return EINVAL; - /* - * Total size. - */ - if (buf->uh_total_size == 0) { + /* Total size. */ + if (buf->uh_total_size == 0) total_size = data_size + 48; - } else { + else total_size = buf->uh_total_size; - } if ((total_size % 1024) != 0) return EINVAL; if (total_size > sc->sc_blobsize) return EINVAL; - /* - * Payload size. - */ + /* Payload size. */ payload_size = data_size + 48; if (payload_size > sc->sc_blobsize) return EINVAL; - /* - * Verify checksum of update data and header. Exclude extended - * signature. - */ + /* Verify checksum of update data and header(s). */ sum = 0; - for (i = 0; i < (payload_size / sizeof(uint32_t)); i++) { - sum += *((uint32_t *)buf + i); - } + p = (uint32_t *)buf; + for (i = 0; i < (payload_size / sizeof(uint32_t)); i++) + sum += p[i]; if (sum != 0) return EINVAL; - /* - * Extended table size. Ignored for now. - */ ext_size = total_size - payload_size; if (ext_size > 0) { - printf("This image has extended signature table."); + /* This image has extended signature table. */ + ehdr = (struct intel1_ucode_ext_table *) + ((uint8_t *)buf + sizeof(struct intel1_ucode_header) + + data_size); + payload_size = + sizeof(struct intel1_ucode_ext_table) + + sizeof(struct intel1_ucode_proc_signature) * + ehdr->uet_count; + + sum = 0; + p = (uint32_t *)ehdr; + for (i = 0; i < (payload_size / sizeof(uint32_t)); i++) + sum += p[i]; + if (sum != 0) + return EINVAL; } return 0; @@ -198,7 +200,8 @@ cpu_ucode_intel_apply(struct cpu_ucode_s /* Make the buffer 16 byte aligned. */ newbufsize = sc->sc_blobsize + 15; uha = kmem_alloc(newbufsize, KM_SLEEP); - uh = (struct intel1_ucode_header *)roundup2((uintptr_t)uha, 16); + uh = + (struct intel1_ucode_header *)roundup2((uintptr_t)uha, 16); memcpy(uh, sc->sc_blob, sc->sc_blobsize); }