Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp6014973imm; Sat, 19 May 2018 15:09:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZotAJTDV0fAunA4NR3tTBXk+2R9IFuvWNs1weAvN/DEjnOxBQVnvWxCD56svNW67tOq3HE4 X-Received: by 2002:a62:c81d:: with SMTP id z29-v6mr14508324pff.81.1526767779961; Sat, 19 May 2018 15:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526767779; cv=none; d=google.com; s=arc-20160816; b=D7/oeHSfsO6Q6P66fHBq/QMKxgUWICxwr42sMUUiYwHY1i5ZnzDY2DZ0VphNoJ6sH1 1Euu9TMyjwtaY+viqCKfzFZWObi1uhAu9GemDqxzRDS6/rCeMLMlxpuKT+GI5HgAs9R4 y4myXbU3CnITT1LBKQHUrfdtMRsr5FkwWccF5pGKTof++XPoxCz+G1ChsoRwnV9wTfxm 5yikaAt3ghk1vx4BbiFa3roBKEJc7rubvzHujljvUaZ440l8pfEGVGmj/OP1nm5YfcTs YkeCRIZJi8VNj8itq9lAjDLUhu+u6CRUdExihVnUf0M4+CEociu8lkIIQYfTEbusGD+I 120w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=E2nfxtTRKTPtCK4UZmstuJaAmCqHRa+UU14YWRwzOAk=; b=H8Az+vUYqqIq2cRd2ohyY9SJKgKE4AxgoyiJUVfGsUy0ftC9N/J9R4K8Px8NWYJulg u8X7K3PeygGPnzW3Ez4uIVc9Dj4wVNOX5ia/P7fPCeC+xLQyVKEsPU7jJ7NOit81fLsk iTc2RFG5XdS/IlLfNjlWZ+a85kvRJy0LlbT+ygd9MwxOaaqy1S3bKjmCcJfzULn9WJjQ sRwQEPZa9mTjNsHaijCzZQCw1nQZtxecRHo4iwTDqhXO6qyTr007K787MYmyshTguRKk bcBphq8CLEE48fc1m4yb4XfqV5qFPRjs1tiRdYCi4SnufYhOCpucY/bZd/Bm5Z8L0iNi nXuA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r5-v6si8173117pgv.244.2018.05.19.15.09.25; Sat, 19 May 2018 15:09:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752744AbeESWIf (ORCPT + 99 others); Sat, 19 May 2018 18:08:35 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:49444 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752575AbeESWHs (ORCPT ); Sat, 19 May 2018 18:07:48 -0400 Received: by vps-vb.mhejs.net with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1fKA0a-0001Oz-79; Sun, 20 May 2018 00:07:24 +0200 From: "Maciej S. Szmigiero" To: Borislav Petkov Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 6/8] x86/microcode/AMD: Integrate verify_patch_size() into verify_patch() Date: Sun, 20 May 2018 00:07:20 +0200 Message-Id: X-Mailer: git-send-email 2.17.0 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that the previous commit converted the late loader to do a full patch checking via verify_patch() instead of calling verify_patch_size() directly we can integrate the later function into the former because it was its only user. Signed-off-by: Maciej S. Szmigiero --- arch/x86/kernel/cpu/microcode/amd.c | 72 +++++++++++------------------ 1 file changed, 27 insertions(+), 45 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c index 3e10a5920f58..764dac82c03f 100644 --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c @@ -182,9 +182,6 @@ static bool verify_patch_section(const u8 *buf, size_t buf_size, bool early) return true; } -static unsigned int verify_patch_size(u8 family, u32 patch_size, - unsigned int size); - /* * Checks whether a microcode patch located at the beginning of a passed * buffer @buf of size @size is not too large for a particular @family @@ -195,19 +192,43 @@ static unsigned int verify_patch_size(u8 family, u32 patch_size, static bool verify_patch(u8 family, const u8 *buf, size_t buf_size, bool early) { const u32 *hdr = (const u32 *)buf; - u32 patch_size; + u32 patch_size, max_size; if (!verify_patch_section(buf, buf_size, early)) return false; patch_size = hdr[1]; +#define F1XH_MPB_MAX_SIZE 2048 +#define F14H_MPB_MAX_SIZE 1824 +#define F15H_MPB_MAX_SIZE 4096 +#define F16H_MPB_MAX_SIZE 3458 +#define F17H_MPB_MAX_SIZE 3200 + + switch (family) { + case 0x14: + max_size = F14H_MPB_MAX_SIZE; + break; + case 0x15: + max_size = F15H_MPB_MAX_SIZE; + break; + case 0x16: + max_size = F16H_MPB_MAX_SIZE; + break; + case 0x17: + max_size = F17H_MPB_MAX_SIZE; + break; + default: + max_size = F1XH_MPB_MAX_SIZE; + break; + } + /* * The section header length is not included in this indicated size * but is present in the leftover file length so we need to subtract - * it before passing this value to the function below. + * it from the leftover file length. */ - if (!verify_patch_size(family, patch_size, buf_size - SECTION_HDR_SIZE)) { + if (patch_size > min_t(u32, max_size, buf_size - SECTION_HDR_SIZE)) { if (!early) pr_err("Patch of size %u too large.\n", patch_size); @@ -612,45 +633,6 @@ static int collect_cpu_info_amd(int cpu, struct cpu_signature *csig) return 0; } -/* - * Check whether the passed remaining file @size is large enough to contain a - * patch of the indicated @patch_size (and also whether this size does not - * exceed the per-family maximum). - */ -static unsigned int verify_patch_size(u8 family, u32 patch_size, unsigned int size) -{ - u32 max_size; - -#define F1XH_MPB_MAX_SIZE 2048 -#define F14H_MPB_MAX_SIZE 1824 -#define F15H_MPB_MAX_SIZE 4096 -#define F16H_MPB_MAX_SIZE 3458 -#define F17H_MPB_MAX_SIZE 3200 - - switch (family) { - case 0x14: - max_size = F14H_MPB_MAX_SIZE; - break; - case 0x15: - max_size = F15H_MPB_MAX_SIZE; - break; - case 0x16: - max_size = F16H_MPB_MAX_SIZE; - break; - case 0x17: - max_size = F17H_MPB_MAX_SIZE; - break; - default: - max_size = F1XH_MPB_MAX_SIZE; - break; - } - - if (patch_size > min_t(u32, size, max_size)) - return 0; - - return patch_size; -} - static enum ucode_state apply_microcode_amd(int cpu) { struct cpuinfo_x86 *c = &cpu_data(cpu);