Received: by 10.213.65.68 with SMTP id h4csp44479imn; Thu, 15 Mar 2018 16:10:09 -0700 (PDT) X-Google-Smtp-Source: AG47ELv2ONjFewCRCHpC7u6C05C25bFx9bjjikSUnQ11vmJETmL8CH5RovukocDnDGeVL8xe2qPV X-Received: by 10.101.69.66 with SMTP id x2mr7948442pgr.438.1521155409217; Thu, 15 Mar 2018 16:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521155409; cv=none; d=google.com; s=arc-20160816; b=mywXKeY7kurkaPYKztbOTigrkVg2cJ5TIKXzA2eCanoXEIkeXaN010eFrHhHupldeG QNprOZ+yMdSQNoigYLABoyjg+LH6TS6TILzS1oxbMGBfeBXVmzkE7knfvgzbLol+ATJZ kCIywMNuSwVsdoqe7CPJdiJfmnugFWWg8ABP/yjzLWE2q7aC+ma2viDU5S43vpod6yBk kAYl0/A/Fc5La0QJo0Ntkz6hv3gdUEpAdxZvJKe4MgOe6vxWsLV1d6P8HosiTSC7nW3W 2stqcNJfFO130Mw0HUINpsqV6M5g5rmFoM5ZTMRbnZ+jIxHb6HbUUCXvmMIl05zVrqu5 g7MA== 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=SEzqLI8vgrMSI5736b4/Tul5QLpPLN48NjQfrQDYraA=; b=ExXFTdI7N916rPADrBNQwE+Yswfli9/rEYEw1tFAaYCtcDlNkfdKICKLzdpHdCoeri AebiTwYZzTL/K1tbxzjufyQBWtqllBbGpO4+mwADpSmBsx3YzyfllrSRqy/uHq1NxsU5 QLHqI8odaXH9zWuTTNhspKPsD06bISwRKDlt0ZzUNvWAB33GBebSUpOV2nkB7WLzHyTl z9V+hgDr++76gi/jy1MrKyHif58LFQ9e2mMVxqfwtJdKE21wA1CmGr/RQvYHX58rMw9W 70P2SUFhoXYVXeulht6K0oLBoMdogwAHJ3DHTdFYcoDWUSHARRSpc8DMc6L9B/FkxVei K0wg== 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 q9si4051182pgp.108.2018.03.15.16.09.53; Thu, 15 Mar 2018 16:10:09 -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 S933044AbeCOXIO (ORCPT + 99 others); Thu, 15 Mar 2018 19:08:14 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:47696 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932526AbeCOXIL (ORCPT ); Thu, 15 Mar 2018 19:08:11 -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-0008SI-Q0; Fri, 16 Mar 2018 00:08:09 +0100 From: "Maciej S. Szmigiero" Subject: [PATCH v4 04/10] x86/microcode/AMD: install_equiv_cpu_table() should not return a signed int 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:08:09 +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 The maximum possible value returned by install_equiv_cpu_table() is UINT_MAX (on a 64-bit kernel). This is more than (signed) int type currently returned by this function can hold so this function will need to return an unsigned int instead. In order to avoid an overflow of this type on a 64-bit kernel we'll need to also modify this function to return only the CPU equivalence table length (without the container header length), leaving its single caller (__load_microcode_amd()) the job of adding the container header length to skip to the fist patch section. The individual (negative) error codes returned by install_equiv_cpu_table() are of no use anyway, since they are all normalized to UCODE_ERROR by its caller. Signed-off-by: Maciej S. Szmigiero --- arch/x86/kernel/cpu/microcode/amd.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c index ed24200cf936..8e8df37f2f1b 100644 --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c @@ -551,40 +551,39 @@ static enum ucode_state apply_microcode_amd(int cpu) return UCODE_UPDATED; } -static int install_equiv_cpu_table(const u8 *buf, size_t buf_size) +static unsigned int install_equiv_cpu_table(const u8 *buf, size_t buf_size) { unsigned int *ibuf = (unsigned int *)buf; unsigned int type, equiv_tbl_len; if (buf_size <= CONTAINER_HDR_SZ) { pr_err("Truncated microcode container header.\n"); - return -EINVAL; + return 0; } type = ibuf[1]; if (type != UCODE_EQUIV_CPU_TABLE_TYPE) { pr_err("Wrong microcode container equivalence table type: %u.\n", type); - return -EINVAL; + return 0; } equiv_tbl_len = ibuf[2]; if (equiv_tbl_len < sizeof(struct equiv_cpu_entry) || buf_size - CONTAINER_HDR_SZ < equiv_tbl_len) { pr_err("Truncated equivalence table.\n"); - return -EINVAL; + return 0; } equiv_cpu_table = vmalloc(equiv_tbl_len); if (!equiv_cpu_table) { pr_err("failed to allocate equivalent CPU table\n"); - return -ENOMEM; + return 0; } memcpy(equiv_cpu_table, buf + CONTAINER_HDR_SZ, equiv_tbl_len); - /* add header length */ - return equiv_tbl_len + CONTAINER_HDR_SZ; + return equiv_tbl_len; } static void free_equiv_cpu_table(void) @@ -681,18 +680,24 @@ static enum ucode_state __load_microcode_amd(u8 family, const u8 *data, size_t size) { enum ucode_state ret = UCODE_ERROR; - unsigned int leftover; + size_t leftover; u8 *fw = (u8 *)data; int crnt_size = 0; - int offset; + unsigned int offset; offset = install_equiv_cpu_table(data, size); - if (offset < 0) { + if (!offset) { pr_err("failed to create equivalent cpu table\n"); return ret; } + + /* + * Skip also the container header, since install_equiv_cpu_table() + * returns just the raw equivalence table size without the header + */ + fw += CONTAINER_HDR_SZ; fw += offset; - leftover = size - offset; + leftover = size - CONTAINER_HDR_SZ - offset; if (*(u32 *)fw != UCODE_UCODE_TYPE) { pr_err("invalid type field in container file section header\n");