Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp6015458imm; Sat, 19 May 2018 15:10:27 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrtYutkKu/TngYJ9bGSKICjRKB3qkF7BRza/GlnHAdatD+L+9IQtJfucT/bE0g1E2sLGrXo X-Received: by 2002:a17:902:8c92:: with SMTP id t18-v6mr14984402plo.337.1526767827688; Sat, 19 May 2018 15:10:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526767827; cv=none; d=google.com; s=arc-20160816; b=Xj5an5wMYgU7luW06N5/TgKRcqQT76ednqi+2UbktySvuZUXNJbLE06JPeHhujVc/Z 2718KcUt+Mbf1CjfQ0TIOZFkpvKI6UE6EExzP6dZNWc1EpDObpfS05nqtlMJTrVc3DYf aChpIkDw/tOXbGpJQa7mzgXtijAdjhtwXNQxOYKdyVO3Nkq79QvtQHb8ANL92tIsGfQE 4bu880ceTQd/m5M0c2OYxtSz7S0b/+KSFqWffGiofPQTJ7AoufiNiKhdCDQzJNeIi9c4 tqUceWRQjQ4XXtYHqDPB0rCXPck1mqAoh4aEQvPDRmhw5YR3MmWEXmJqRVfdJItw82pf KoKw== 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=SVgGYWu2RX+jbosGolKtCh4Jb0wkrUnfdlyNFMtSOTI=; b=QVCCfYL2Kp6T+AkkC4BdH+rwJkE/ABr5NEkX+2R+gcwilwvBfvB2EYsJmccgNO6ZLQ O4lPBt1HZIJ/k6ak70K7IfrEoxfftSXD7nfVlQ4+kjp/1NaXnRek8UK34hlSCs0zaZct f5i0KGSR+B4Vk43UBbOFxoi8XIQeVdpD/5eEsDMOWiYaWscV7JPI4212hvRAKgA10kUS mMt1TYD1eI7WOuZbMpDLO5bCN05LT2+lE67BRPUbSw+8ll38xPBiUS3Qvcj2MV2vyVRh aP5NkTLKTgfds+1a8Q/TQIZ0KNGhEGYpSuVIDgz/4j19t2siYqhUZKzssO4kJwgT7+Oo DMmg== 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 e11-v6si8312965pgu.459.2018.05.19.15.10.13; Sat, 19 May 2018 15:10:27 -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 S1752759AbeESWIg (ORCPT + 99 others); Sat, 19 May 2018 18:08:36 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:49440 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752569AbeESWHs (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 1fKA0Y-0001Ok-VY; Sun, 20 May 2018 00:07:23 +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 1/8] x86/microcode/AMD: Subtract SECTION_HDR_SIZE from file leftover length Date: Sun, 20 May 2018 00:07:15 +0200 Message-Id: <67484125a94a1d1120dae5c82601f7bc81d078c8.1526767245.git.mail@maciej.szmigiero.name> 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 verify_patch_size() verifies whether the remaining size of the microcode container file is large enough to contain a patch of the indicated size. However, the section header length is not included in this indicated size but it is present in the leftover file length so it should be subtracted from the leftover file length before passing this value to verify_patch_size(). Signed-off-by: Maciej S. Szmigiero Link: http://lkml.kernel.org/r/b4854b17-e3ba-54d6-488d-0e0bfffe4c71@maciej.szmigiero.name [ Split comment. ] Signed-off-by: Borislav Petkov --- arch/x86/kernel/cpu/microcode/amd.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c index 0624957aa068..dc8ea9a9d962 100644 --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c @@ -461,8 +461,12 @@ static int collect_cpu_info_amd(int cpu, struct cpu_signature *csig) return 0; } -static unsigned int verify_patch_size(u8 family, u32 patch_size, - unsigned int size) +/* + * 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; @@ -613,7 +617,12 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover) return crnt_size; } - ret = verify_patch_size(family, patch_size, leftover); + /* + * 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. + */ + ret = verify_patch_size(family, patch_size, leftover - SECTION_HDR_SIZE); if (!ret) { pr_err("Patch-ID 0x%08x: size mismatch.\n", mc_hdr->patch_id); return crnt_size;