lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening linux-cve-announce PHC | |
Open Source and information security mailing list archives
| ||
|
Date: Tue, 19 Jun 2018 20:47:35 +0200 From: "Maciej S. Szmigiero" <mail@...iej.szmigiero.name> To: Borislav Petkov <bp@...en8.de> Cc: Thomas Gleixner <tglx@...utronix.de>, Ingo Molnar <mingo@...hat.com>, "H. Peter Anvin" <hpa@...or.com>, x86@...nel.org, linux-kernel@...r.kernel.org Subject: [PATCH v7 5/9] x86/microcode/AMD: Split status from data to skip in verify_and_add_patch() verify_and_add_patch() returned a single "int" value which encoded both this function error status and also a length of microcode container data to skip. Unfortunately, ranges of these two values collide: the length of data to skip can be any value between 1 and UINT_MAX, so, for example, error status of -EINVAL maps to a valid return value of 4294967274 bytes. That's why these two values need to be split. Let's keep the common convention that a function zero return value means success while a negative value means an error while moving the returned length of microcode container data to skip to a separate output parameter. Signed-off-by: Maciej S. Szmigiero <mail@...iej.szmigiero.name> --- arch/x86/kernel/cpu/microcode/amd.c | 35 +++++++++++++++-------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c index c05531540b57..9e29374ce4d0 100644 --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c @@ -754,45 +754,46 @@ static void cleanup(void) } /* - * We return the current size even if some of the checks failed so that - * we can skip over the next patch. If we return a negative value, we - * signal a grave error like a memory allocation has failed and the - * driver cannot continue functioning normally. In such cases, we tear - * down everything we've used up so far and exit. + * We return zero (success) and the current patch data size in @crnt_size + * even if some of the checks failed so that we can skip over the next patch. + * If we return a negative value, we signal a grave error like a memory + * allocation has failed and the driver cannot continue functioning normally. + * In such cases, we tear down everything we've used up so far and exit. */ -static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover) +static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover, + unsigned int *crnt_size) { struct microcode_header_amd *mc_hdr; struct ucode_patch *patch; - unsigned int patch_size, crnt_size; + unsigned int patch_size; u32 proc_fam; u16 proc_id; patch_size = *(u32 *)(fw + 4); - crnt_size = patch_size + SECTION_HDR_SIZE; + *crnt_size = patch_size + SECTION_HDR_SIZE; mc_hdr = (struct microcode_header_amd *)(fw + SECTION_HDR_SIZE); proc_id = mc_hdr->processor_rev_id; proc_fam = find_cpu_family_by_equiv_cpu(proc_id); if (!proc_fam) { pr_err("No patch family for equiv ID: 0x%04x\n", proc_id); - return crnt_size; + return 0; } /* check if patch is for the current family */ proc_fam = ((proc_fam >> 8) & 0xf) + ((proc_fam >> 20) & 0xff); if (proc_fam != family) - return crnt_size; + return 0; if (mc_hdr->nb_dev_id || mc_hdr->sb_dev_id) { pr_err("Patch-ID 0x%08x: chipset-specific code unsupported.\n", mc_hdr->patch_id); - return crnt_size; + return 0; } - if (!verify_patch(family, fw, leftover, &crnt_size, false)) { + if (!verify_patch(family, fw, leftover, crnt_size, false)) { pr_err("Patch-ID 0x%08x: size mismatch.\n", mc_hdr->patch_id); - return crnt_size; + return 0; } patch = kzalloc(sizeof(*patch), GFP_KERNEL); @@ -818,7 +819,7 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover) /* ... and add to cache. */ update_cache(patch); - return crnt_size; + return 0; } static enum ucode_state __load_microcode_amd(u8 family, const u8 *data, @@ -827,7 +828,6 @@ static enum ucode_state __load_microcode_amd(u8 family, const u8 *data, enum ucode_state ret = UCODE_ERROR; unsigned int leftover; u8 *fw = (u8 *)data; - int crnt_size = 0; int offset; offset = install_equiv_cpu_table(data); @@ -845,8 +845,9 @@ static enum ucode_state __load_microcode_amd(u8 family, const u8 *data, } while (leftover) { - crnt_size = verify_and_add_patch(family, fw, leftover); - if (crnt_size < 0) + unsigned int crnt_size; + + if (verify_and_add_patch(family, fw, leftover, &crnt_size) < 0) return ret; fw += crnt_size;
Powered by blists - more mailing lists