Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5525938imm; Tue, 19 Jun 2018 11:49:53 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIhkPn2dueG7egoith6zSxZ+1wEEP6pIdhGoU92HREKio+9yf793J2ywc2o4gT5oq8Hzmy+ X-Received: by 2002:a62:3c96:: with SMTP id b22-v6mr18862048pfk.235.1529434193584; Tue, 19 Jun 2018 11:49:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529434193; cv=none; d=google.com; s=arc-20160816; b=VUsS67T5USqG+LYxP9fXFwS2gFy/jjkmB0lh7M4T1KQxrtxbpI/uFivBEiLDJUH8aI 5TTXpM1ldNyxpTD33zpiS/ooodhKmMhhHVvSVTpzVbAkKUkbMixVo5uM/HCgTQO2vqPu zOHU1iZx2umvJ3KJItOvT80FcDEWNsysKM7gChu5/kk9DxVt2N2HVndHpnbRA6aUFT8I dyWJ2gxZDICiPeCfavDUp96UC8zDN91sp35HKn7y4DpDLk40KMNj1NGz+SL4Tdsb14ma w3F0CeUD1KX4mUoTLQmd0lyVppPJRVS3pWUnEKv1ZHW/5nyGmwpWazNCiTSyxW5WQHfG wl/A== 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=pjZRrXSogExlpe+7FRZj+1ITLqhRbHqhBO2ocRd8QisOftQfs5H67zL1mkpPSgWq5g R7fgZhmjDDvmaa7x8pnsnweQisZLOqDdYnJohtiui4mSzFrRZ3/db9N+tZkXzClox/Do xMmjbn94ofX5HvYdist6qUbdZS2gnDnsvyXq3c3QUzSjGSWw2y8Q3K9Fr2/mbHwpuPi4 jBe0KwXdZgsR2VjIVe5rE7SbYXHn4Umh3I8Q3mm37Tt/IQ5bC7iyPcsuzXj/4xp8CwlC T2PyqtC6IGitagQUz5ph2m3KAsRvU65sV/UCS/5Z/lEeJGU6xj17AB5ttafX4juGpUjL AKeA== 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 l19-v6si298259pgn.625.2018.06.19.11.49.39; Tue, 19 Jun 2018 11:49:53 -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 S1030478AbeFSSr4 (ORCPT + 99 others); Tue, 19 Jun 2018 14:47:56 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:39770 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030320AbeFSSry (ORCPT ); Tue, 19 Jun 2018 14:47:54 -0400 Received: by vps-vb.mhejs.net with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1fVLfH-0003Vp-S0; Tue, 19 Jun 2018 20:47:39 +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 v7 1/9] x86/microcode/AMD: Subtract SECTION_HDR_SIZE from file leftover length Date: Tue, 19 Jun 2018 20:47:31 +0200 Message-Id: <6df43f4f6a28186a13a66e8d7e61143c5e1a2324.1529424596.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;