Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2544986imu; Mon, 19 Nov 2018 02:13:59 -0800 (PST) X-Google-Smtp-Source: AJdET5cGuMYkaqYfXDprOaykGxqMci8KEkIcKIQ3+6Ktemuo+lT9UsVj9zZQTQ7FAvLonohbicEX X-Received: by 2002:a63:224f:: with SMTP id t15mr19490076pgm.69.1542622439486; Mon, 19 Nov 2018 02:13:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542622439; cv=none; d=google.com; s=arc-20160816; b=HxV/zgEWqToKsQ5PF6Wo/x+IpQDpgZTpDD1dwx2WuWUHpP/+lXxKzDUSpT5rC/g5qE 5GOpUOv5WpgQHHeLHTTHI16o31CaOVQFJm9jUmHgtwu9mI21o/mGOMRx7uMila5mofJs /diUnuCHEJMXTmDpYFli3SpNaBQXEk3cbZM7a94rH3SFLYzlY5qSQy+QjEypKUHRIN4U gX/gtQMCZI5bDwY4vqyFudY6ny6lnCoNjp2qCxzQSoymD0ef+j5ZgHJOeOIdRjRVyXpv Jm0VWXsV4TqfL/9XKas2bbCZ/2e8TAOBFIpACeHHxK/lfsDKo/4pl1y9HXYCyZVCbaKQ 7iZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=g6yxIuUv++QZ8xUceqZYVw8mlNmJI4dke3+qzftt/+0=; b=qUkQ+uPvBtulYbFRjUg4wQt81fbxBiUzvH3ln6cRmlBnLO+59P1mES/2uPiVHjYBpl KjlUzsnhwGFGj2JjxJ2EAXamwmxDiuxn5/nTCdda0b29XlUNy7ObXw8XLWl/wlUotGSZ F5AramvREVjSlQo0CXdiCtF97KIuRIY+Wed9ZGIB/Zlx5+KrVTxJ7EKseSa/SAPgmsYC J+gF47myg8lv++VSnqcIhct52kga4SlY64fKtg4E0aQ+HVOPqZxRYINzHK4By0a5lngT U7+GlxT1dQgp2IiczSvLiyclpvu1/tRa5yFn9hhcKXDE7YC8qpPDOxh0I5kgaqxyte75 rqVQ== 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 p2si38581131pgr.133.2018.11.19.02.13.44; Mon, 19 Nov 2018 02:13:59 -0800 (PST) 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 S1727630AbeKSUgU (ORCPT + 99 others); Mon, 19 Nov 2018 15:36:20 -0500 Received: from terminus.zytor.com ([198.137.202.136]:49821 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726461AbeKSUgU (ORCPT ); Mon, 19 Nov 2018 15:36:20 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id wAJACuGD2523680 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 19 Nov 2018 02:12:56 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id wAJACuPH2523676; Mon, 19 Nov 2018 02:12:56 -0800 Date: Mon, 19 Nov 2018 02:12:56 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: "tip-bot for Maciej S. Szmigiero" Message-ID: Cc: bp@suse.de, x86@kernel.org, mingo@kernel.org, linux-kernel@vger.kernel.org, mail@maciej.szmigiero.name, hpa@zytor.com, tglx@linutronix.de Reply-To: bp@suse.de, mingo@kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, hpa@zytor.com, mail@maciej.szmigiero.name, tglx@linutronix.de In-Reply-To: <6df43f4f6a28186a13a66e8d7e61143c5e1a2324.1529424596.git.mail@maciej.szmigiero.name> References: <6df43f4f6a28186a13a66e8d7e61143c5e1a2324.1529424596.git.mail@maciej.szmigiero.name> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/microcode] x86/microcode/AMD: Subtract SECTION_HDR_SIZE from file leftover length Git-Commit-ID: 479229d1607b6051abc4f9c2ccbb65338f030c65 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=0.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 479229d1607b6051abc4f9c2ccbb65338f030c65 Gitweb: https://git.kernel.org/tip/479229d1607b6051abc4f9c2ccbb65338f030c65 Author: Maciej S. Szmigiero AuthorDate: Tue, 19 Jun 2018 20:47:31 +0200 Committer: Borislav Petkov CommitDate: Mon, 19 Nov 2018 10:44:59 +0100 x86/microcode/AMD: Subtract SECTION_HDR_SIZE from file leftover length 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(). [ bp: Split comment. ] Signed-off-by: Maciej S. Szmigiero Signed-off-by: Borislav Petkov Cc: x86-ml Link: http://lkml.kernel.org/r/6df43f4f6a28186a13a66e8d7e61143c5e1a2324.1529424596.git.mail@maciej.szmigiero.name --- 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 07b5fc00b188..b44c9029860c 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; @@ -621,7 +625,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;