Received: by 10.213.65.68 with SMTP id h4csp43981imn; Thu, 15 Mar 2018 16:08:57 -0700 (PDT) X-Google-Smtp-Source: AG47ELtXr4Ezb7a6xLe/gWklZPO6loZaysrynTUW3qvHCuq0yHqUoALadKGmU7725/GI3VcBw5v8 X-Received: by 10.98.46.197 with SMTP id u188mr3281433pfu.32.1521155337589; Thu, 15 Mar 2018 16:08:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521155337; cv=none; d=google.com; s=arc-20160816; b=uwQP9cgdbpx7FFhyJv/x0s58nB0sYhMohQEEpCJwgjZZQ2/T2p1KMViiBZPdjDjxO9 E+0zoyzMOk8R7EUq/jlpE1GPoyKHbOTDHSHUiN7ouRW99Sq8znRxuRgXcU/2LgQ3gqsx dsTJZsE35nzADY0enOnsOj65+rQ6QRdVQd05UyphCY2In4jrcaTPLeTL4YKmsDOt2zEL vOxW2cDIsSDhnI5IMXITDlNYvqlLtid32gDaTufrbUf4X1uTpygQb2ACPyfKVlFbiZsR NRLLJYZHlrwrVKnmVyamWGFGURR+FG/LvLDBVJ7r/ES6fFetRN1GtDeSHLLbTKhwkSCQ Fpag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:subject:from:arc-authentication-results; bh=RU1Zepf89jtRRNsw6/qwIJyZhXophXXZ26s4Hlu7bpc=; b=uqDocyU+h1nRKQCIFJlFfZsTNvBWHdljf+nkGyyfO7454h35OigSKtGOg0QwIqexef 7SCUSw/NM8udkRRxqB2pcynIcaMGZC5zeUlp1vksz6Be0Uiezxf6cKKDZ4ypxnWzWr0m ER9Ol90Vy3uCtZhO15e4ns6CLMbqo/a2StgPoZQQdsAiyxry/M6oM5a/TCFQSOjS0Lb1 vmK/3yeUVEmxm4WlcsK+kF94Wqk+lQUOdZwuSvIVK19jocwbdwXDzR2qf5fiNwCvGnoi eK7JDm2y3uuN8l1Oth24BgOPtmGJySElQP0wrMqMB0Tk5fYlMPjxBPA07tl8tGVEa31e 4sdA== 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 e190si4501667pfe.203.2018.03.15.16.08.43; Thu, 15 Mar 2018 16:08:57 -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 S932974AbeCOXHr (ORCPT + 99 others); Thu, 15 Mar 2018 19:07:47 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:47160 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932526AbeCOXHp (ORCPT ); Thu, 15 Mar 2018 19:07:45 -0400 Received: by vps-vb.mhejs.net with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ewbyJ-0008Rm-B1; Fri, 16 Mar 2018 00:07:43 +0100 From: "Maciej S. Szmigiero" Subject: [PATCH v4 01/10] x86/microcode/AMD: Subtract SECTION_HDR_SIZE from file leftover length To: Borislav Petkov Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org References: Message-ID: Date: Fri, 16 Mar 2018 00:07:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=iso-8859-2 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org verify_patch_size() function verifies whether the microcode container file remaining size 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 --- arch/x86/kernel/cpu/microcode/amd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c index a998e1a7d46f..6a93be0f771c 100644 --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c @@ -613,7 +613,16 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover) return crnt_size; } - ret = verify_patch_size(family, patch_size, leftover); + /* + * verify_patch_size() checks whether the passed remaining file size + * is large enough to contain a patch of the indicated size (and also + * whether this size does not exceed the family maximum). + * + * The section header length is not included in this indicated size + * but it is present in the leftover file length so we need to subtract + * it before passing this value to that function. + */ + 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;